Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix db_query_bound() to work with ADOdb::Execute()

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...
commit fbf016c3b497a7b223751fd4cc537904c4810b58 1 parent 83e1cfd
@dregad dregad authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 core/database_api.php
View
11 core/database_api.php
@@ -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 ) {
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.