<?php
namespace Hsi\Firebird\DBAL;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\ForwardCompatibility\Result;
use Doctrine\DBAL\SQLParserUtils;
use Throwable;
/**
* Bez zmian w tej klasie nie działają transakcje
*/
class Connection extends \Doctrine\DBAL\Connection
{
public function prepare($sql)
{
try {
$stmt = new Statement($sql, $this);
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $sql);
}
$stmt->setFetchMode($this->defaultFetchMode);
return $stmt;
}
public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null)
{
// OWN
if ($qcp !== null) {
return $this->executeCacheQuery($sql, $params, $types, $qcp);
}
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger) {
$logger->startQuery($sql, $params, $types);
}
try {
if ($params) {
[$sql, $params, $types] = SQLParserUtils::expandListParameters($sql, $params, $types);
/**
* Poprawki wprowadzone w celu możliwości wyszukania wartości dłuższych niż kolumna,
* co w przypadku whereów na wielu kolumnach jest krytyczną funkcjonalnością.
* PDO na PHP 8.2 jest zbugowane i nie radzi sobie z "named parameters".
*/
$sql = vsprintf($this->prepareSql($sql), $this->prepareParams($connection, $params));
$stmt = $connection->prepare($sql);
$stmt->execute();
} else {
$stmt = $connection->query($sql);
}
} catch (Throwable $e) {
$this->handleExceptionDuringQuery(
$e,
$sql,
$params,
$types
);
}
$stmt->setFetchMode($this->defaultFetchMode);
if ($logger) {
$logger->stopQuery();
}
return $this->ensureForwardCompatibilityStatement($stmt);
}
private function ensureForwardCompatibilityStatement(ResultStatement $stmt)
{
return Result::ensure($stmt);
}
private function prepareParams($connection, $params): array
{
return array_map(function ($value) use ($connection) {
return $connection->quote($value);
}, $params);
}
private function prepareSql($sql)
{
return str_replace('?', "%s", $sql);
}
}