2018-11-29 18:45:37 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Db\PostgreSQL;
|
|
|
|
|
2018-12-14 00:47:51 +00:00
|
|
|
class PDOStatement extends Statement {
|
2018-11-29 18:45:37 +00:00
|
|
|
use \JKingWeb\Arsse\Db\PDOError;
|
|
|
|
|
|
|
|
protected $db;
|
|
|
|
protected $st;
|
|
|
|
protected $qOriginal;
|
|
|
|
protected $qMunged;
|
|
|
|
protected $bindings;
|
|
|
|
|
|
|
|
public function __construct(\PDO $db, string $query, array $bindings = []) {
|
2018-12-14 00:47:51 +00:00
|
|
|
$this->db = $db;
|
2018-11-29 18:45:37 +00:00
|
|
|
$this->qOriginal = $query;
|
|
|
|
$this->retypeArray($bindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
unset($this->db, $this->st);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function retypeArray(array $bindings, bool $append = false): bool {
|
|
|
|
if ($append) {
|
|
|
|
return parent::retypeArray($bindings, $append);
|
|
|
|
} else {
|
|
|
|
$this->bindings = $bindings;
|
|
|
|
parent::retypeArray($bindings, $append);
|
|
|
|
$this->qMunged = self::mungeQuery($this->qOriginal, $this->types, false);
|
|
|
|
try {
|
2018-11-29 18:56:15 +00:00
|
|
|
// statement creation with PostgreSQL should never fail (it is not evaluated at creation time)
|
2018-11-29 18:45:37 +00:00
|
|
|
$s = $this->db->prepare($this->qMunged);
|
2018-11-29 18:56:15 +00:00
|
|
|
} catch (\PDOException $e) { // @codeCoverageIgnore
|
|
|
|
list($excClass, $excMsg, $excData) = $this->exceptionBuild(true); // @codeCoverageIgnore
|
|
|
|
throw new $excClass($excMsg, $excData); // @codeCoverageIgnore
|
2018-11-29 18:45:37 +00:00
|
|
|
}
|
2018-11-29 18:56:15 +00:00
|
|
|
$this->st = new \JKingWeb\Arsse\Db\PDOStatement($this->db, $s, $this->bindings);
|
2018-11-29 18:45:37 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function runArray(array $values = []): \JKingWeb\Arsse\Db\Result {
|
|
|
|
return $this->st->runArray($values);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @codeCoverageIgnore */
|
|
|
|
protected function bindValue($value, string $type, int $position): bool {
|
|
|
|
// stub required by abstract parent, but never used
|
2018-12-14 00:47:51 +00:00
|
|
|
return true;
|
2018-11-29 18:45:37 +00:00
|
|
|
}
|
|
|
|
}
|