Fixed error handling in debug mode
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 3 May 2009 13:50:05 +0000 (13:50 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 3 May 2009 13:50:05 +0000 (13:50 +0000)
includes/db/connect_db.inc
includes/errors.inc

index dc2dd027ede11c4aadcb1acafbed14be6c8b30fa..fd6870e947ed121d58ec558a13a00561b523c3f5 100644 (file)
@@ -28,8 +28,6 @@ function db_query($sql, $err_msg=null)
 {
        global $db, $show_sql, $sql_trail, $select_trail, $go_debug;
        
-       if (!$err_msg && $go_debug) 
-               $err_msg = "Debug mode error";
        //echo "<br>$sql<br>";
        if ($show_sql)
        {
@@ -51,12 +49,13 @@ function db_query($sql, $err_msg=null)
                }
        }
 
-       if ($err_msg != null)
-         if (function_exists('xdebug_call_file'))
-               check_db_error('<br>At file '.xdebug_call_file().':'.xdebug_call_line().':<br>'.$err_msg, $sql);
-         else
-               check_db_error($err_msg, $sql);
-
+       if ($err_msg != null || $go_debug) {
+               $exit = $err_msg != null;
+               if (function_exists('xdebug_call_file'))
+                       check_db_error('<br>At file '.xdebug_call_file().':'.xdebug_call_line().':<br>'.$err_msg, $sql, $exit);
+               else
+                       check_db_error($err_msg, $sql, $exit);
+       }
        return $result;
 }
 
index 160d41e5100dce8fe0d84bda8dd4d55b9c516f8f..1a39f1637ce3bffef74fbc61c28e42582ad843f8 100644 (file)
@@ -83,9 +83,15 @@ function error_box() {
 function display_db_error($msg, $sql_statement=null, $exit=true)
 {
        global $db, $debug;
+
+       $warning = $msg==null;
        $db_error = db_error_no();
        
-       $str = "<span class='errortext'><b>" . _("DATABASE ERROR :") . "</b> $msg</span><br>";
+//     $str = "<span class='errortext'><b>" . _("DATABASE ERROR :") . "</b> $msg</span><br>";
+       if($warning)
+               $str = "<b>" . _("Debug mode database warning:") . "</b><br>";
+       else
+               $str = "<b>" . _("DATABASE ERROR :") . "</b> $msg<br>";
        
        if ($db_error != 0) 
        {
@@ -99,9 +105,10 @@ function display_db_error($msg, $sql_statement=null, $exit=true)
        }
        
        $str .= "<br><br>";
-
-       trigger_error($str, E_USER_ERROR);
-
+       if($msg)
+               trigger_error($str, E_USER_ERROR);
+       else    // $msg can be null here only in debug mode, otherwise the error is ignored
+               trigger_error($str, E_USER_WARNING);
        if ($exit)
                exit;
 }
@@ -127,8 +134,9 @@ function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_
        if ($db_error != 0) 
        {
                
-               if (!frindly_db_error($db_error))
-                       display_db_error($msg, $sql_statement, false);
+               if (!frindly_db_error($db_error)) {
+                               display_db_error($msg, $sql_statement, false);
+               }
                
                if ($rollback_if_error) 
                {