fix some functions related to PG-SQL
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 10 Jun 2010 17:50:46 +0000 (17:50 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Thu, 10 Jun 2010 17:50:46 +0000 (17:50 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@501 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

phpbase/db_pgsql.php
phpbase/table.php

index 04a050e..def1723 100644 (file)
@@ -57,7 +57,7 @@ class PGsqlEngine extends DbEngine
                if(!$dbScheme->hasTable($tnm))return false;
                $res=@pg_query($this->dbhdl,"select * from ".$this->tableName($tnm)." where 1=2");
                if($res===false){
-                       $this->db_debug_error("has table");
+                       $this->db_debug_error("has table",$tnm);
                        return false;
                }
                pg_free_result($res);
@@ -113,12 +113,12 @@ class PGsqlEngine extends DbEngine
                        $i++;
                        $req.=$this->tableName($tab);
                }
-               $req.=" IN ACCESS EXCLUSIVE";
+               $req.=" IN ACCESS EXCLUSIVE MODE";
                $res=@pg_query($this->dbhdl,$req);
                if($res!==false){
                        pg_free_result($res);
                }else
-                       $this->db_debug_error("lock");
+                       $this->db_debug_error("lock",$req);
        }
        
        public function sqlBeginTransaction(){return "BEGIN";}
@@ -139,7 +139,7 @@ class PGsqlEngine extends DbEngine
                        $query.=" FOR UPDATE";
                $res=@pg_query($this->dbhdl,$query);
                if($res===false){
-                       $this->db_debug_error("select");
+                       $this->db_debug_error("select",$query);
                        return false;
                }
                //get column names and types
@@ -184,7 +184,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");
+                       $this->db_debug_error("create Table",$sql);
                        pg_free_result($res);
                        return true;
                }else
@@ -243,9 +243,10 @@ class PGsqlEngine extends DbEngine
        public function insert($table,array $values)
        {
                $this->transmode=true;
-               $res=@pg_query($this->dbhdl,$this->sqlInsert($table,$values));
+               $sql=$this->sqlInsert($table,$values);
+               $res=@pg_query($this->dbhdl,$sql);
                if($res===false){
-                       $this->db_debug_error("insert");
+                       $this->db_debug_error("insert",$sql);
                        return false;
                }
                pg_free_result($res);
@@ -270,13 +271,14 @@ class PGsqlEngine extends DbEngine
        public function update($table,array $values,$where)
        {
                $this->transmode=true;
-               $res=@pg_query($this->dbhdl,$this->sqlUpdate($table,$values,$where));
+               $sql=$this->sqlUpdate($table,$values,$where);
+               $res=@pg_query($this->dbhdl,$sql);
                if($res!==false){
                        $ret=pg_affected_rows($res);
                        pg_free_result($res);
                        return $ret;
                }else{
-                       $this->db_debug_error("update");
+                       $this->db_debug_error("update",$sql);
                        return false;
                }
        }
@@ -284,13 +286,14 @@ class PGsqlEngine extends DbEngine
        public function deleteRows($table,$where)
        {
                $this->transmode=true;
-               $res=@pg_query($this->dbhdl,$this->sqlDelete($table,$where));
+               $sql=$this->sqlDelete($table,$where);
+               $res=@pg_query($this->dbhdl,$sql);
                if($res!==false){
                        $ret=pg_affected_rows($res);
                        pg_free_result($res);
                        return $ret;
                }else{
-                       $this->db_debug_error("delete");
+                       $this->db_debug_error("delete",$sql);
                        return false;
                }
        }
@@ -337,7 +340,7 @@ class PGsqlEngine extends DbEngine
 //             print($q."<br/>\n");
                $res=@pg_query($this->dbhdl,$q);
                if($res===false){
-                       $this->db_debug_error("sequence sync");
+                       $this->db_debug_error("sequence sync",$q);
                        return false;
                }
                pg_free_result($res);
@@ -351,11 +354,14 @@ class PGsqlEngine extends DbEngine
        }
        
        /**internal helper: print debug message as XML comment, if activated*/
-       private function db_debug_error($what)
+       private function db_debug_error($what,$detail=false)
        {
-               //change this to if(1) if you want debug messages
-               if($this->do_debug)
-               print("<!-- Error while doing '".$what."' on DB: ".xq($this->lastError())." -->\n");
+               if($this->do_debug){
+                       print("<!-- Error while doing '".$what."' on DB: ".xq($this->lastError())." -->\n");
+                       if($detail!==false)
+                               print("<!-- details: ".xq($detail)." -->\n");
+//                     die("giving up");
+               }
        }
 };
 
index c95eed4..a9cc4bc 100644 (file)
@@ -175,11 +175,12 @@ abstract class WobTable
                $this->isfromdb=true;
                $this->data=$data;
                $this->cdata=array();
-               $this->createAudit();
                //assign primary key if sequence (otherwise newKey has done it)
                $seq=$dbScheme->hasSequence($this->table);
                if($seq!==false)
                        $this->data[$seq]=$r;
+               //create audit data
+               $this->createAudit();
                //return success
                return true;
        }