diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PDO/Statement.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PDO/Statement.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/PDO/Statement.php b/vendor/doctrine/dbal/src/Driver/PDO/Statement.php new file mode 100644 index 0000000..4f0e070 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PDO/Statement.php | |||
@@ -0,0 +1,80 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PDO; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Exception as ExceptionInterface; | ||
8 | use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
9 | use Doctrine\DBAL\ParameterType; | ||
10 | use PDO; | ||
11 | use PDOException; | ||
12 | use PDOStatement; | ||
13 | |||
14 | final class Statement implements StatementInterface | ||
15 | { | ||
16 | /** @internal The statement can be only instantiated by its driver connection. */ | ||
17 | public function __construct(private readonly PDOStatement $stmt) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
22 | { | ||
23 | $pdoType = $this->convertParamType($type); | ||
24 | |||
25 | try { | ||
26 | $this->stmt->bindValue($param, $value, $pdoType); | ||
27 | } catch (PDOException $exception) { | ||
28 | throw Exception::new($exception); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * @internal Driver options can be only specified by a PDO-based driver. | ||
34 | * | ||
35 | * @throws ExceptionInterface | ||
36 | */ | ||
37 | public function bindParamWithDriverOptions( | ||
38 | string|int $param, | ||
39 | mixed &$variable, | ||
40 | ParameterType $type, | ||
41 | mixed $driverOptions, | ||
42 | ): void { | ||
43 | $pdoType = $this->convertParamType($type); | ||
44 | |||
45 | try { | ||
46 | $this->stmt->bindParam($param, $variable, $pdoType, 0, $driverOptions); | ||
47 | } catch (PDOException $exception) { | ||
48 | throw Exception::new($exception); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public function execute(): Result | ||
53 | { | ||
54 | try { | ||
55 | $this->stmt->execute(); | ||
56 | } catch (PDOException $exception) { | ||
57 | throw Exception::new($exception); | ||
58 | } | ||
59 | |||
60 | return new Result($this->stmt); | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * Converts DBAL parameter type to PDO parameter type | ||
65 | * | ||
66 | * @psalm-return PDO::PARAM_* | ||
67 | */ | ||
68 | private function convertParamType(ParameterType $type): int | ||
69 | { | ||
70 | return match ($type) { | ||
71 | ParameterType::NULL => PDO::PARAM_NULL, | ||
72 | ParameterType::INTEGER => PDO::PARAM_INT, | ||
73 | ParameterType::STRING, | ||
74 | ParameterType::ASCII => PDO::PARAM_STR, | ||
75 | ParameterType::BINARY, | ||
76 | ParameterType::LARGE_OBJECT => PDO::PARAM_LOB, | ||
77 | ParameterType::BOOLEAN => PDO::PARAM_BOOL, | ||
78 | }; | ||
79 | } | ||
80 | } | ||