Commit fc599a74 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#175117 by kbahey: developer improvement: include caller function name and...

#175117 by kbahey: developer improvement: include caller function name and user name in SQL queries for the query log when debug mode is turned on, so debugging gets easier
parent f412b0a5
...@@ -128,17 +128,19 @@ function db_connect($url) { ...@@ -128,17 +128,19 @@ function db_connect($url) {
* Helper function for db_query(). * Helper function for db_query().
*/ */
function _db_query($query, $debug = 0) { function _db_query($query, $debug = 0) {
global $active_db, $queries; global $active_db, $queries, $user;
if (variable_get('dev_query', 0)) { if (variable_get('dev_query', 0)) {
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
$timer = (float)$usec + (float)$sec; $timer = (float)$usec + (float)$sec;
$bt = debug_backtrace();
$name = ($user->uid) ? $user->name : variable_get('anonymous', t('Anonymous'));;
$query = '/* '. $name .' : '. $bt[2]['function'] .' */ '. $query;
} }
$result = mysql_query($query, $active_db); $result = mysql_query($query, $active_db);
if (variable_get('dev_query', 0)) { if (variable_get('dev_query', 0)) {
$bt = debug_backtrace();
$query = $bt[2]['function'] ."\n". $query; $query = $bt[2]['function'] ."\n". $query;
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec; $stop = (float)$usec + (float)$sec;
......
...@@ -125,17 +125,19 @@ function db_connect($url) { ...@@ -125,17 +125,19 @@ function db_connect($url) {
* Helper function for db_query(). * Helper function for db_query().
*/ */
function _db_query($query, $debug = 0) { function _db_query($query, $debug = 0) {
global $active_db, $queries; global $active_db, $queries, $user;
if (variable_get('dev_query', 0)) { if (variable_get('dev_query', 0)) {
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
$timer = (float)$usec + (float)$sec; $timer = (float)$usec + (float)$sec;
$bt = debug_backtrace();
$name = ($user->uid) ? $user->name : variable_get('anonymous', t('Anonymous'));
$query = '/* '. $name .' : '. $bt[2]['function'] .' */ '. $query;
} }
$result = mysqli_query($active_db, $query); $result = mysqli_query($active_db, $query);
if (variable_get('dev_query', 0)) { if (variable_get('dev_query', 0)) {
$bt = debug_backtrace();
$query = $bt[2]['function'] ."\n". $query; $query = $bt[2]['function'] ."\n". $query;
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec; $stop = (float)$usec + (float)$sec;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment