From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/doctrine/dbal/src/Driver/PDO/Connection.php | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 vendor/doctrine/dbal/src/Driver/PDO/Connection.php (limited to 'vendor/doctrine/dbal/src/Driver/PDO/Connection.php') diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Connection.php b/vendor/doctrine/dbal/src/Driver/PDO/Connection.php new file mode 100644 index 0000000..b1faca1 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Connection.php @@ -0,0 +1,133 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + public function exec(string $sql): int + { + try { + $result = $this->connection->exec($sql); + + assert($result !== false); + + return $result; + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function getServerVersion(): string + { + return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); + } + + public function prepare(string $sql): Statement + { + try { + $stmt = $this->connection->prepare($sql); + assert($stmt instanceof PDOStatement); + + return new Statement($stmt); + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function query(string $sql): Result + { + try { + $stmt = $this->connection->query($sql); + assert($stmt instanceof PDOStatement); + + return new Result($stmt); + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function quote(string $value): string + { + return $this->connection->quote($value); + } + + public function lastInsertId(): int|string + { + try { + $value = $this->connection->lastInsertId(); + } catch (PDOException $exception) { + assert($exception->errorInfo !== null); + [$sqlState] = $exception->errorInfo; + + // if the PDO driver does not support this capability, PDO::lastInsertId() triggers an IM001 SQLSTATE + // see https://www.php.net/manual/en/pdo.lastinsertid.php + if ($sqlState === 'IM001') { + throw IdentityColumnsNotSupported::new(); + } + + // PDO PGSQL throws a 'lastval is not yet defined in this session' error when no identity value is + // available, with SQLSTATE 55000 'Object Not In Prerequisite State' + if ($sqlState === '55000' && $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME) === 'pgsql') { + throw NoIdentityValue::new($exception); + } + + throw Exception::new($exception); + } + + // pdo_mysql & pdo_sqlite return '0', pdo_sqlsrv returns '' or false depending on the PHP version + if ($value === '0' || $value === '' || $value === false) { + throw NoIdentityValue::new(); + } + + return $value; + } + + public function beginTransaction(): void + { + try { + $this->connection->beginTransaction(); + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function commit(): void + { + try { + $this->connection->commit(); + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function rollBack(): void + { + try { + $this->connection->rollBack(); + } catch (PDOException $exception) { + throw Exception::new($exception); + } + } + + public function getNativeConnection(): PDO + { + return $this->connection; + } +} -- cgit v1.2.3