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/Statement.php | 143 +++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 vendor/doctrine/dbal/src/Statement.php (limited to 'vendor/doctrine/dbal/src/Statement.php') diff --git a/vendor/doctrine/dbal/src/Statement.php b/vendor/doctrine/dbal/src/Statement.php new file mode 100644 index 0000000..9b4a3b4 --- /dev/null +++ b/vendor/doctrine/dbal/src/Statement.php @@ -0,0 +1,143 @@ +Statement for the given SQL and Connection. + * + * @internal The statement can be only instantiated by {@see Connection}. + * + * @param Connection $conn The connection for handling statement errors. + * @param Driver\Statement $stmt The underlying driver-level statement. + * @param string $sql The SQL of the statement. + * + * @throws Exception + */ + public function __construct( + protected Connection $conn, + protected Driver\Statement $stmt, + protected string $sql, + ) { + $this->platform = $conn->getDatabasePlatform(); + } + + /** + * Binds a parameter value to the statement. + * + * The value can optionally be bound with a DBAL mapping type. + * If bound with a DBAL mapping type, the binding type is derived from the mapping + * type and the value undergoes the conversion routines of the mapping type before + * being bound. + * + * @param string|int $param Parameter identifier. For a prepared statement using named placeholders, + * this will be a parameter name of the form :name. For a prepared statement + * using question mark placeholders, this will be the 1-indexed position + * of the parameter. + * @param mixed $value The value to bind to the parameter. + * @param ParameterType|string|Type $type Either a {@see \Doctrine\DBAL\ParameterType} or a DBAL mapping type name + * or instance. + * + * @throws Exception + */ + public function bindValue( + string|int $param, + mixed $value, + string|ParameterType|Type $type = ParameterType::STRING, + ): void { + $this->params[$param] = $value; + $this->types[$param] = $type; + + if (is_string($type)) { + $type = Type::getType($type); + } + + if ($type instanceof Type) { + $value = $type->convertToDatabaseValue($value, $this->platform); + $bindingType = $type->getBindingType(); + } else { + $bindingType = $type; + } + + try { + $this->stmt->bindValue($param, $value, $bindingType); + } catch (Driver\Exception $e) { + throw $this->conn->convertException($e); + } + } + + /** @throws Exception */ + private function execute(): Result + { + try { + return new Result( + $this->stmt->execute(), + $this->conn, + ); + } catch (Driver\Exception $ex) { + throw $this->conn->convertExceptionDuringQuery($ex, $this->sql, $this->params, $this->types); + } + } + + /** + * Executes the statement with the currently bound parameters and return result. + * + * @throws Exception + */ + public function executeQuery(): Result + { + return $this->execute(); + } + + /** + * Executes the statement with the currently bound parameters and return affected rows. + * + * If the number of rows exceeds {@see PHP_INT_MAX}, it might be returned as string if the driver supports it. + * + * @return int|numeric-string + * + * @throws Exception + */ + public function executeStatement(): int|string + { + return $this->execute()->rowCount(); + } + + /** + * Gets the wrapped driver statement. + */ + public function getWrappedStatement(): Driver\Statement + { + return $this->stmt; + } +} -- cgit v1.2.3