Skip to content

Commit

Permalink
Fix db_query_bound() to work with ADOdb::Execute()
Browse files Browse the repository at this point in the history
In ADOdb v5.19 the Execute() method was modified to perform a strict
type check on the $inputarr parameter. Since that param defaults to
'false', database errors are triggered when the method receives 'null'
and there are no parameters to the query being executed.

Since db_query_bound() $p_arr_parms defaults to null, the problem occurs
almost everywhere. To fix this, we can either:

  1. set $p_arr_parms to array() when it is null
  2. defaut $p_arr_parms to array()

The 2nd option would cause errors with db_query_bound($sql, null)
calls, so we implement the first one as it offers better backwards
compatibility.

Function can be called like this (the first 3 methods being equivalent):
- db_query_bound($sql)
- db_query_bound($sql, null)
- db_query_bound($sql, array())
- db_query_bound($sql, array(1,2))
  • Loading branch information
dregad committed Jul 7, 2014
1 parent 83e1cfd commit fbf016c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/database_api.php
Expand Up @@ -333,7 +333,14 @@ function db_query_bound( $p_query, array $p_arr_parms = null, $p_limit = -1, $p_

$t_start = microtime( true );

if( $p_arr_parms != null && $s_check_params ) {
# This ensures that we don't get an error from ADOdb if $p_arr_parms == null,
# as Execute() expects either an array or false if there are no parameters -
# null actually gets treated as array( 0 => null )
if( is_null( $p_arr_parms ) ) {
$p_arr_parms = array();
}

if( !empty( $p_arr_parms ) && $s_check_params ) {
$t_params = count( $p_arr_parms );
for( $i = 0;$i < $t_params;$i++ ) {
if( $p_arr_parms[$i] === false ) {
Expand All @@ -360,7 +367,7 @@ function db_query_bound( $p_query, array $p_arr_parms = null, $p_limit = -1, $p_
if( ON == $g_db_log_queries ) {
$t_lastoffset = 0;
$i = 0;
if( !( is_null( $p_arr_parms ) || empty( $p_arr_parms ) ) ) {
if( !empty( $p_arr_parms ) ) {
while( preg_match( '/\?/', $p_query, $t_matches, PREG_OFFSET_CAPTURE, $t_lastoffset ) ) {
$t_matches = $t_matches[0];
# Realign the offset returned by preg_match as it is byte-based,
Expand Down

0 comments on commit fbf016c

Please sign in to comment.