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/IBMDB2/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/IBMDB2/Connection.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Driver/IBMDB2/Connection.php | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/Connection.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/Connection.php new file mode 100644 index 0000000..2c8783b --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/Connection.php | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\IBMDB2; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
| 8 | use Doctrine\DBAL\Driver\Exception\NoIdentityValue; | ||
| 9 | use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionError; | ||
| 10 | use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed; | ||
| 11 | use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError; | ||
| 12 | use stdClass; | ||
| 13 | |||
| 14 | use function assert; | ||
| 15 | use function db2_autocommit; | ||
| 16 | use function db2_commit; | ||
| 17 | use function db2_escape_string; | ||
| 18 | use function db2_exec; | ||
| 19 | use function db2_last_insert_id; | ||
| 20 | use function db2_num_rows; | ||
| 21 | use function db2_prepare; | ||
| 22 | use function db2_rollback; | ||
| 23 | use function db2_server_info; | ||
| 24 | use function error_get_last; | ||
| 25 | |||
| 26 | use const DB2_AUTOCOMMIT_OFF; | ||
| 27 | use const DB2_AUTOCOMMIT_ON; | ||
| 28 | |||
| 29 | final class Connection implements ConnectionInterface | ||
| 30 | { | ||
| 31 | /** | ||
| 32 | * @internal The connection can be only instantiated by its driver. | ||
| 33 | * | ||
| 34 | * @param resource $connection | ||
| 35 | */ | ||
| 36 | public function __construct(private readonly mixed $connection) | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | public function getServerVersion(): string | ||
| 41 | { | ||
| 42 | $serverInfo = db2_server_info($this->connection); | ||
| 43 | assert($serverInfo instanceof stdClass); | ||
| 44 | |||
| 45 | return $serverInfo->DBMS_VER; | ||
| 46 | } | ||
| 47 | |||
| 48 | public function prepare(string $sql): Statement | ||
| 49 | { | ||
| 50 | $stmt = @db2_prepare($this->connection, $sql); | ||
| 51 | |||
| 52 | if ($stmt === false) { | ||
| 53 | throw PrepareFailed::new(error_get_last()); | ||
| 54 | } | ||
| 55 | |||
| 56 | return new Statement($stmt); | ||
| 57 | } | ||
| 58 | |||
| 59 | public function query(string $sql): Result | ||
| 60 | { | ||
| 61 | return $this->prepare($sql)->execute(); | ||
| 62 | } | ||
| 63 | |||
| 64 | public function quote(string $value): string | ||
| 65 | { | ||
| 66 | return "'" . db2_escape_string($value) . "'"; | ||
| 67 | } | ||
| 68 | |||
| 69 | public function exec(string $sql): int|string | ||
| 70 | { | ||
| 71 | $stmt = @db2_exec($this->connection, $sql); | ||
| 72 | |||
| 73 | if ($stmt === false) { | ||
| 74 | throw StatementError::new(); | ||
| 75 | } | ||
| 76 | |||
| 77 | $numRows = db2_num_rows($stmt); | ||
| 78 | |||
| 79 | if ($numRows === false) { | ||
| 80 | throw StatementError::new(); | ||
| 81 | } | ||
| 82 | |||
| 83 | return $numRows; | ||
| 84 | } | ||
| 85 | |||
| 86 | public function lastInsertId(): string | ||
| 87 | { | ||
| 88 | $lastInsertId = db2_last_insert_id($this->connection); | ||
| 89 | |||
| 90 | if ($lastInsertId === null) { | ||
| 91 | throw NoIdentityValue::new(); | ||
| 92 | } | ||
| 93 | |||
| 94 | return $lastInsertId; | ||
| 95 | } | ||
| 96 | |||
| 97 | public function beginTransaction(): void | ||
| 98 | { | ||
| 99 | if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_OFF) !== true) { | ||
| 100 | throw ConnectionError::new($this->connection); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | public function commit(): void | ||
| 105 | { | ||
| 106 | if (! db2_commit($this->connection)) { | ||
| 107 | throw ConnectionError::new($this->connection); | ||
| 108 | } | ||
| 109 | |||
| 110 | if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) { | ||
| 111 | throw ConnectionError::new($this->connection); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | public function rollBack(): void | ||
| 116 | { | ||
| 117 | if (! db2_rollback($this->connection)) { | ||
| 118 | throw ConnectionError::new($this->connection); | ||
| 119 | } | ||
| 120 | |||
| 121 | if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) { | ||
| 122 | throw ConnectionError::new($this->connection); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | /** @return resource */ | ||
| 127 | public function getNativeConnection() | ||
| 128 | { | ||
| 129 | return $this->connection; | ||
| 130 | } | ||
| 131 | } | ||
