From 7cae171db494abfdd1cdb564c1c3708908901ebb Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 25 May 2010 18:13:44 +0000 Subject: [PATCH] minor update in PgSql driver git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@477 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- phpbase/db_pgsql.php | 59 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 48 insertions(+), 11 deletions(-) diff --git a/phpbase/db_pgsql.php b/phpbase/db_pgsql.php index 49aa9c8..5b0f518 100644 --- a/phpbase/db_pgsql.php +++ b/phpbase/db_pgsql.php @@ -57,16 +57,20 @@ class PGsqlEngine extends DbEngine global $dbScheme; if(!$dbScheme->hasTable($tnm))return false; $res=@pg_query($this->dbhdl,"select * from ".$this->tableName($tnm)." where 1=2"); - if($res===false)return false; + if($res===false){ + $this->db_debug_error("has table"); + return false; + } pg_free_result($res); return true; } public function beginTransaction() { $res=@pg_query($this->dbhdl,$this->sqlBeginTransaction()); - if($res===false) + if($res===false){ + $this->db_debug_error("begin transaction"); $this->intrans=false; - else{ + }else{ $this->intrans=pg_result_status($res)==PGSQL_COMMAND_OK; pg_free_result($res); } @@ -82,8 +86,10 @@ class PGsqlEngine extends DbEngine if($res!==false){ pg_free_result($res); return true; - }else + }else{ + $this->db_debug_error("commit"); return false; + } } public function rollbackTransaction() @@ -91,7 +97,10 @@ class PGsqlEngine extends DbEngine $this->intrans=false; //don't ask, just do (also catches implicit transactions) $res=@pg_query($this->dbhdl,$this->sqlRollbackTransaction()); - if($res!==false)pg_free_result($res); + if($res!==false){ + pg_free_result($res); + }else + $this->db_debug_error("rollback"); } protected function lockDB($wl) @@ -107,7 +116,10 @@ class PGsqlEngine extends DbEngine } $req.=" IN ACCESS EXCLUSIVE"; $res=@pg_query($this->dbhdl,$req); - if($res!==false)pg_free_result($res); + if($res!==false){ + pg_free_result($res); + }else + $this->db_debug_error("lock"); } public function sqlBeginTransaction(){return "BEGIN";} @@ -121,9 +133,16 @@ class PGsqlEngine extends DbEngine { //actual select $query=$this->sqlSelect($table,$cols,$where,$orderby); - if($this->transmode)$query.=" FOR UPDATE"; + //if we are in write mode and there is no grouping + //(no grouping is a PGSql limitation) + //then append "FOR UPDATE" to tell the DB we will be writing + if($this->transmode && $orderby!="") + $query.=" FOR UPDATE"; $res=@pg_query($this->dbhdl,$query); - if($res===false)return false; + if($res===false){ + $this->db_debug_error("select"); + return false; + } //get column names and types $nf=pg_num_fields($res); $fnames=array(); @@ -166,6 +185,7 @@ class PGsqlEngine extends DbEngine $sql=$this->sqlCreateTable($tn,$t); $res=@pg_query($this->dbhdl,$sql); if($res!==false){ + $this->db_debug_error("create Table"); pg_free_result($res); return true; }else @@ -225,7 +245,10 @@ class PGsqlEngine extends DbEngine { $this->transmode=true; $res=@pg_query($this->dbhdl,$this->sqlInsert($table,$values)); - if($res===false)return false; + if($res===false){ + $this->db_debug_error("insert"); + return false; + } pg_free_result($res); global $dbScheme; $seq=$dbScheme->hasSequence($table); @@ -253,7 +276,10 @@ class PGsqlEngine extends DbEngine $ret=pg_affected_rows($res); pg_free_result($res); return $ret; - }else return false; + }else{ + $this->db_debug_error("update"); + return false; + } } public function deleteRows($table,$where) @@ -264,7 +290,10 @@ class PGsqlEngine extends DbEngine $ret=pg_affected_rows($res); pg_free_result($res); return $ret; - }else return false; + }else{ + $this->db_debug_error("delete"); + return false; + } } public function lastError() @@ -296,6 +325,14 @@ class PGsqlEngine extends DbEngine if($b=="t" || $b=="true" || $b=="yes" || $b=="y" || $b=="on")return true; else return false; } + + /**internal helper: print debug message as XML comment, if activated*/ + private function db_debug_error($what) + { + //change this to if(1) if you want debug messages + if(0) + print("\n"); + } }; ?> \ No newline at end of file -- 1.7.2.5