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 .= '