Added development/bugtracking sql trail.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Dec 2008 16:13:41 +0000 (16:13 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Dec 2008 16:13:41 +0000 (16:13 +0000)
config.php
includes/db/connect_db.inc
sql/alter2.1.sql

index 8b213cf1e7ca2ea975ed4d03344398cb46471679..bf0771ba46ba25832d85ee8b4883513b2f09a3ab 100644 (file)
@@ -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);
index 223a37984a0bd6b3b703cfcb933a74cf77261f5b..18c27ac9f7a35c45fba64a4ba1110eb6aadfcb53 100644 (file)
@@ -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 "<br>$sql<br>";
        if ($show_sql)
@@ -28,9 +28,19 @@ function db_query($sql, $err_msg=null)
                echo $sql;
                echo "</pre>\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('<br>At file '.xdebug_call_file().':'.xdebug_call_line().':<br>'.$err_msg, $sql);
index 62c4b132477bff8875e4cbf8634acd4f54bda313..d29d00c076fe794b1c7ca413a81a187a17c2dc9c 100644 (file)
@@ -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;
+