Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e8e4892
Choose a base ref
...
head repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 39a4080
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 27, 2012

  1. Fix utf8 offset when logging SQL in db_query_bound

    The fix for #13280 (5835572) only fixed
    one part of the problem, i.e. when the UTF8 characters were in the SQL
    query itself. This commit fixes the remaining case when the string
    parameters contain multibyte chars.
    
    Fixes #14097
    dregad committed Mar 27, 2012
    Copy the full SHA
    094d4b2 View commit details
  2. Copy the full SHA
    9c210a3 View commit details
  3. Avoid unnecessary execution of query logging code

    As per documentation for $g_show_queries_list, this option should only
    be effective when $g_show_queries_count is ON. However, the global
    variable $g_db_log_queries initialized in database_api.php did not
    reflect this, which resulted in unnecessary execution of the logging
    code in db_query_bound().
    dregad committed Mar 27, 2012
    Copy the full SHA
    39a4080 View commit details
Showing with 14 additions and 14 deletions.
  1. +14 −14 core/database_api.php
28 changes: 14 additions & 14 deletions core/database_api.php
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@
* Store whether to log queries ( used for show_queries_count/query list)
* @global bool $g_db_log_queries
*/
$g_db_log_queries = config_get_global( 'show_queries_list' );
$g_db_log_queries = config_get_global( 'show_queries_count' ) && config_get_global( 'show_queries_list' );

/**
* set adodb fetch mode
@@ -351,39 +351,39 @@ function db_query_bound( $p_query, $arr_parms = null, $p_limit = -1, $p_offset =
$t_elapsed = number_format( microtime(true) - $t_start, 4 );

$lastoffset = 0;
$i = 1;
$i = 0;
if( !( is_null( $arr_parms ) || empty( $arr_parms ) ) ) {
while( preg_match( '/\?/', $p_query, $matches, PREG_OFFSET_CAPTURE, $lastoffset ) ) {
$matches = $matches[0];
# Realign the offset returned by preg_match as it is byte-based,
# which causes issues with UTF-8 characters in the query string
# (e.g. from custom fields names)
$matches[1] = utf8_strlen( substr( $p_query, 0, $matches[1]), mb_internal_encoding() );
$t_utf8_offset = utf8_strlen( substr( $p_query, 0, $matches[1]), mb_internal_encoding() );
if( $i <= count( $arr_parms ) ) {
if( is_null( $arr_parms[$i - 1] ) ) {
if( is_null( $arr_parms[$i] ) ) {
$replace = 'NULL';
}
else if( is_string( $arr_parms[$i - 1] ) ) {
$replace = "'" . $arr_parms[$i - 1] . "'";
else if( is_string( $arr_parms[$i] ) ) {
$replace = "'" . $arr_parms[$i] . "'";
}
else if( is_integer( $arr_parms[$i - 1] ) || is_float( $arr_parms[$i - 1] ) ) {
$replace = (float) $arr_parms[$i - 1];
else if( is_integer( $arr_parms[$i] ) || is_float( $arr_parms[$i] ) ) {
$replace = (float) $arr_parms[$i];
}
else if( is_bool( $arr_parms[$i - 1] ) ) {
else if( is_bool( $arr_parms[$i] ) ) {
switch( $t_db_type ) {
case 'pgsql':
$replace = "'" . $arr_parms[$i - 1] . "'";
$replace = "'" . $arr_parms[$i] . "'";
break;
default:
$replace = $arr_parms[$i - 1];
$replace = $arr_parms[$i];
break;
}
} else {
echo( "Invalid argument type passed to query_bound(): $i" );
echo( "Invalid argument type passed to query_bound(): " . $i + 1 );
exit( 1 );
}
$p_query = utf8_substr( $p_query, 0, $matches[1] ) . $replace . utf8_substr( $p_query, $matches[1] + utf8_strlen( $matches[0] ) );
$lastoffset = $matches[1] + utf8_strlen( $replace );
$p_query = utf8_substr( $p_query, 0, $t_utf8_offset ) . $replace . utf8_substr( $p_query, $t_utf8_offset + utf8_strlen( $matches[0] ) );
$lastoffset = $matches[1] + strlen( $replace ) + 1;
} else {
$lastoffset = $matches[1] + 1;
}