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);
$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";}
$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
$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
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);
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;
}
}
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;
}
}
// 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);
}
/**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");
+ }
}
};