vendor/hsi/firebird/src/DBAL/Connection.php line 29

Open in your IDE?
  1. <?php
  2. namespace Hsi\Firebird\DBAL;
  3. use Doctrine\DBAL\Cache\QueryCacheProfile;
  4. use Doctrine\DBAL\Driver\ResultStatement;
  5. use Doctrine\DBAL\ForwardCompatibility\Result;
  6. use Doctrine\DBAL\SQLParserUtils;
  7. use Throwable;
  8. /**
  9.  * Bez zmian w tej klasie nie działają transakcje
  10.  */
  11. class Connection extends \Doctrine\DBAL\Connection
  12. {
  13.     public function prepare($sql)
  14.     {
  15.         try {
  16.             $stmt = new Statement($sql, $this);
  17.         } catch (Throwable $e) {
  18.             $this->handleExceptionDuringQuery($e, $sql);
  19.         }
  20.         $stmt->setFetchMode($this->defaultFetchMode);
  21.         return $stmt;
  22.     }
  23.     public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null)
  24.     {
  25.         // OWN
  26.         if ($qcp !== null) {
  27.             return $this->executeCacheQuery($sql, $params, $types, $qcp);
  28.         }
  29.         $connection = $this->getWrappedConnection();
  30.         $logger = $this->_config->getSQLLogger();
  31.         if ($logger) {
  32.             $logger->startQuery($sql, $params, $types);
  33.         }
  34.         try {
  35.             if ($params) {
  36.                 [$sql, $params, $types] = SQLParserUtils::expandListParameters($sql, $params, $types);
  37.                 /**
  38.                  * Poprawki wprowadzone w celu możliwości wyszukania wartości dłuższych niż kolumna,
  39.                  * co w przypadku whereów na wielu kolumnach jest krytyczną funkcjonalnością.
  40.                  * PDO na PHP 8.2 jest zbugowane i nie radzi sobie z "named parameters".
  41.                  */
  42.                 $sql = vsprintf($this->prepareSql($sql), $this->prepareParams($connection, $params));
  43.                 $stmt = $connection->prepare($sql);
  44.                 $stmt->execute();
  45.             } else {
  46.                 $stmt = $connection->query($sql);
  47.             }
  48.         } catch (Throwable $e) {
  49.             $this->handleExceptionDuringQuery(
  50.                 $e,
  51.                 $sql,
  52.                 $params,
  53.                 $types
  54.             );
  55.         }
  56.         $stmt->setFetchMode($this->defaultFetchMode);
  57.         if ($logger) {
  58.             $logger->stopQuery();
  59.         }
  60.         return $this->ensureForwardCompatibilityStatement($stmt);
  61.     }
  62.     private function ensureForwardCompatibilityStatement(ResultStatement $stmt)
  63.     {
  64.         return Result::ensure($stmt);
  65.     }
  66.     private function prepareParams($connection, $params): array
  67.     {
  68.         return array_map(function ($value) use ($connection) {
  69.             return $connection->quote($value);
  70.         }, $params);
  71.     }
  72.     private function prepareSql($sql)
  73.     {
  74.         return str_replace('?', "%s", $sql);
  75.     }
  76. }