diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Statement.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Statement.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Statement.php | 143 |
1 files changed, 143 insertions, 0 deletions
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 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
| 8 | use Doctrine\DBAL\Types\Type; | ||
| 9 | |||
| 10 | use function is_string; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * A database abstraction-level statement that implements support for logging, DBAL mapping types, etc. | ||
| 14 | */ | ||
| 15 | class Statement | ||
| 16 | { | ||
| 17 | /** | ||
| 18 | * The bound parameters. | ||
| 19 | * | ||
| 20 | * @var mixed[] | ||
| 21 | */ | ||
| 22 | protected array $params = []; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * The parameter types. | ||
| 26 | * | ||
| 27 | * @var ParameterType[]|string[]|Type[] | ||
| 28 | */ | ||
| 29 | protected array $types = []; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * The underlying database platform. | ||
| 33 | */ | ||
| 34 | protected AbstractPlatform $platform; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>. | ||
| 38 | * | ||
| 39 | * @internal The statement can be only instantiated by {@see Connection}. | ||
| 40 | * | ||
| 41 | * @param Connection $conn The connection for handling statement errors. | ||
| 42 | * @param Driver\Statement $stmt The underlying driver-level statement. | ||
| 43 | * @param string $sql The SQL of the statement. | ||
| 44 | * | ||
| 45 | * @throws Exception | ||
| 46 | */ | ||
| 47 | public function __construct( | ||
| 48 | protected Connection $conn, | ||
| 49 | protected Driver\Statement $stmt, | ||
| 50 | protected string $sql, | ||
| 51 | ) { | ||
| 52 | $this->platform = $conn->getDatabasePlatform(); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Binds a parameter value to the statement. | ||
| 57 | * | ||
| 58 | * The value can optionally be bound with a DBAL mapping type. | ||
| 59 | * If bound with a DBAL mapping type, the binding type is derived from the mapping | ||
| 60 | * type and the value undergoes the conversion routines of the mapping type before | ||
| 61 | * being bound. | ||
| 62 | * | ||
| 63 | * @param string|int $param Parameter identifier. For a prepared statement using named placeholders, | ||
| 64 | * this will be a parameter name of the form :name. For a prepared statement | ||
| 65 | * using question mark placeholders, this will be the 1-indexed position | ||
| 66 | * of the parameter. | ||
| 67 | * @param mixed $value The value to bind to the parameter. | ||
| 68 | * @param ParameterType|string|Type $type Either a {@see \Doctrine\DBAL\ParameterType} or a DBAL mapping type name | ||
| 69 | * or instance. | ||
| 70 | * | ||
| 71 | * @throws Exception | ||
| 72 | */ | ||
| 73 | public function bindValue( | ||
| 74 | string|int $param, | ||
| 75 | mixed $value, | ||
| 76 | string|ParameterType|Type $type = ParameterType::STRING, | ||
| 77 | ): void { | ||
| 78 | $this->params[$param] = $value; | ||
| 79 | $this->types[$param] = $type; | ||
| 80 | |||
| 81 | if (is_string($type)) { | ||
| 82 | $type = Type::getType($type); | ||
| 83 | } | ||
| 84 | |||
| 85 | if ($type instanceof Type) { | ||
| 86 | $value = $type->convertToDatabaseValue($value, $this->platform); | ||
| 87 | $bindingType = $type->getBindingType(); | ||
| 88 | } else { | ||
| 89 | $bindingType = $type; | ||
| 90 | } | ||
| 91 | |||
| 92 | try { | ||
| 93 | $this->stmt->bindValue($param, $value, $bindingType); | ||
| 94 | } catch (Driver\Exception $e) { | ||
| 95 | throw $this->conn->convertException($e); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | /** @throws Exception */ | ||
| 100 | private function execute(): Result | ||
| 101 | { | ||
| 102 | try { | ||
| 103 | return new Result( | ||
| 104 | $this->stmt->execute(), | ||
| 105 | $this->conn, | ||
| 106 | ); | ||
| 107 | } catch (Driver\Exception $ex) { | ||
| 108 | throw $this->conn->convertExceptionDuringQuery($ex, $this->sql, $this->params, $this->types); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Executes the statement with the currently bound parameters and return result. | ||
| 114 | * | ||
| 115 | * @throws Exception | ||
| 116 | */ | ||
| 117 | public function executeQuery(): Result | ||
| 118 | { | ||
| 119 | return $this->execute(); | ||
| 120 | } | ||
| 121 | |||
| 122 | /** | ||
| 123 | * Executes the statement with the currently bound parameters and return affected rows. | ||
| 124 | * | ||
| 125 | * If the number of rows exceeds {@see PHP_INT_MAX}, it might be returned as string if the driver supports it. | ||
| 126 | * | ||
| 127 | * @return int|numeric-string | ||
| 128 | * | ||
| 129 | * @throws Exception | ||
| 130 | */ | ||
| 131 | public function executeStatement(): int|string | ||
| 132 | { | ||
| 133 | return $this->execute()->rowCount(); | ||
| 134 | } | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Gets the wrapped driver statement. | ||
| 138 | */ | ||
| 139 | public function getWrappedStatement(): Driver\Statement | ||
| 140 | { | ||
| 141 | return $this->stmt; | ||
| 142 | } | ||
| 143 | } | ||
