diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php b/vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php new file mode 100644 index 0000000..fe22e1d --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php | |||
@@ -0,0 +1,61 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\SQLite3; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
8 | use Doctrine\DBAL\ParameterType; | ||
9 | use SQLite3; | ||
10 | use SQLite3Stmt; | ||
11 | |||
12 | use function assert; | ||
13 | |||
14 | use const SQLITE3_BLOB; | ||
15 | use const SQLITE3_INTEGER; | ||
16 | use const SQLITE3_NULL; | ||
17 | use const SQLITE3_TEXT; | ||
18 | |||
19 | final class Statement implements StatementInterface | ||
20 | { | ||
21 | private const TYPE_BLOB = SQLITE3_BLOB; | ||
22 | private const TYPE_INTEGER = SQLITE3_INTEGER; | ||
23 | private const TYPE_NULL = SQLITE3_NULL; | ||
24 | private const TYPE_TEXT = SQLITE3_TEXT; | ||
25 | |||
26 | /** @internal The statement can be only instantiated by its driver connection. */ | ||
27 | public function __construct( | ||
28 | private readonly SQLite3 $connection, | ||
29 | private readonly SQLite3Stmt $statement, | ||
30 | ) { | ||
31 | } | ||
32 | |||
33 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
34 | { | ||
35 | $this->statement->bindValue($param, $value, $this->convertParamType($type)); | ||
36 | } | ||
37 | |||
38 | public function execute(): Result | ||
39 | { | ||
40 | try { | ||
41 | $result = $this->statement->execute(); | ||
42 | } catch (\Exception $e) { | ||
43 | throw Exception::new($e); | ||
44 | } | ||
45 | |||
46 | assert($result !== false); | ||
47 | |||
48 | return new Result($result, $this->connection->changes()); | ||
49 | } | ||
50 | |||
51 | /** @psalm-return self::TYPE_* */ | ||
52 | private function convertParamType(ParameterType $type): int | ||
53 | { | ||
54 | return match ($type) { | ||
55 | ParameterType::NULL => self::TYPE_NULL, | ||
56 | ParameterType::INTEGER, ParameterType::BOOLEAN => self::TYPE_INTEGER, | ||
57 | ParameterType::STRING, ParameterType::ASCII => self::TYPE_TEXT, | ||
58 | ParameterType::BINARY, ParameterType::LARGE_OBJECT => self::TYPE_BLOB, | ||
59 | }; | ||
60 | } | ||
61 | } | ||