Skip to content

Commit

Permalink
DbQuery: push/pop param count before execution
Browse files Browse the repository at this point in the history
This is for backwards compatibility with legacy code still relying on
DB API functions. Without this, parameter count gets reset after query
execution, which causes issues on PostgreSQL.

Fixes #27113
  • Loading branch information
dregad committed Feb 4, 2021
1 parent 7ebc4c3 commit 066f4bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/classes/DbQuery.class.php
Expand Up @@ -241,6 +241,12 @@ public function set_offset( $p_offset = -1 ) {
* @return IteratorAggregate|boolean ADOdb result set or false if the query failed.
*/
public function execute( array $p_bind_array = null, $p_limit = null, $p_offset = null ) {
# For backwards compatibility with legacy code still relying on DB API,
# we need to save the parameters count before binding otherwise it will
# be reset after query execution, which will cause issues on RDBMS with
# numbered params (e.g. PostgreSQL).
db_param_push();

# bind values if provided
if( null !== $p_bind_array ) {
$this->bind_values( $p_bind_array );
Expand All @@ -251,7 +257,9 @@ public function execute( array $p_bind_array = null, $p_limit = null, $p_offset
$this->process_bind_params();
$this->process_sql_syntax();

return $this->db_execute( $p_limit, $p_offset );
$t_result = $this->db_execute($p_limit, $p_offset);
db_param_pop();
return $t_result;
}

/**
Expand Down

0 comments on commit 066f4bc

Please sign in to comment.