[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 8412:45c680be2d8e
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/45c680be2d8e
user: Dirk Haun <dirk at haun-online.de>
date: Sun Sep 18 13:26:08 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/mssql.class.php | 24 ++++++++++++++++++++----
system/databases/pgsql.class.php | 23 ++++++++++++++++++++---
2 files changed, 40 insertions(+), 7 deletions(-)
diffs (86 lines):
diff -r 932f8094b0c2 -r 45c680be2d8e system/databases/mssql.class.php
--- a/system/databases/mssql.class.php Sun Sep 18 11:43:30 2011 +0200
+++ b/system/databases/mssql.class.php Sun Sep 18 13:26:08 2011 +0200
@@ -988,14 +988,30 @@
{
$msg = mssql_get_last_message();
if (trim($msg)!='') {
+ $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)) {
+ $fn = ' in ' . $fn;
+ }
+ }
if (substr($msg, 0, 7) == 'Caution') {
- $this->_errorlog('SQL Warning: "' . $msg . '" SQL in question: ' . $sql);
+ $this->_errorlog('SQL Warning: "' . $msg . '"$fn. SQL in question: ' . $sql);
} else if (substr($msg, 0, 25) == 'The object was renamed to') {
- $this->_errorlog('Object Renamed: "' . $msg . '" SQL in question: ' . $sql);
+ $this->_errorlog('Object Renamed: "' . $msg . '"$fn. SQL in question: ' . $sql);
} else if (substr($msg, 0, 25) == 'The COLUMN was renamed to') {
- $this->_errorlog('Column Renamed: "' . $msg . '" SQL in question: ' . $sql);
+ $this->_errorlog('Column Renamed: "' . $msg . '"$fn. SQL in question: ' . $sql);
} else {
- $this->_errorlog($msg . ': ' . $msg . ". SQL in question: $sql");
+ $this->_errorlog($msg . ': ' . $msg . "$fn. SQL in question: $sql");
if (true ||$this->_display_error) {
return $msg . ': ' . $sql;
} else {
diff -r 932f8094b0c2 -r 45c680be2d8e system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php Sun Sep 18 11:43:30 2011 +0200
+++ b/system/databases/pgsql.class.php Sun Sep 18 13:26:08 2011 +0200
@@ -833,16 +833,33 @@
*/
function dbError($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)) {
+ $fn = ' in ' . $fn;
+ }
+ }
+
$result = pg_get_result($this->_db);
if ($this->_pgsql_version >= 7.4) {
// this provides a much more detailed error report
if (pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE)) {
$this->_errorlog('You have an error in your SQL query on line '
. pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE)
- . "\nSQL in question: $sql");
+ . "$fn\nSQL in question: $sql");
$this->_errorlog('Error: '
. pg_result_error_field($result, PGSQL_DIAG_SQLSTATE)
- . "\nDescription: "
+ . "$fn\nDescription: "
. pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL));
if ($this->_display_error) {
$error = "An SQL error has occurred in the following SQL: $sql";
@@ -854,7 +871,7 @@
} else {
if (pg_result_error($result)) {
$this->_errorlog(pg_result_error($result)
- . ". SQL in question: $sql");
+ . "$fn. SQL in question: $sql");
if ($this->_display_error) {
$error = 'Error ' . pg_result_error($result);
} else {
More information about the geeklog-cvs
mailing list