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);
}
if($res!==false){
pg_free_result($res);
return true;
- }else
+ }else{
+ $this->db_debug_error("commit");
return false;
+ }
}
public function rollbackTransaction()
$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)
}
$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";}
{
//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();
$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
{
$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);
$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)
$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()
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("<!-- Error while doing '".$what."' on DB: ".xq($this->lastError())." -->\n");
+ }
};
?>
\ No newline at end of file