dg / dibi

Dibi - smart database abstraction layer
https://dibiphp.com
Other
487 stars 136 forks source link

Dibi::query() is not throwing exception on "Relation already exists" DB error #259

Closed khamyl closed 7 years ago

khamyl commented 7 years ago

Description

Dibi is not throwing exception when trying to catch the "Relation Aready Exists!" Error in postgres database.

Steps To Reproduce

$sql = array();
$sql[] = "
          CREATE TABLE ...
            (
             ...
              CONSTRAINT ..._tid PRIMARY KEY (tid)
            )
            WITH(OIDS=FALSE);";

try{
 dibi::query($sql);
 $this->DBG("OK!",'nl');
}catch(exception $e){
 if(preg_match("/relation \"(.*?)\" already exists/", $e->getMessage(), $matches)){
  $this->DBG('Already exists!', 'nl');
 }else{
  \log::error('cron_geom_kostry_table_create_error',$e->getMessage(),4);
  $this->DBG("ERROR!",'nl');
  }
}

It juts dies at the "dibi::query($sql);" line :/

But for SEQUENCE:

try{
        dibi::query('CREATE SEQUENCE ..._tid_seq;');
        $this->DBG(..._tid_seq CREATED!', 'nl');
      }catch(\Exception $e){
        if(preg_match("/relation \"(.*?)\" already exists/", $e->getMessage(), $matches)){
          $this->DBG(..._tid_seq Already exists!', 'nl');
        }else{
          $this->DBG(..._tid_seq creation ERROR!', 'nl');
          \log::error('cron_geom_kostry_seqence_create_error',$e->getMessage(),4);
          continue;
        }
      }

It works fine...

khamyl commented 7 years ago

I tested it in separate script and it seems it works fine. So for now Im closing this issue. I will reopen it if I will have more specific details regarding this error (if it will be a dibi error at all).