summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php')
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php109
1 files changed, 109 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php b/vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php
new file mode 100644
index 0000000..1e9af93
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php
@@ -0,0 +1,109 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLite3;
6
7use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
8use Doctrine\DBAL\Driver\Exception\NoIdentityValue;
9use SQLite3;
10
11use function assert;
12use function sprintf;
13
14final class Connection implements ConnectionInterface
15{
16 /** @internal The connection can be only instantiated by its driver. */
17 public function __construct(private readonly SQLite3 $connection)
18 {
19 }
20
21 public function prepare(string $sql): Statement
22 {
23 try {
24 $statement = $this->connection->prepare($sql);
25 } catch (\Exception $e) {
26 throw Exception::new($e);
27 }
28
29 assert($statement !== false);
30
31 return new Statement($this->connection, $statement);
32 }
33
34 public function query(string $sql): Result
35 {
36 try {
37 $result = $this->connection->query($sql);
38 } catch (\Exception $e) {
39 throw Exception::new($e);
40 }
41
42 assert($result !== false);
43
44 return new Result($result, $this->connection->changes());
45 }
46
47 public function quote(string $value): string
48 {
49 return sprintf('\'%s\'', SQLite3::escapeString($value));
50 }
51
52 public function exec(string $sql): int
53 {
54 try {
55 $this->connection->exec($sql);
56 } catch (\Exception $e) {
57 throw Exception::new($e);
58 }
59
60 return $this->connection->changes();
61 }
62
63 public function lastInsertId(): int
64 {
65 $value = $this->connection->lastInsertRowID();
66 if ($value === 0) {
67 throw NoIdentityValue::new();
68 }
69
70 return $value;
71 }
72
73 public function beginTransaction(): void
74 {
75 try {
76 $this->connection->exec('BEGIN');
77 } catch (\Exception $e) {
78 throw Exception::new($e);
79 }
80 }
81
82 public function commit(): void
83 {
84 try {
85 $this->connection->exec('COMMIT');
86 } catch (\Exception $e) {
87 throw Exception::new($e);
88 }
89 }
90
91 public function rollBack(): void
92 {
93 try {
94 $this->connection->exec('ROLLBACK');
95 } catch (\Exception $e) {
96 throw Exception::new($e);
97 }
98 }
99
100 public function getNativeConnection(): SQLite3
101 {
102 return $this->connection;
103 }
104
105 public function getServerVersion(): string
106 {
107 return SQLite3::version()['versionString'];
108 }
109}