dblayeroo : allow to log with priority
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5483 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -30,7 +30,7 @@ class dblayeroo
|
||||
private $foreign = array ();
|
||||
/** Debug of the SQL
|
||||
*/
|
||||
private $debug = FALSE;
|
||||
protected $debug = FALSE;
|
||||
/** The connecting DSN
|
||||
*/
|
||||
private $dsn = null;
|
||||
@@ -334,7 +334,7 @@ class dblayeroo
|
||||
public function createTable ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering createTable");
|
||||
$this->debugLog ("Entering createTable", 2);
|
||||
if ($this->sep === "")
|
||||
$this->DBException (dgettext ("domframework", "Database not connected"),
|
||||
500);
|
||||
@@ -674,7 +674,7 @@ class dblayeroo
|
||||
public function dropTable ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering dropTable ()");
|
||||
$this->debugLog ("Entering dropTable ()", 2);
|
||||
if ($this->sep === "")
|
||||
$this->DBException (dgettext ("domframework", "Database not connected"));
|
||||
if ($this->table === null)
|
||||
@@ -692,7 +692,7 @@ class dblayeroo
|
||||
public function getTableSchema ($tableName)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering getTableSchema (",$tableName,")");
|
||||
$this->debugLog ("Entering getTableSchema (",$tableName,")", 2);
|
||||
switch (self::$instance[$this->dsn]->getAttribute(\PDO::ATTR_DRIVER_NAME))
|
||||
{
|
||||
case "sqlite":
|
||||
@@ -1048,7 +1048,7 @@ class dblayeroo
|
||||
private function fieldTypeComplete ($field)
|
||||
/* {{{ */
|
||||
{
|
||||
// $this->debugLog ("Entering fieldTypeComplete (",$field,")");
|
||||
// $this->debugLog ("Entering fieldTypeComplete (",$field,")", 2);
|
||||
if (! array_key_exists ($field, $this->fields))
|
||||
$this->DBException (sprintf (
|
||||
"fieldType : can't find the definition for field '%s'",
|
||||
@@ -1108,7 +1108,7 @@ class dblayeroo
|
||||
public function table ($table = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering table (",$table,")");
|
||||
$this->debugLog ("Entering table (",$table,")", 2);
|
||||
if ($table === null)
|
||||
return $this->table;
|
||||
if (! is_string ($table))
|
||||
@@ -1126,7 +1126,7 @@ class dblayeroo
|
||||
public function tableprefix ($tableprefix = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering tableprefix (",$tableprefix,")");
|
||||
$this->debugLog ("Entering tableprefix (",$tableprefix,")", 2);
|
||||
if ($tableprefix === null)
|
||||
return $this->tableprefix;
|
||||
if (! is_string ($tableprefix))
|
||||
@@ -1147,7 +1147,7 @@ class dblayeroo
|
||||
public function fields ($fields = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering fields (VALUE)");
|
||||
$this->debugLog ("Entering fields (VALUE)", 2);
|
||||
if ($fields === null)
|
||||
return $this->fields;
|
||||
if (! is_array ($fields))
|
||||
@@ -1233,7 +1233,7 @@ class dblayeroo
|
||||
public function primary ($primary = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering primary (",$primary,")");
|
||||
$this->debugLog ("Entering primary (",$primary,")", 2);
|
||||
if ($primary === null)
|
||||
return $this->primary;
|
||||
if (! is_string ($primary))
|
||||
@@ -1253,7 +1253,7 @@ class dblayeroo
|
||||
public function unique ($unique = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering unique (VALUE)");
|
||||
$this->debugLog ("Entering unique (VALUE)", 2);
|
||||
if ($unique === null)
|
||||
return $this->unique;
|
||||
if (! is_array ($unique))
|
||||
@@ -1299,7 +1299,7 @@ class dblayeroo
|
||||
public function foreign ($foreign = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering foreign (VALUE)");
|
||||
$this->debugLog ("Entering foreign (VALUE)", 2);
|
||||
if ($foreign === null)
|
||||
return $this->foreign;
|
||||
if (! is_array ($foreign))
|
||||
@@ -1360,7 +1360,7 @@ class dblayeroo
|
||||
public function debug ($debug = null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering debug (",$debug,")");
|
||||
$this->debugLog ("Entering debug (",$debug,")", 2);
|
||||
if ($debug === null)
|
||||
return $this->debug;
|
||||
if (! is_int ($debug))
|
||||
@@ -1385,7 +1385,7 @@ class dblayeroo
|
||||
public function dsn ($dsn=null)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering dsn (",$dsn,")");
|
||||
$this->debugLog ("Entering dsn (",$dsn,")", 2);
|
||||
if ($dsn === null)
|
||||
return $this->dsn;
|
||||
if (! is_string ($dsn))
|
||||
@@ -1402,7 +1402,7 @@ class dblayeroo
|
||||
public function titles ($titles=null, $full = false)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering titles (VALUE)");
|
||||
$this->debugLog ("Entering titles (VALUE)", 2);
|
||||
if ($titles === null)
|
||||
{
|
||||
if ($full === false && $this->joinObject === null)
|
||||
@@ -1563,7 +1563,7 @@ class dblayeroo
|
||||
/** The debug depth (as we clone object, the depth is increased to debug
|
||||
* easily the functions
|
||||
*/
|
||||
private $debugDepth = 1;
|
||||
protected $debugDepth = 1;
|
||||
|
||||
/** The sort order of select/order entries crossed the differents objects
|
||||
*/
|
||||
@@ -1584,7 +1584,7 @@ class dblayeroo
|
||||
public function clearRequest ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering clearRequest ()");
|
||||
$this->debugLog ("Entering clearRequest ()", 2);
|
||||
if ($this->joinObject !== null)
|
||||
{
|
||||
foreach ($this->joinObject as $obj)
|
||||
@@ -1619,7 +1619,7 @@ class dblayeroo
|
||||
public function setForeignObj ($object)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering setForeignObj (OBJECT)");
|
||||
$this->debugLog ("Entering setForeignObj (OBJECT)", 2);
|
||||
if (! is_object ($object))
|
||||
$this->DBException ("Invalid setForeignObj parameter: not an object");
|
||||
if (! is_subclass_of ($object, __CLASS__) &&
|
||||
@@ -1642,7 +1642,7 @@ class dblayeroo
|
||||
public function command ($command)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering command (",$command,")");
|
||||
$this->debugLog ("Entering command (",$command,")", 2);
|
||||
$allowed = array ("SELECT", "INSERT", "DELETE", "UPDATE");
|
||||
if (! is_string ($command))
|
||||
$this->DBException ("Invalid command provided (not string)");
|
||||
@@ -1728,7 +1728,7 @@ class dblayeroo
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering displayAdd (", $columnNames, ",", $aliasNames,
|
||||
")");
|
||||
")", 2);
|
||||
if (! is_string ($columnNames) && ! is_array ($columnNames))
|
||||
$this->DBException (
|
||||
"Invalid columnNames provided (not string and not array)");
|
||||
@@ -1986,7 +1986,7 @@ class dblayeroo
|
||||
public function joinInner ($object, $joinArray)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering joinInner (OBJECT, JOINARRAY)");
|
||||
$this->debugLog ("Entering joinInner (OBJECT, JOINARRAY)", 2);
|
||||
return $this->joinReal ("INNER", $object, $joinArray);
|
||||
}
|
||||
/* }}} */
|
||||
@@ -2001,7 +2001,7 @@ class dblayeroo
|
||||
public function joinLeft ($object, $joinArray)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering joinLeft (OBJECT, JOINARRAY)");
|
||||
$this->debugLog ("Entering joinLeft (OBJECT, JOINARRAY)", 2);
|
||||
return $this->joinReal ("LEFT", $object, $joinArray);
|
||||
}
|
||||
/* }}} */
|
||||
@@ -2016,7 +2016,7 @@ class dblayeroo
|
||||
public function joinRight ($object, $joinArray)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering joinRight (OBJECT, JOINARRAY)");
|
||||
$this->debugLog ("Entering joinRight (OBJECT, JOINARRAY)", 2);
|
||||
return $this->joinReal ("RIGHT", $object, $joinArray);
|
||||
}
|
||||
/* }}} */
|
||||
@@ -2066,7 +2066,7 @@ class dblayeroo
|
||||
private function joinReal ($joinType, $object, $joinArray)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering joinReal (",$joinType,", OBJECT, JOINARRAY)");
|
||||
$this->debugLog ("Entering joinReal (",$joinType,", OBJECT, JOINARRAY)", 2);
|
||||
if (! is_string ($joinType))
|
||||
$this->DBException ("Invalid joinType provided to join (not string)");
|
||||
if (! in_array ($joinType, array ("INNER", "LEFT", "RIGHT")))
|
||||
@@ -2166,7 +2166,7 @@ class dblayeroo
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering whereAdd (",$field,", ",$operator,", ",$value,
|
||||
")");
|
||||
")", 2);
|
||||
if (! is_string ($field))
|
||||
$this->DBException ("Invalid field provided (not string)");
|
||||
if (! is_string ($operator))
|
||||
@@ -2225,7 +2225,7 @@ class dblayeroo
|
||||
public function whereAddAND ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering whereAddAND ()");
|
||||
$this->debugLog ("Entering whereAddAND ()", 2);
|
||||
if (count ($this->whereExpression) === 0)
|
||||
$this->DBException ("Can not add AND as there is no previous expression");
|
||||
$this->whereExpression[] = "AND";
|
||||
@@ -2238,7 +2238,7 @@ class dblayeroo
|
||||
public function whereAddOR ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering whereAddOR ()");
|
||||
$this->debugLog ("Entering whereAddOR ()", 2);
|
||||
if (count ($this->whereExpression) === 0)
|
||||
$this->DBException ("Can not add OR as there is no previous expression");
|
||||
$this->whereExpression[] = "OR";
|
||||
@@ -2251,7 +2251,7 @@ class dblayeroo
|
||||
public function whereAddParenthesisOpen ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering whereAddParenthesisOpen ()");
|
||||
$this->debugLog ("Entering whereAddParenthesisOpen ()", 2);
|
||||
if (count ($this->whereExpression) &&
|
||||
end ($this->whereExpression) !== "AND" &&
|
||||
end ($this->whereExpression) !== "OR" &&
|
||||
@@ -2267,7 +2267,7 @@ class dblayeroo
|
||||
public function whereAddParenthesisClose ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering whereAddParenthesisClose ()");
|
||||
$this->debugLog ("Entering whereAddParenthesisClose ()", 2);
|
||||
$this->whereExpression[] = ")";
|
||||
return $this;
|
||||
}
|
||||
@@ -2332,7 +2332,7 @@ class dblayeroo
|
||||
public function orderAdd ($field, $sort = "ASC")
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering orderAdd (",$field,", ",$sort,")");
|
||||
$this->debugLog ("Entering orderAdd (",$field,", ",$sort,")", 2);
|
||||
if (! is_string ($field))
|
||||
$this->DBException ("Invalid field provided (not string)");
|
||||
if (! is_string ($sort))
|
||||
@@ -2484,7 +2484,7 @@ class dblayeroo
|
||||
public function limit ($startLine, $nbLines)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering limit (",$startLine,", ",$nbLines,")");
|
||||
$this->debugLog ("Entering limit (",$startLine,", ",$nbLines,")", 2);
|
||||
if (! preg_match ("/^\d+$/", $startLine))
|
||||
$this->DBException (sprintf (
|
||||
"Invalid startLine to limit '%d': not numerical", $startLine));
|
||||
@@ -2507,7 +2507,7 @@ class dblayeroo
|
||||
public function limitLines ($nbLines)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering limitLines (",$nbLines,")");
|
||||
$this->debugLog ("Entering limitLines (",$nbLines,")", 2);
|
||||
if (! preg_match ("/^\d+$/", $nbLines))
|
||||
$this->DBException (sprintf (
|
||||
"Invalid nbLines to limit '%d': not numerical", $nbLines));
|
||||
@@ -2525,7 +2525,7 @@ class dblayeroo
|
||||
public function setValues ($values)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering setValues (",$values,")");
|
||||
$this->debugLog ("Entering setValues (",$values,")", 2);
|
||||
if (! is_array ($values))
|
||||
$this->DBException ("Invalid values to setValues : not an array");
|
||||
$values = $this->normalize ($values);
|
||||
@@ -3132,7 +3132,7 @@ class dblayeroo
|
||||
public function checkValues ($values, $update = false)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering checkValues (",$update,")");
|
||||
$this->debugLog ("Entering checkValues (",$update,")", 2);
|
||||
if (! is_array ($values))
|
||||
{
|
||||
$this->DBException ("checkValues fields : ".
|
||||
@@ -3163,7 +3163,8 @@ class dblayeroo
|
||||
public function checkRealTypes ($values, $allowEmpty = false)
|
||||
// {{{
|
||||
{
|
||||
$this->debugLog ("Entering checkRealTypes (",$values,",",$allowEmpty,")");
|
||||
$this->debugLog ("Entering checkRealTypes (",$values,",",$allowEmpty,")",
|
||||
2);
|
||||
if (! is_array ($values))
|
||||
$this->DBException ("Invalid checkRealTypes provided : not an array",
|
||||
500);
|
||||
@@ -3215,7 +3216,7 @@ class dblayeroo
|
||||
public function execute ()
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering execute ()");
|
||||
$this->debugLog ("Entering execute ()", 2);
|
||||
switch ($this->command)
|
||||
{
|
||||
case "SELECT":
|
||||
@@ -3241,9 +3242,9 @@ class dblayeroo
|
||||
default:
|
||||
$this->DBException ("execute : command not defined : no check");
|
||||
}
|
||||
$this->debugLog ("Entering createRequest ()");
|
||||
$this->debugLog ("Entering createRequest ()", 2);
|
||||
$sql = $this->createRequest ();
|
||||
$this->debugLog ("Entering prepareRequest (XXX, ",false,")");
|
||||
$this->debugLog ("Entering prepareRequest (XXX, ",false,")", 2);
|
||||
$st = $this->prepareRequest ($sql, false);
|
||||
$this->debugLog ("'", $this->getDisplayQuery (), "'");
|
||||
$startTime = microtime (true);
|
||||
@@ -3473,14 +3474,19 @@ class dblayeroo
|
||||
|
||||
/** Debug function
|
||||
* @param mixed ...$message The message to display in debug
|
||||
* @param integer priority The display message if $priority <= $this->debug
|
||||
*/
|
||||
private function debugLog ($message)
|
||||
public function debugLog ($message, $priority)
|
||||
/* {{{ */
|
||||
{
|
||||
if ((!!$this->debug) === false)
|
||||
return;
|
||||
$args = func_get_args();
|
||||
$priority = array_pop ($args);
|
||||
if ($priority > $this->debug)
|
||||
return;
|
||||
echo str_repeat ("=", $this->debugDepth * 2)." ";
|
||||
foreach (func_get_args() as $nb=>$arg)
|
||||
foreach ($args as $nb=>$arg)
|
||||
{
|
||||
if (is_string ($arg) || is_int ($arg))
|
||||
echo $arg;
|
||||
|
||||
Reference in New Issue
Block a user