Skip to content

Commit

Permalink
Make index variable 0-based to optimize and make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
dregad committed Mar 27, 2012
1 parent 50f45ad commit ba21cce
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/database_api.php
Expand Up @@ -328,7 +328,7 @@ function db_query_bound( $p_query, $arr_parms = null, $p_limit = -1, $p_offset =

if( ON == $g_db_log_queries ) {
$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];
Expand All @@ -337,26 +337,26 @@ function db_query_bound( $p_query, $arr_parms = null, $p_limit = -1, $p_offset =
# (e.g. from custom fields names)
$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, $t_utf8_offset ) . $replace . utf8_substr( $p_query, $t_utf8_offset + utf8_strlen( $matches[0] ) );
Expand Down

0 comments on commit ba21cce

Please sign in to comment.