Implemented changes requested by Wettennet.

PDOStatementWrapper now directly binds parameters. This allows for values such as 'NULL' to be properly utilized.
This commit is contained in:
Abel Hoogeveen 2020-06-13 12:07:06 +02:00
parent 72b404ecc9
commit 6c53eb8cd4
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
2 changed files with 23 additions and 2 deletions

View File

@ -101,7 +101,10 @@ class PDOStatementWrapper
{
// Run the query and benchmark the time
$benchmarkStart = microtime(true);
$result = $this->statement->execute($input_parameters);
if (empty($input_parameters))
$result = $this->statement->execute();
else
$result = $this->statement->execute($input_parameters);
$benchmarkEnd = microtime(true) - $benchmarkStart;
$errInfo = $this->error();
call_user_func_array($this->logQueryCallable, [$this->statement->queryString, $this->statement->rowCount(), $benchmarkEnd, $errInfo]);
@ -128,6 +131,16 @@ class PDOStatementWrapper
return $this->statement;
}
/**
* Returns the query string
*
* @return string
*/
public function getQuery(): string
{
return $this->statement->queryString;
}
/**
* Generates an error message for the last failure in PDO
*

View File

@ -186,7 +186,15 @@ class PDOTableModel implements iDatabaseTableModel
$this->lastStatement = $this->dbEngine->prepare($sql);
// And execute the query
$this->lastStatement->execute($filter);
foreach ($filter as $key => $val)
{
if (is_null($val))
$this->lastStatement->bindValue(':' . $key, $val, PDO::PARAM_NULL);
else
$this->lastStatement->bindValue(':' . $key, $val);
}
$this->lastStatement->execute();
// Fetch PDO Iterable
return new TableModelResult($this->lastStatement->getStatement());