}
$ret.=$this->createTableExtras($tablename,$table);
$ret.=")";
+ WobTransaction::debug("Create Table Stmt: ".$ret,WobTransaction::DebugDbStatement);
return $ret;
}
$query="SELECT $cols FROM ".$this->tableName($table);
if($where!="")$query.=" WHERE ".$where;
if($orderby!="")$query.=" ".$orderby;
+ WobTransaction::debug("DB Select Stmt: ".$query,WobTransaction::DebugDbStatement);
return $query;
}
$val.="NULL";
}
$ret.=$val.")";
-// print $ret;
+ WobTransaction::debug("DB Insert Stmt: ".$ret,WobTransaction::DebugDbStatement);
return $ret;
}
/**creates a SQL92 statement for deletes; overwrite this to implement DB specific syntax*/
protected function sqlDelete($table,$where)
{
- return "DELETE FROM ".$this->tableName($table)." WHERE ".$where;
+ $ret="DELETE FROM ".$this->tableName($table)." WHERE ".$where;
+ WobTransaction::debug("DB Delete Stmt: ".$ret,WobTransaction::DebugDbStatement);
+ return $ret;
}
/**creates a SQL92 statement for updates; overwrite this to implement DB specific syntax*/
$ret.="NULL";
}
$ret.=" WHERE ".$where;
- //print $ret;
+ WobTransaction::debug("DB Update Stmt: ".$ret,WobTransaction::DebugDbStatement);
return $ret;
}
}
public function beginTransaction()
{
+ WobTransaction::debug("DB Begin Transaction",WobTransaction::DebugDbTransaction);
$this->intrans=mysqli_query($this->dbhdl,$this->sqlBeginTransaction());
return $this->intrans;
}
public function commitTransaction()
{
if(!$this->intrans)return false;
+ WobTransaction::debug("DB Commit Transaction",WobTransaction::DebugDbTransaction);
//otherwise commit
$this->intrans=false;
return mysqli_query($this->dbhdl,$this->sqlCommitTransaction());
public function rollbackTransaction()
{
$this->intrans=false;
+ WobTransaction::debug("DB RollBack Transaction",WobTransaction::DebugDbTransaction);
//don't ask, just do (also catches implicit transactions)
return mysqli_query($this->dbhdl,$this->sqlRollbackTransaction());
}
if($wl)$req.=" WRITE";
else $req.=" READ";
}
+ WobTransaction::debug("DB Lock: ".$req,WobTransaction::DebugDbQuery);
mysqli_query($this->dbhdl,$req);
}
protected function unlockDB()
{
+ WobTransaction::debug("DB Full Unlock",WobTransaction::DebugDbQuery);
mysqli_query($this->dbhdl,"UNLOCK TABLES");
}
$query=$this->sqlSelect($table,$cols,$where,$orderby);
if($this->transmode)$query.=" FOR UPDATE";
$res=mysqli_query($this->dbhdl,$query);
+ WobTransaction::debug("DB SELECT: ".$query."\n".($res===false?"failed":"successful"),WobTransaction::DebugDbQuery);
if($res===false)return false;
$nr=mysqli_num_rows($res);
$ret=array();
protected function createTable($tn,$t)
{
$sql=$this->sqlCreateTable($tn,$t);
+ WobTransaction::debug("DB create table: ".$sql,WobTransaction::DebugDbQuery);
return mysqli_query($this->dbhdl,$sql);
}
public function insert($table,array $values)
{
$this->transmode=true;
- $res=mysqli_query($this->dbhdl,$this->sqlInsert($table,$values));
+ $sql=$this->sqlInsert($table,$values);
+ $res=mysqli_query($this->dbhdl,$sql);
+ WobTransaction::debug("DB Insert: ".$sql."\n".($res===false?"failed":"successful"),WobTransaction::DebugDbQuery);
if($res===false)return false;
global $dbScheme;
$seq=$dbScheme->hasSequence($table);
public function update($table,array $values,$where)
{
$this->transmode=true;
- $res=mysqli_query($this->dbhdl,$this->sqlUpdate($table,$values,$where));
+ $sql=$this->sqlUpdate($table,$values,$where);
+ $res=mysqli_query($this->dbhdl,$sql);
+ WobTransaction::debug("DB Update: ".$sql."\n".($res===false?"failed":"successful"),WobTransaction::DebugDbQuery);
if($res!==false)return mysqli_affected_rows($this->dbhdl);
else return false;
}
public function deleteRows($table,$where)
{
$this->transmode=true;
- $b=mysqli_query($this->dbhdl,$this->sqlDelete($table,$where));
+ $sql=$this->sqlDelete($table,$where);
+ $b=mysqli_query($this->dbhdl,$sql);
+ WobTransaction::debug("DB Delete Rows: ".$sql."\n".($b===false?"failed":"successful"),WobTransaction::DebugDbQuery);
// echo mysqli_error($this->dbhdl);
if($b!==false)return mysqli_affected_rows($this->dbhdl);
else return false;
case WobTransactionBase::Soap12Encoding:$this->printXmlSchema();break;
default: $this->printXmlWob();break;
}
+ //print debug stuff (if anything left)
+ WobTransaction::printDebug();
}
/**used by machine oriented transaction to print the proper XML representation of the error in Wob Encoding*/
- public function printXmlWob()
+ protected function printXmlWob()
{
header("X-WobResponse-Status: Error");
$xml=new DOMDocument;
protected $aoutput;
protected $toutput;
protected $headers=array();
+ static protected $debugstr="";
+ static protected $debuglev=0;
+
+ ///no debugging (used only in setDebugLevel())
+ const DebugNone = 0;
+ ///activate all debug (used only in setDebugLevel())
+ const DebugAll = 0x0ffffff;
+ ///flag: output the debug string immediately (risks losing headers, used only in debug())
+ const DebugUrgent = 0x1000000;
+ ///debug database errors
+ const DebugDbError = 0x0000001;
+ ///debug database queries when they are executed
+ const DebugDbQuery = 0x0000002;
+ ///debug database statements when they are constructed
+ const DebugDbStatement = 0x0000004;
+ ///debug database transaction start/end
+ const DebugDbTransaction= 0x0000008;
+ ///output all database related actions (used only in setDebugLevel())
+ const DebugDbAll = 0x00000ff;
+ ///debug transaction related actions
+ const DebugTransactions = 0x0000100;
+ ///miscellaneous debug output (default level)
+ const DebugMisc = 0x0800000;
//these encoding constants must match the WocProcessor::MessageEncoding enum
/**encode messages according to PACK standard - with minimal XML levels*/
///returns the currently running instance of a transaction
static public function getInstance(){return self::$instance;}
+ ///set the debug level of the server
+ static public function setDebugLevel($level)
+ {
+ self::$debuglev=$level & self::DebugAll;
+ }
+
+ ///inserts a comment as debug statement
+ static public function debug($str,$level=self::DebugMisc)
+ {
+ if((self::$debuglev & $level) == 0)return;
+
+ if(self::$debugstr!="")self::$debugstr.="\n\n";
+ self::$debugstr.=$str;
+
+ if($level & self::DebugUrgent)self::printDebug();
+ }
+
+ ///print debug comment now (called from xmlToString() and TransactionError
+ static public function printDebug()
+ {
+ if(self::$debugstr == "")return;
+ print(self::getDebug());
+ }
+
+ ///return debug comment now (called from xmlToString() and TransactionError
+ static public function getDebug()
+ {
+ if(self::$debugstr == "")return "";
+ $ret="\n<!-- ".htmlentities(self::$debugstr)." -->\n";
+ self::$debugstr="";
+ return $ret;
+ }
+
/**Wob message encoding: called to determine the correct transaction, aborts the script if there is none.*/
static public function getTransactionNameWob()
{
//put envelope into document
$xml["doc"]->appendChild($env);
}
- return $xml["doc"]->saveXml();
+ return $xml["doc"]->saveXml() . self::getDebug();
}
};