Support for debugging sql queries in page footer.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 21 Jun 2010 17:17:44 +0000 (17:17 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 21 Jun 2010 17:17:44 +0000 (17:17 +0000)
admin/system_diagnostics.php
config.default.php
includes/db/connect_db.inc
includes/errors.inc
includes/page/footer.inc

index 8fba181051c23a9329cf89983e6cc5e732074832..e1d8961863077e6b74df8a78e7025b11485d0216 100644 (file)
@@ -114,7 +114,7 @@ function tst_debug()
        $test['type'] = 0;
        $test['test'] = $go_debug ? _("Yes") : _("No");
        $test['result'] = $go_debug != 0;
-       $test['comments'] = _('To switch debugging on set $go_debug=1 in config.php file');
+       $test['comments'] = _('To switch debugging on set $go_debug>1 in config.php file');
 
        return $test;
 }
index 747d6f26b9fe20b6b56a14d020e8ab599de03a9f..84c8578f5446537201d96a945b9e8556dd30bd5e 100644 (file)
@@ -25,10 +25,11 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
        // Special value 'syslog' can be used for system logger usage (see php manual).
        //$error_logfile = '';
        $error_logfile = dirname(__FILE__).'/tmp/errors.log';
-       $debug                  = 1;
-       $show_sql               = 0;
-       $go_debug               = 0;
-       $pdf_debug              = 0;
+       $debug                  = 1;    // show sql on database errors
+
+       $show_sql               = 0;    // show all sql queries in page footer for debugging purposes
+       $go_debug               = 0;    // set to 1 for basic debugging, or 2 to see also backtrace after failure.
+       $pdf_debug              = 0;    // display pdf source instead reports for debugging when $go_debug!=0
        // set $sql_trail to 1 only if you want to perform bugtracking sql trail
        // Warning: this produces huge amount of data in sql_trail table.
        // Don't forget switch the option off and flush the table manually after 
@@ -36,7 +37,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
        //
        $sql_trail              = 0; // save all sql queries in sql_trail
        $select_trail   = 0; // track also SELECT queries
-       if ($go_debug == 1)
+       if ($go_debug > 0)
        {
                error_reporting(E_ALL);
                ini_set("display_errors", "On");
index 3e0d551f2888beef86d29c29466e19da01c999a2..5babac1bd4f3676bd5f6d2874df2e37cb6ca736f 100644 (file)
@@ -26,16 +26,13 @@ $db_duplicate_error_code = 1062;
 
 function db_query($sql, $err_msg=null)
 {
-       global $db, $show_sql, $sql_trail, $select_trail, $go_debug;
+       global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax;
        
        if ($show_sql)
        {
-               echo "<font face=arial size=2 color=000099><b>SQL..</b></font>";
-               echo "<pre>";
-               echo $sql;
-               echo "</pre>\n";
+               $Ajax->activate('footer_debug');
+               $sql_queries .= "<pre>$sql</pre>\n<hr>";
        }
-       
 
        $result = mysql_query($sql, $db);
        if($sql_trail) {
index 9e0dba2e87fc99edf3694e96528e6096e74c31b3..16b5be40f4c59c254af75cb26ac2367a77157383 100644 (file)
@@ -108,7 +108,7 @@ function end_flush() {
 
 function display_db_error($msg, $sql_statement=null, $exit=true)
 {
-       global $db, $debug;
+       global $db, $debug, $go_debug;
 
        $warning = $msg==null;
        $db_error = db_error_no();
@@ -128,6 +128,7 @@ function display_db_error($msg, $sql_statement=null, $exit=true)
        if ($debug == 1) 
        {
                $str .= "sql that failed was : " . $sql_statement . "<br>";
+               if ($go_debug > 1) display_backtrace();
        }
        
        $str .= "<br><br>";
index 23318932abfc68376ad4f2f4d76043fb29b59f23..68f76f35ef0c0696424b66d4cd2867f9928dee36 100644 (file)
@@ -11,7 +11,7 @@
 ***********************************************************************/
 function page_footer($no_menu=false, $is_index=false, $hide_back_link=false)
 {
-       global $path_to_root, $js_lib, $Validate, $Editors, $Ajax;
+       global $path_to_root, $js_lib, $Validate, $Editors, $Ajax, $sql_queries;
 
        include_once($path_to_root."/themes/".user_theme()."/renderer.php");
        $rend = new renderer();
@@ -32,6 +32,12 @@ function page_footer($no_menu=false, $is_index=false, $hide_back_link=false)
        foreach($js_lib as $text)
                echo $text;
        echo "\n--></script>\n";
+
+       if ($sql_queries) {
+               div_start('footer_debug');
+                echo "<div class='note_msg'>$sql_queries</div>";
+               div_end();
+       }
     echo "</body></html>\n";
 }