summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/SQLite3
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Driver/SQLite3
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLite3')
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php109
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Driver.php48
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Exception.php20
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Result.php88
-rw-r--r--vendor/doctrine/dbal/src/Driver/SQLite3/Statement.php61
5 files changed, 326 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}
diff --git a/vendor/doctrine/dbal/src/Driver/SQLite3/Driver.php b/vendor/doctrine/dbal/src/Driver/SQLite3/Driver.php
new file mode 100644
index 0000000..e6996d3
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/SQLite3/Driver.php
@@ -0,0 +1,48 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLite3;
6
7use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
8use SensitiveParameter;
9use SQLite3;
10
11final class Driver extends AbstractSQLiteDriver
12{
13 /**
14 * {@inheritDoc}
15 */
16 public function connect(
17 #[SensitiveParameter]
18 array $params,
19 ): Connection {
20 $isMemory = $params['memory'] ?? false;
21
22 if (isset($params['path'])) {
23 if ($isMemory) {
24 throw new Exception(
25 'Invalid connection settings: specifying both parameters "path" and "memory" is ambiguous.',
26 );
27 }
28
29 $filename = $params['path'];
30 } elseif ($isMemory) {
31 $filename = ':memory:';
32 } else {
33 throw new Exception(
34 'Invalid connection settings: specify either the "path" or the "memory" parameter for SQLite3.',
35 );
36 }
37
38 try {
39 $connection = new SQLite3($filename);
40 } catch (\Exception $e) {
41 throw Exception::new($e);
42 }
43
44 $connection->enableExceptions(true);
45
46 return new Connection($connection);
47 }
48}
diff --git a/vendor/doctrine/dbal/src/Driver/SQLite3/Exception.php b/vendor/doctrine/dbal/src/Driver/SQLite3/Exception.php
new file mode 100644
index 0000000..d423004
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/SQLite3/Exception.php
@@ -0,0 +1,20 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLite3;
6
7use Doctrine\DBAL\Driver\AbstractException;
8
9/**
10 * @internal
11 *
12 * @psalm-immutable
13 */
14final class Exception extends AbstractException
15{
16 public static function new(\Exception $exception): self
17 {
18 return new self($exception->getMessage(), null, (int) $exception->getCode(), $exception);
19 }
20}
diff --git a/vendor/doctrine/dbal/src/Driver/SQLite3/Result.php b/vendor/doctrine/dbal/src/Driver/SQLite3/Result.php
new file mode 100644
index 0000000..61b42d3
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/SQLite3/Result.php
@@ -0,0 +1,88 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLite3;
6
7use Doctrine\DBAL\Driver\FetchUtils;
8use Doctrine\DBAL\Driver\Result as ResultInterface;
9use SQLite3Result;
10
11use const SQLITE3_ASSOC;
12use const SQLITE3_NUM;
13
14final class Result implements ResultInterface
15{
16 private ?SQLite3Result $result;
17
18 /** @internal The result can be only instantiated by its driver connection or statement. */
19 public function __construct(SQLite3Result $result, private readonly int $changes)
20 {
21 $this->result = $result;
22 }
23
24 public function fetchNumeric(): array|false
25 {
26 if ($this->result === null) {
27 return false;
28 }
29
30 return $this->result->fetchArray(SQLITE3_NUM);
31 }
32
33 public function fetchAssociative(): array|false
34 {
35 if ($this->result === null) {
36 return false;
37 }
38
39 return $this->result->fetchArray(SQLITE3_ASSOC);
40 }
41
42 public function fetchOne(): mixed
43 {
44 return FetchUtils::fetchOne($this);
45 }
46
47 /** @inheritDoc */
48 public function fetchAllNumeric(): array
49 {
50 return FetchUtils::fetchAllNumeric($this);
51 }
52
53 /** @inheritDoc */
54 public function fetchAllAssociative(): array
55 {
56 return FetchUtils::fetchAllAssociative($this);
57 }
58
59 /** @inheritDoc */
60 public function fetchFirstColumn(): array
61 {
62 return FetchUtils::fetchFirstColumn($this);
63 }
64
65 public function rowCount(): int
66 {
67 return $this->changes;
68 }
69
70 public function columnCount(): int
71 {
72 if ($this->result === null) {
73 return 0;
74 }
75
76 return $this->result->numColumns();
77 }
78
79 public function free(): void
80 {
81 if ($this->result === null) {
82 return;
83 }
84
85 $this->result->finalize();
86 $this->result = null;
87 }
88}
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
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\SQLite3;
6
7use Doctrine\DBAL\Driver\Statement as StatementInterface;
8use Doctrine\DBAL\ParameterType;
9use SQLite3;
10use SQLite3Stmt;
11
12use function assert;
13
14use const SQLITE3_BLOB;
15use const SQLITE3_INTEGER;
16use const SQLITE3_NULL;
17use const SQLITE3_TEXT;
18
19final 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}