From 55ad71a698674111e24b6eb3485b5b84643868a5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 21 Jan 2006 21:02:06 +0000 Subject: [PATCH] Make query debug output much nicer --- db.php | 38 ++++++++++++++++++++++++++++++-------- printer.php | 4 +--- template.php | 4 +--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/db.php b/db.php index f80e2fb..b7ee77c 100644 --- a/db.php +++ b/db.php @@ -216,22 +216,22 @@ class DB_Abstract $this->querystr = $string; $this->result = call_user_func($this->commands['query'], $this->dblink, $string); + + if (!$this->result) + { + $this->error('Invalid SQL query'); + } + + $this->history[] = $history = array('query' => $string, 'time' => $this->registry->modules['functions']->fetch_microtime_diff($time), 'trace' => $this->registry->format_debug_trace(debug_backtrace())); if (defined('ISSO_SHOW_QUERIES_LIVE')) { if (constant('ISSO_SHOW_QUERIES_LIVE')) { - print($this->querystr . '
'); + print($this->construct_query_debug($history)); } } - if (!$this->result) - { - $this->error('Invalid SQL query'); - } - - $this->history[] = array('query' => $string, 'time' => $this->registry->modules['functions']->fetch_microtime_diff($time), 'trace' => $this->registry->format_debug_trace(debug_backtrace())); - return $this->result; } @@ -358,6 +358,28 @@ class DB_Abstract return call_user_func($this->commands['affected_rows'], $result); } + // ################################################################### + /** + * Constructs a table of query information output that is used in some + * other modules to display a list of queries. This merely formats + * a DB->history array entry nicely + * + * @access public + * + * @param array An entry from DB->history + * + * @return string A formatted table block + */ + function construct_query_debug($query) + { + $block = "Query:\n\n
" . $this->registry->entity_encode($query['query']) . "
\n"; + $block .= "\n\t\n\t\t"; + $block .= "Time: $query[time]
\n\t\t
\n\t\t"; + $block .= "Backtrace:\n\t\t
" . implode("
\n", $query['trace']) . "
\n\t\n"; + + return $this->registry->message('Query Debug', $block, 1, true, false, 0); + } + // ################################################################### /** * Error wrapper for ISSO->message() diff --git a/printer.php b/printer.php index 49ad720..410b322 100644 --- a/printer.php +++ b/printer.php @@ -397,12 +397,10 @@ JS; if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) { - echo '
';
 				foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query)
 				{
-					echo print_r($query, true) . "\n\n
\n\n"; + echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); } - echo '
'; } exit; } diff --git a/template.php b/template.php index 2a4071c..ab9b0f4 100644 --- a/template.php +++ b/template.php @@ -286,12 +286,10 @@ class Template { if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) { - echo '
';
 				foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query)
 				{
-					echo $query . "\n\n
\n\n"; + echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); } - echo '
'; } exit; } -- 2.43.5