mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-21 01:54:23 +00:00
Fix support for ? parameters as well as named ones.
This commit is contained in:
parent
028481d917
commit
65e26e3a4b
@ -264,35 +264,36 @@ class AwlDBDialect {
|
||||
*/
|
||||
function ReplaceParameters() {
|
||||
$argc = func_num_args();
|
||||
$qry = func_get_arg(0);
|
||||
$args = func_get_args();
|
||||
|
||||
if ( is_array($qry) ) {
|
||||
if ( is_array($args[0]) ) {
|
||||
/**
|
||||
* If the first argument is an array we treat that as our arguments instead
|
||||
*/
|
||||
$qry = $args[0][0];
|
||||
$args = $args[0];
|
||||
$argc = count($args);
|
||||
}
|
||||
$qry = array_shift($args);
|
||||
|
||||
if ( is_array($args[0]) ) {
|
||||
$args = $args[0];
|
||||
$argc = count($args);
|
||||
}
|
||||
|
||||
if ( ! isset($args[0]) ) return $this->ReplaceNamedParameters($qry,$args);
|
||||
|
||||
/**
|
||||
* We only split into a maximum of $argc chunks. Any leftover ? will remain in
|
||||
* the string and may be replaced at Exec rather than Prepare.
|
||||
* the string and may be replaced at Exec rather than Prepare. Scary!
|
||||
*/
|
||||
$parts = explode( '?', $qry, $argc );
|
||||
$parts = explode( '?', $qry, $argc + 1 );
|
||||
$querystring = $parts[0];
|
||||
$z = count($parts);
|
||||
|
||||
for( $i = 1; $i < $z; $i++ ) {
|
||||
for( $i = 0; $i < $argc; $i++ ) {
|
||||
$arg = $args[$i];
|
||||
if ( !isset($arg) ) {
|
||||
$querystring .= 'NULL';
|
||||
}
|
||||
else {
|
||||
$querystring .= $this->Quote($arg); //parameter
|
||||
}
|
||||
$querystring .= $parts[$i]; //extras eg. ","
|
||||
$querystring .= $parts[$i+1]; //extras eg. ","
|
||||
}
|
||||
if ( isset($parts[$z]) ) $querystring .= $parts[$z]; //puts last part on the end
|
||||
|
||||
|
||||
@ -340,7 +340,7 @@ class AwlQuery
|
||||
|
||||
if ( isset($c->expand_pdo_parameters) && $c->expand_pdo_parameters
|
||||
&& isset($this->bound_parameters) ) {
|
||||
$this->bound_querystring = $this->connection->ReplaceNamedParameters($this->querystring,$this->bound_parameters);
|
||||
$this->bound_querystring = $this->connection->ReplaceParameters($this->querystring,$this->bound_parameters);
|
||||
$this->sth = true;
|
||||
}
|
||||
else {
|
||||
@ -370,16 +370,12 @@ class AwlQuery
|
||||
&& isset($c->expand_pdo_parameters) && $c->expand_pdo_parameters
|
||||
&& isset($this->bound_parameters)
|
||||
) {
|
||||
$this->bound_querystring = $this->connection->ReplaceNamedParameters($ths->querystring,$this->bound_parameters);
|
||||
$this->bound_querystring = $this->connection->ReplaceParameters($ths->querystring,$this->bound_parameters);
|
||||
}
|
||||
|
||||
$t1 = microtime(true); // get start time
|
||||
if ( isset($this->bound_querystring) || !isset($this->bound_parameters) ) {
|
||||
if ( ! isset($this->bound_querystring) ) $this->bound_querystring = $this->querystring;
|
||||
// printf( "Bound: %s\n", $this->bound_querystring );
|
||||
// if ( $this->bound_querystring == '' ) {
|
||||
// print_r($this);
|
||||
// }
|
||||
$this->sth = $this->connection->query($this->bound_querystring);
|
||||
$this->bound_querystring = null;
|
||||
if ( ! $this->sth ) {
|
||||
@ -388,7 +384,6 @@ class AwlQuery
|
||||
}
|
||||
}
|
||||
else {
|
||||
// printf( "notbound: %s\n", $this->querystring );
|
||||
if ( ! $this->sth->execute( $this->bound_parameters ) ) {
|
||||
$this->error_info = $this->sth->errorInfo();
|
||||
return false;
|
||||
@ -546,7 +541,7 @@ class AwlQuery
|
||||
if ( ! $success ) {
|
||||
// query failed
|
||||
$this->errorstring = sprintf( 'SQL error "%s" - %s"', $this->error_info[0], (isset($this->error_info[2]) ? $this->error_info[2] : ''));
|
||||
if ( $c->dbg['print_query_errors'] ) {
|
||||
if ( isset($c->dbg['print_query_errors']) && $c->dbg['print_query_errors'] ) {
|
||||
printf( "\n=====================\n" );
|
||||
printf( "%s[%d] QF: %s\n", $file, $line, $this->errorstring);
|
||||
printf( "%s\n", $this->querystring );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user