Index: branches/RC/core/kernel/utility/debugger.php =================================================================== diff -u -N -r10304 -r10459 --- branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10304) +++ branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10459) @@ -4,6 +4,14 @@ class Debugger { /** + * Holds reference to global KernelApplication instance + * + * @access public + * @var kApplication + */ + var $Application = null; + + /** * Set to true if fatal error occured * * @var bool @@ -173,6 +181,11 @@ $dbg_constMap['DBG_SQL_PROFILE'] = 0; } + // when showing explain make shure, that debugger window is large enough + if (array_key_exists('DBG_SQL_EXPLAIN', $dbg_constMap) && $dbg_constMap['DBG_SQL_EXPLAIN']) { + $dbg_constMap['DBG_WINDOW_WIDTH'] = 1000; + } + foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) { $this->safeDefine($dbg_constName, $dbg_constValue); } @@ -565,14 +578,35 @@ */ function formatSQL($sql) { - $sql = preg_replace('/(\n|\t| )+/is', ' ', $sql); - $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ", $sql); - return $this->highlightString($sql); + $sql = trim( preg_replace('/(\n|\t| )+/is', ' ', $sql) ); + + $formatted_sql = preg_replace('/\s(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY)\s/is', "\n\t$1 ", ' ' . $sql); + $formatted_sql = $this->highlightString($formatted_sql); + + if (defined('DBG_SQL_EXPLAIN') && DBG_SQL_EXPLAIN) { + if (substr($sql, 0, 6) == 'SELECT') { + $formatted_sql .= '
' . 'Explain:

'; + $explain_result = $this->Application->Conn->Query('EXPLAIN ' . $sql, null, true); + + $explain_table = ''; + foreach ($explain_result as $explain_row) { + if (!$explain_table) { + // first row -> draw header + $explain_table .= '' . implode('', array_keys($explain_row)) . ''; + } + $explain_table .= '' . implode('', $explain_row) . ''; + } + + $formatted_sql .= '' . $explain_table . '
'; + } + } + + return $formatted_sql; } function highlightString($string) { - if (!$this->constOn('DBG_USE_HIGHLIGHT')) { + if (!(defined('DBG_USE_HIGHLIGHT') && DBG_USE_HIGHLIGHT)) { return $string; } @@ -806,16 +840,18 @@ $func_arguments = func_get_args(); $rows_affected = $func_arguments[3]; + $additional = Array (); + if ($rows_affected > 0) { - $additional = Array ( - Array ('name' => 'Affected Rows', 'value' => $rows_affected), - ); + $additional[] = Array ('name' => 'Affected Rows', 'value' => $rows_affected); if (isset($func_arguments[4])) { $additional[] = Array ('name' => 'Result', 'value' => $func_arguments[4]); } - $this->ProfilerData[$key]['additional'] =& $additional; } + + $additional[] = Array ('name' => 'Query Number', 'value' => $func_arguments[5]); + $this->ProfilerData[$key]['additional'] =& $additional; } } @@ -1281,13 +1317,15 @@ } function AttachToApplication() { - if (!$this->constOn('DBG_HANDLE_ERRORS')) return true; + if (!$this->constOn('DBG_HANDLE_ERRORS')) { + return true; + } if (class_exists('kApplication')) { restore_error_handler(); - $application =& kApplication::Instance(); - $application->Debugger =& $this; - $application->errorHandlers[] = Array(&$this, 'saveError'); + $this->Application =& kApplication::Instance(); + $this->Application->Debugger =& $this; + $this->Application->errorHandlers[] = Array(&$this, 'saveError'); } else { set_error_handler(Array(&$this, 'saveError'));