From c67f9fd41437917b5032c0396ab42704d0870064 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 8 Dec 2008 16:13:41 +0000 Subject: [PATCH] Added development/bugtracking sql trail. --- config.php | 7 +++++++ includes/db/connect_db.inc | 14 ++++++++++++-- sql/alter2.1.sql | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/config.php b/config.php index 8b213cf1..bf0771ba 100644 --- a/config.php +++ b/config.php @@ -25,6 +25,13 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ $show_sql = 0; $go_debug = 1; $pdf_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 + // trail, or your future backup files are overloaded with unneeded data. + // + $sql_trail = 0; // save all sql queries in sql_trail + $select_trail = 0; // track also SELECT queries if ($go_debug == 1) { error_reporting(E_ALL); diff --git a/includes/db/connect_db.inc b/includes/db/connect_db.inc index 223a3798..18c27ac9 100644 --- a/includes/db/connect_db.inc +++ b/includes/db/connect_db.inc @@ -18,7 +18,7 @@ $db_duplicate_error_code = 1062; function db_query($sql, $err_msg=null) { - global $db, $show_sql; + global $db, $show_sql, $sql_trail, $select_trail; //echo "
$sql
"; if ($show_sql) @@ -28,9 +28,19 @@ function db_query($sql, $err_msg=null) echo $sql; echo "\n"; } - + $result = mysql_query($sql, $db); + if($sql_trail) { + if ($select_trail || (strstr($sql, 'SELECT') === false)) { + mysql_query( + "INSERT INTO ".TB_PREF."sql_trail + (`sql`, `result`, `msg`) + VALUES(".db_escape($sql).",".($result ? 1 : 0).", + ".db_escape($err_msg).")", $db); + } + } + if ($err_msg != null) if (function_exists('xdebug_call_file')) check_db_error('
At file '.xdebug_call_file().':'.xdebug_call_line().':
'.$err_msg, $sql); diff --git a/sql/alter2.1.sql b/sql/alter2.1.sql index 62c4b132..d29d00c0 100644 --- a/sql/alter2.1.sql +++ b/sql/alter2.1.sql @@ -206,3 +206,14 @@ ALTER TABLE `0_suppliers` DROP COLUMN `credit_limit`; ALTER TABLE `0_suppliers` ADD `credit_limit` double NOT NULL DEFAULT '0' AFTER `tax_group_id`; ALTER TABLE `0_chart_types` DROP INDEX `name`, ADD INDEX `name` ( `name` ); + +DROP TABLE IF EXISTS `0_sql_trail`; + +CREATE TABLE IF NOT EXISTS `0_sql_trail` ( + `id` int(11) NOT NULL auto_increment, + `sql` text NOT NULL, + `result` tinyint(1) NOT NULL, + `msg` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) TYPE = MyISAM; + -- 2.30.2