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/Driver/SQLite3/Connection.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/Driver/SQLite3/Connection.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/SQLite3/Connection.php | 109 |
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 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\SQLite3; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
| 8 | use Doctrine\DBAL\Driver\Exception\NoIdentityValue; | ||
| 9 | use SQLite3; | ||
| 10 | |||
| 11 | use function assert; | ||
| 12 | use function sprintf; | ||
| 13 | |||
| 14 | final 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 | } | ||
