[aur-dev] [PATCH 1/1] add SQL_DEBUG variable and database logging
add a hook to db_query to log all sql queries when SQL_DEBUG is set Additionally, provide better logging for sql error situations (provide backtrace as well as error message). --- web/lib/aur.inc | 12 ++++++++++++ web/lib/config.inc.proto | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 4e94340..2c6cd0d 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -238,10 +238,22 @@ function db_query($query="", $db_handle="") { if (!$query) { return FALSE; } + if (!$db_handle) { die("DB handle was not provided to db_query"); } + + if (SQL_DEBUG == 1) { + $bt = debug_backtrace(); + error_log("DEBUG: '".$bt[0]['file'].":".$bt[0]['line']." query: $query\n"); + } + $result = @mysql_query($query, $db_handle); + if (!$result) { + $bt = debug_backtrace(); + error_log("ERROR: near '".$bt[0]['file'].":".$bt[0]['line']." in query: $query\n -> ".mysql_error($db_handle)); + } + return $result; } diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 80a7e54..43c64d2 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -20,6 +20,10 @@ define( "PASSWD_MAX_LEN", 128 ); # Default language for displayed messages in the web interface. define("DEFAULT_LANG", "en"); +# Enable debug sql output. This sends each query to error_log. Useful for +# development. Should not be enabled in production. Default to 0 (off). +define("SQL_DEBUG", 0); + # Languages we have translations for $SUPPORTED_LANGS = array( "ca" => "Català", -- 1.7.4.1
--- web/lib/aur.inc | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 2c6cd0d..f6d6a6c 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -245,7 +245,7 @@ function db_query($query="", $db_handle="") { if (SQL_DEBUG == 1) { $bt = debug_backtrace(); - error_log("DEBUG: '".$bt[0]['file'].":".$bt[0]['line']." query: $query\n"); + error_log("DEBUG: ".$bt[0]['file'].":".$bt[0]['line']." query: $query\n"); } $result = @mysql_query($query, $db_handle); -- 1.7.4.1
--- web/lib/aur.inc | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/web/lib/aur.inc b/web/lib/aur.inc index f6d6a6c..8daba0e 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -251,7 +251,7 @@ function db_query($query="", $db_handle="") { $result = @mysql_query($query, $db_handle); if (!$result) { $bt = debug_backtrace(); - error_log("ERROR: near '".$bt[0]['file'].":".$bt[0]['line']." in query: $query\n -> ".mysql_error($db_handle)); + error_log("ERROR: near ".$bt[0]['file'].":".$bt[0]['line']." in query: $query\n -> ".mysql_error($db_handle)); } return $result; -- 1.7.4.1
On Tue, Apr 26, 2011 at 11:52:11AM -0700, elij wrote:
add a hook to db_query to log all sql queries when SQL_DEBUG is set Additionally, provide better logging for sql error situations (provide backtrace as well as error message). --- web/lib/aur.inc | 12 ++++++++++++ web/lib/config.inc.proto | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-)
Pushed that (after fixing up stuff). I also added some note on merging config file changes to "UPGRADING".
On Wed, Apr 27, 2011 at 9:34 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Apr 26, 2011 at 11:52:11AM -0700, elij wrote:
add a hook to db_query to log all sql queries when SQL_DEBUG is set Additionally, provide better logging for sql error situations (provide backtrace as well as error message). --- web/lib/aur.inc | 12 ++++++++++++ web/lib/config.inc.proto | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-)
Pushed that (after fixing up stuff). I also added some note on merging config file changes to "UPGRADING".
Just curious, but what did you 'fixed up'?
On Wed, Apr 27, 2011 at 1:57 PM, elij <elij.mx@gmail.com> wrote:
On Wed, Apr 27, 2011 at 9:34 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Apr 26, 2011 at 11:52:11AM -0700, elij wrote:
add a hook to db_query to log all sql queries when SQL_DEBUG is set Additionally, provide better logging for sql error situations (provide backtrace as well as error message). --- web/lib/aur.inc | 12 ++++++++++++ web/lib/config.inc.proto | 4 ++++ 2 files changed, 16 insertions(+), 0 deletions(-)
Pushed that (after fixing up stuff). I also added some note on merging config file changes to "UPGRADING".
Just curious, but what did you 'fixed up'?
oh. nevermind. I see you just squashed the previous 'oops forgot to remove this quote mark' fixes. :)
participants (2)
-
elij
-
Lukas Fleischer