Skip to content

Commit

Permalink
Show_queries count is global variable - only populate query array if …
Browse files Browse the repository at this point in the history
…show queries is on.

git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4693 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
mantis committed Oct 31, 2007
1 parent d570598 commit 745a1f6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 64 deletions.
2 changes: 1 addition & 1 deletion config_defaults_inc.php
Expand Up @@ -141,7 +141,7 @@
# These patterns will be concatenated and used as a regular expression
# to bypass the database lookup and look here for appropriate global settings.
$g_global_settings = array(
'_table$', 'cookie', '^db_', 'hostname', 'database_name',
'_table$', 'cookie', '^db_', 'hostname', 'database_name', 'show_queries_count',
'_path$', 'use_iis', 'language', 'use_javascript', 'display_errors', 'stop_on_errors', 'login_method', '_file$',
'anonymous', 'content_expire', 'html_valid_tags', 'custom_headers', 'rss_key_seed'
);
Expand Down
135 changes: 72 additions & 63 deletions core/database_api.php
Expand Up @@ -158,30 +158,34 @@ function db_is_db2() {
function db_query( $p_query, $p_limit = -1, $p_offset = -1 ) {
global $g_queries_array, $g_db;

$t_start = microtime_float();

if ( ON == config_get_global( 'show_queries_count' ) ) {
$t_start = microtime_float();

$t_backtrace = debug_backtrace();
$t_caller = basename( $t_backtrace[0]['file'] );
$t_caller .= ":" . $t_backtrace[0]['line'];

# Is this called from another function?
if ( isset( $t_backtrace[1] ) ) {
$t_caller .= ' ' . $t_backtrace[1]['function'] . '()';
} else {
# or from a script directly?
$t_caller .= ' ' . $_SERVER['PHP_SELF'];
}
}

if ( ( $p_limit != -1 ) || ( $p_offset != -1 ) ) {
$t_result = $g_db->SelectLimit( $p_query, $p_limit, $p_offset );
} else {
$t_result = $g_db->Execute( $p_query );
}

$t_elapsed = number_format( microtime_float() - $t_start, 4);

$t_backtrace = debug_backtrace();
$t_caller = basename( $t_backtrace[0]['file'] );
$t_caller .= ":" . $t_backtrace[0]['line'];
if ( ON == config_get_global( 'show_queries_count' ) ) {
$t_elapsed = number_format( microtime_float() - $t_start, 4);

# Is this called from another function?
if ( isset( $t_backtrace[1] ) ) {
$t_caller .= ' ' . $t_backtrace[1]['function'] . '()';
} else {
# or from a script directly?
$t_caller .= ' ' . $_SERVER['PHP_SELF'];
array_push ( $g_queries_array, array( $p_query, $t_elapsed, $t_caller ) );
}

array_push ( $g_queries_array, array( $p_query, $t_elapsed, $t_caller ) );


if ( !$t_result ) {
db_error($p_query);
trigger_error( ERROR_DB_QUERY_FAILED, ERROR );
Expand All @@ -194,67 +198,72 @@ function db_query( $p_query, $p_limit = -1, $p_offset = -1 ) {
function db_query_bound($p_query, $arr_parms = null, $p_limit = -1, $p_offset = -1 )
{
global $g_queries_array, $g_db;
$t_db_type = config_get( 'db_type' );

$t_start = microtime_float();
if ( ON == config_get_global( 'show_queries_count' ) ) {
$t_db_type = config_get( 'db_type' );

$t_start = microtime_float();

$t_backtrace = debug_backtrace();
$t_caller = basename( $t_backtrace[0]['file'] );
$t_caller .= ":" . $t_backtrace[0]['line'];

# Is this called from another function?
if ( isset( $t_backtrace[1] ) ) {
$t_caller .= ' ' . $t_backtrace[1]['function'] . '()';
} else {
# or from a script directly?
$t_caller .= ' ' . $_SERVER['PHP_SELF'];
}
}

if ( ( $p_limit != -1 ) || ( $p_offset != -1 ) ) {
$t_result = $g_db->SelectLimit( $p_query, $p_limit, $p_offset, $arr_parms );
} else {
$t_result = $g_db->Execute( $p_query, $arr_parms );
}
$t_elapsed = number_format( microtime_float() - $t_start, 4);

$lastoffset = 0; $i = 1;
if ( false && !is_null( $arr_parms ) ) {
if ($arr_parms[0] === null) {
debug_print_backtrace();
}
while (preg_match('/(\?)/', $p_query, $matches, PREG_OFFSET_CAPTURE, $lastoffset)) {
if ( $i <= count($arr_parms)) {
if (is_null($arr_parms[$i-1]))
$replace = 'NULL';
else if(is_string($arr_parms[$i-1]))
$replace = "'" . $arr_parms[$i-1] . "'";
else if(is_integer($arr_parms[$i-1]) || is_float($arr_parms[$i-1]))
$replace = (float)$arr_parms[$i-1];
else if(is_bool($arr_parms[$i-1]))
switch( $t_db_type ) {
case 'pgsql':
$replace = "'" . $arr_parms[$i-1] . "'";
break;
default:
$replace = $arr_parms[$i-1];
break;
}
if ( ON == config_get_global( 'show_queries_count' ) ) {
$t_elapsed = number_format( microtime_float() - $t_start, 4);

else {
echo("Invalid argument type passed to query_bound(): $i");
exit(1);
$lastoffset = 0; $i = 1;
if ( false && !is_null( $arr_parms ) ) {
if ($arr_parms[0] === null) {
debug_print_backtrace();
}
while (preg_match('/(\?)/', $p_query, $matches, PREG_OFFSET_CAPTURE, $lastoffset)) {
if ( $i <= count($arr_parms)) {
if (is_null($arr_parms[$i-1]))
$replace = 'NULL';
else if(is_string($arr_parms[$i-1]))
$replace = "'" . $arr_parms[$i-1] . "'";
else if(is_integer($arr_parms[$i-1]) || is_float($arr_parms[$i-1]))
$replace = (float)$arr_parms[$i-1];
else if(is_bool($arr_parms[$i-1]))
switch( $t_db_type ) {
case 'pgsql':
$replace = "'" . $arr_parms[$i-1] . "'";
break;
default:
$replace = $arr_parms[$i-1];
break;
}
else {
echo("Invalid argument type passed to query_bound(): $i");
exit(1);
}
$p_query = substr($p_query, 0, $matches[1][1]) . $replace . substr($p_query, $matches[1][1] + strlen($matches[1][0]));
$lastoffset = $matches[1][1] + strlen($replace);
} else {
$lastoffset = $matches[1][1] + 1;
}
$p_query = substr($p_query, 0, $matches[1][1]) . $replace . substr($p_query, $matches[1][1] + strlen($matches[1][0]));
$lastoffset = $matches[1][1] + strlen($replace);
} else {
$lastoffset = $matches[1][1] + 1;
$i++;
}
$i++;
}
}

$t_backtrace = debug_backtrace();
$t_caller = basename( $t_backtrace[0]['file'] );
$t_caller .= ":" . $t_backtrace[0]['line'];

# Is this called from another function?
if ( isset( $t_backtrace[1] ) ) {
$t_caller .= ' ' . $t_backtrace[1]['function'] . '()';
} else {
# or from a script directly?
$t_caller .= ' ' . $_SERVER['PHP_SELF'];
array_push ( $g_queries_array, array( $p_query, $t_elapsed, $t_caller ) );
}

array_push ( $g_queries_array, array( $p_query, $t_elapsed, $t_caller ) );


if ( !$t_result ) {
db_error($p_query);
trigger_error( ERROR_DB_QUERY_FAILED, ERROR );
Expand Down

0 comments on commit 745a1f6

Please sign in to comment.