[geeklog-cvs] geeklog: When an SQL query fails, try to log the file name and l...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Sep 18 10:26:01 EDT 2011


changeset 8411:932f8094b0c2
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/932f8094b0c2
user: Dirk Haun <dirk at haun-online.de>
date: Sun Sep 18 11:43:30 2011 +0200
description:
When an SQL query fails, try to log the file name and line number where the offending SQL query is located (feature request #0001377)

diffstat:

 system/databases/mysql.class.php  |  19 ++++++++++++++++++-
 system/databases/mysqli.class.php |  19 ++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diffs (58 lines):

diff -r f7004a908c4d -r 932f8094b0c2 system/databases/mysql.class.php
--- a/system/databases/mysql.class.php	Sun Sep 18 11:00:29 2011 +0200
+++ b/system/databases/mysql.class.php	Sun Sep 18 11:43:30 2011 +0200
@@ -692,7 +692,24 @@
     function dbError($sql='')
     {
         if (mysql_errno()) {
-            $this->_errorlog(@mysql_errno() . ': ' . @mysql_error() . ". SQL in question: $sql");        
+            $fn = '';
+            $btr = debug_backtrace();
+            if (! empty($btr)) {
+                for ($i = 0; $i < 100; $i++) {
+                    $b = $btr[$i];
+                    if ($b['function'] == 'DB_query') {
+                        if (!empty($b['file']) && !empty($b['line'])) {
+                            $fn = $b['file'] . ':' . $b['line'];
+                        }
+                        break;
+                    }
+                }
+            }
+            if (empty($fn)) {
+                $this->_errorlog(@mysql_errno() . ': ' . @mysql_error() . ". SQL in question: $sql");
+            } else {
+                $this->_errorlog(@mysql_errno() . ': ' . @mysql_error() . " in $fn. SQL in question: $sql");
+            }
             if ($this->_display_error) {
                 return  @mysql_errno() . ': ' . @mysql_error();
             } else {
diff -r f7004a908c4d -r 932f8094b0c2 system/databases/mysqli.class.php
--- a/system/databases/mysqli.class.php	Sun Sep 18 11:00:29 2011 +0200
+++ b/system/databases/mysqli.class.php	Sun Sep 18 11:43:30 2011 +0200
@@ -627,7 +627,24 @@
     public function dbError($sql = '')
     {
         if ($this->_db->errno) {
-            $this->_errorlog($this->_db->errno . ': ' . $this->_db->error . ". SQL in question: $sql");
+            $fn = '';
+            $btr = debug_backtrace();
+            if (! empty($btr)) {
+                for ($i = 0; $i < 100; $i++) {
+                    $b = $btr[$i];
+                    if ($b['function'] == 'DB_query') {
+                        if (!empty($b['file']) && !empty($b['line'])) {
+                            $fn = $b['file'] . ':' . $b['line'];
+                        }
+                        break;
+                    }
+                }
+            }
+            if (empty($fn)) {
+                $this->_errorlog($this->_db->errno . ': ' . $this->_db->error . ". SQL in question: $sql");
+            } else {
+                $this->_errorlog($this->_db->errno . ': ' . $this->_db->error . " in $fn. SQL in question: $sql");
+            }
 
             if ($this->_display_error) {
                 return  $this->_db->errno . ': ' . $this->_db->error;



More information about the geeklog-cvs mailing list