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/OCI8 | |
| 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/OCI8')
12 files changed, 662 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Connection.php b/vendor/doctrine/dbal/src/Driver/OCI8/Connection.php new file mode 100644 index 0000000..3652ca0 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Connection.php | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
| 8 | use Doctrine\DBAL\Driver\Exception; | ||
| 9 | use Doctrine\DBAL\Driver\Exception\IdentityColumnsNotSupported; | ||
| 10 | use Doctrine\DBAL\Driver\OCI8\Exception\Error; | ||
| 11 | use Doctrine\DBAL\SQL\Parser; | ||
| 12 | |||
| 13 | use function addcslashes; | ||
| 14 | use function assert; | ||
| 15 | use function is_resource; | ||
| 16 | use function oci_commit; | ||
| 17 | use function oci_parse; | ||
| 18 | use function oci_rollback; | ||
| 19 | use function oci_server_version; | ||
| 20 | use function preg_match; | ||
| 21 | use function str_replace; | ||
| 22 | |||
| 23 | final class Connection implements ConnectionInterface | ||
| 24 | { | ||
| 25 | private readonly Parser $parser; | ||
| 26 | private readonly ExecutionMode $executionMode; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * @internal The connection can be only instantiated by its driver. | ||
| 30 | * | ||
| 31 | * @param resource $connection | ||
| 32 | */ | ||
| 33 | public function __construct(private readonly mixed $connection) | ||
| 34 | { | ||
| 35 | $this->parser = new Parser(false); | ||
| 36 | $this->executionMode = new ExecutionMode(); | ||
| 37 | } | ||
| 38 | |||
| 39 | public function getServerVersion(): string | ||
| 40 | { | ||
| 41 | $version = oci_server_version($this->connection); | ||
| 42 | assert($version !== false); | ||
| 43 | |||
| 44 | $result = preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches); | ||
| 45 | assert($result === 1); | ||
| 46 | |||
| 47 | return $matches[1]; | ||
| 48 | } | ||
| 49 | |||
| 50 | /** @throws Parser\Exception */ | ||
| 51 | public function prepare(string $sql): Statement | ||
| 52 | { | ||
| 53 | $visitor = new ConvertPositionalToNamedPlaceholders(); | ||
| 54 | |||
| 55 | $this->parser->parse($sql, $visitor); | ||
| 56 | |||
| 57 | $statement = oci_parse($this->connection, $visitor->getSQL()); | ||
| 58 | assert(is_resource($statement)); | ||
| 59 | |||
| 60 | return new Statement($this->connection, $statement, $visitor->getParameterMap(), $this->executionMode); | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * @throws Exception | ||
| 65 | * @throws Parser\Exception | ||
| 66 | */ | ||
| 67 | public function query(string $sql): Result | ||
| 68 | { | ||
| 69 | return $this->prepare($sql)->execute(); | ||
| 70 | } | ||
| 71 | |||
| 72 | public function quote(string $value): string | ||
| 73 | { | ||
| 74 | return "'" . addcslashes(str_replace("'", "''", $value), "\000\n\r\\\032") . "'"; | ||
| 75 | } | ||
| 76 | |||
| 77 | /** | ||
| 78 | * @throws Exception | ||
| 79 | * @throws Parser\Exception | ||
| 80 | */ | ||
| 81 | public function exec(string $sql): int|string | ||
| 82 | { | ||
| 83 | return $this->prepare($sql)->execute()->rowCount(); | ||
| 84 | } | ||
| 85 | |||
| 86 | public function lastInsertId(): int|string | ||
| 87 | { | ||
| 88 | throw IdentityColumnsNotSupported::new(); | ||
| 89 | } | ||
| 90 | |||
| 91 | public function beginTransaction(): void | ||
| 92 | { | ||
| 93 | $this->executionMode->disableAutoCommit(); | ||
| 94 | } | ||
| 95 | |||
| 96 | public function commit(): void | ||
| 97 | { | ||
| 98 | if (! oci_commit($this->connection)) { | ||
| 99 | throw Error::new($this->connection); | ||
| 100 | } | ||
| 101 | |||
| 102 | $this->executionMode->enableAutoCommit(); | ||
| 103 | } | ||
| 104 | |||
| 105 | public function rollBack(): void | ||
| 106 | { | ||
| 107 | if (! oci_rollback($this->connection)) { | ||
| 108 | throw Error::new($this->connection); | ||
| 109 | } | ||
| 110 | |||
| 111 | $this->executionMode->enableAutoCommit(); | ||
| 112 | } | ||
| 113 | |||
| 114 | /** @return resource */ | ||
| 115 | public function getNativeConnection() | ||
| 116 | { | ||
| 117 | return $this->connection; | ||
| 118 | } | ||
| 119 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php b/vendor/doctrine/dbal/src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php new file mode 100644 index 0000000..5898a2c --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\SQL\Parser\Visitor; | ||
| 8 | |||
| 9 | use function count; | ||
| 10 | use function implode; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Converts positional (?) into named placeholders (:param<num>). | ||
| 14 | * | ||
| 15 | * Oracle does not support positional parameters, hence this method converts all | ||
| 16 | * positional parameters into artificially named parameters. | ||
| 17 | * | ||
| 18 | * @internal This class is not covered by the backward compatibility promise | ||
| 19 | */ | ||
| 20 | final class ConvertPositionalToNamedPlaceholders implements Visitor | ||
| 21 | { | ||
| 22 | /** @var list<string> */ | ||
| 23 | private array $buffer = []; | ||
| 24 | |||
| 25 | /** @var array<int,string> */ | ||
| 26 | private array $parameterMap = []; | ||
| 27 | |||
| 28 | public function acceptOther(string $sql): void | ||
| 29 | { | ||
| 30 | $this->buffer[] = $sql; | ||
| 31 | } | ||
| 32 | |||
| 33 | public function acceptPositionalParameter(string $sql): void | ||
| 34 | { | ||
| 35 | $position = count($this->parameterMap) + 1; | ||
| 36 | $param = ':param' . $position; | ||
| 37 | |||
| 38 | $this->parameterMap[$position] = $param; | ||
| 39 | |||
| 40 | $this->buffer[] = $param; | ||
| 41 | } | ||
| 42 | |||
| 43 | public function acceptNamedParameter(string $sql): void | ||
| 44 | { | ||
| 45 | $this->buffer[] = $sql; | ||
| 46 | } | ||
| 47 | |||
| 48 | public function getSQL(): string | ||
| 49 | { | ||
| 50 | return implode('', $this->buffer); | ||
| 51 | } | ||
| 52 | |||
| 53 | /** @return array<int,string> */ | ||
| 54 | public function getParameterMap(): array | ||
| 55 | { | ||
| 56 | return $this->parameterMap; | ||
| 57 | } | ||
| 58 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Driver.php b/vendor/doctrine/dbal/src/Driver/OCI8/Driver.php new file mode 100644 index 0000000..1b0afbf --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Driver.php | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractOracleDriver; | ||
| 8 | use Doctrine\DBAL\Driver\OCI8\Exception\ConnectionFailed; | ||
| 9 | use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration; | ||
| 10 | use SensitiveParameter; | ||
| 11 | |||
| 12 | use function oci_connect; | ||
| 13 | use function oci_new_connect; | ||
| 14 | use function oci_pconnect; | ||
| 15 | |||
| 16 | use const OCI_NO_AUTO_COMMIT; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions. | ||
| 20 | */ | ||
| 21 | final class Driver extends AbstractOracleDriver | ||
| 22 | { | ||
| 23 | /** | ||
| 24 | * {@inheritDoc} | ||
| 25 | */ | ||
| 26 | public function connect( | ||
| 27 | #[SensitiveParameter] | ||
| 28 | array $params, | ||
| 29 | ): Connection { | ||
| 30 | $username = $params['user'] ?? ''; | ||
| 31 | $password = $params['password'] ?? ''; | ||
| 32 | $charset = $params['charset'] ?? ''; | ||
| 33 | $sessionMode = $params['sessionMode'] ?? OCI_NO_AUTO_COMMIT; | ||
| 34 | |||
| 35 | $connectionString = $this->getEasyConnectString($params); | ||
| 36 | |||
| 37 | /** @psalm-suppress RiskyTruthyFalsyComparison */ | ||
| 38 | $persistent = ! empty($params['persistent']); | ||
| 39 | /** @psalm-suppress RiskyTruthyFalsyComparison */ | ||
| 40 | $exclusive = ! empty($params['driverOptions']['exclusive']); | ||
| 41 | |||
| 42 | if ($persistent && $exclusive) { | ||
| 43 | throw InvalidConfiguration::forPersistentAndExclusive(); | ||
| 44 | } | ||
| 45 | |||
| 46 | if ($persistent) { | ||
| 47 | $connection = @oci_pconnect($username, $password, $connectionString, $charset, $sessionMode); | ||
| 48 | } elseif ($exclusive) { | ||
| 49 | $connection = @oci_new_connect($username, $password, $connectionString, $charset, $sessionMode); | ||
| 50 | } else { | ||
| 51 | $connection = @oci_connect($username, $password, $connectionString, $charset, $sessionMode); | ||
| 52 | } | ||
| 53 | |||
| 54 | if ($connection === false) { | ||
| 55 | throw ConnectionFailed::new(); | ||
| 56 | } | ||
| 57 | |||
| 58 | return new Connection($connection); | ||
| 59 | } | ||
| 60 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php new file mode 100644 index 0000000..cefe9a3 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Exception; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractException; | ||
| 8 | |||
| 9 | use function assert; | ||
| 10 | use function oci_error; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @internal | ||
| 14 | * | ||
| 15 | * @psalm-immutable | ||
| 16 | */ | ||
| 17 | final class ConnectionFailed extends AbstractException | ||
| 18 | { | ||
| 19 | public static function new(): self | ||
| 20 | { | ||
| 21 | $error = oci_error(); | ||
| 22 | assert($error !== false); | ||
| 23 | |||
| 24 | return new self($error['message'], null, $error['code']); | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Exception/Error.php b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/Error.php new file mode 100644 index 0000000..6abdf23 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/Error.php | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Exception; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractException; | ||
| 8 | |||
| 9 | use function assert; | ||
| 10 | use function oci_error; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @internal | ||
| 14 | * | ||
| 15 | * @psalm-immutable | ||
| 16 | */ | ||
| 17 | final class Error extends AbstractException | ||
| 18 | { | ||
| 19 | /** @param resource $resource */ | ||
| 20 | public static function new($resource): self | ||
| 21 | { | ||
| 22 | $error = oci_error($resource); | ||
| 23 | assert($error !== false); | ||
| 24 | |||
| 25 | return new self($error['message'], null, $error['code']); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php new file mode 100644 index 0000000..e9d2d0e --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Exception; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractException; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @internal | ||
| 11 | * | ||
| 12 | * @psalm-immutable | ||
| 13 | */ | ||
| 14 | final class InvalidConfiguration extends AbstractException | ||
| 15 | { | ||
| 16 | public static function forPersistentAndExclusive(): self | ||
| 17 | { | ||
| 18 | return new self('The "persistent" parameter and the "exclusive" driver option are mutually exclusive'); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php new file mode 100644 index 0000000..776728f --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Exception; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractException; | ||
| 8 | |||
| 9 | use function sprintf; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @internal | ||
| 13 | * | ||
| 14 | * @psalm-immutable | ||
| 15 | */ | ||
| 16 | final class NonTerminatedStringLiteral extends AbstractException | ||
| 17 | { | ||
| 18 | public static function new(int $offset): self | ||
| 19 | { | ||
| 20 | return new self( | ||
| 21 | sprintf( | ||
| 22 | 'The statement contains non-terminated string literal starting at offset %d.', | ||
| 23 | $offset, | ||
| 24 | ), | ||
| 25 | ); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php new file mode 100644 index 0000000..2cd3fe7 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Exception; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\AbstractException; | ||
| 8 | |||
| 9 | use function sprintf; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @internal | ||
| 13 | * | ||
| 14 | * @psalm-immutable | ||
| 15 | */ | ||
| 16 | final class UnknownParameterIndex extends AbstractException | ||
| 17 | { | ||
| 18 | public static function new(int $index): self | ||
| 19 | { | ||
| 20 | return new self( | ||
| 21 | sprintf('Could not find variable mapping with index %d, in the SQL statement', $index), | ||
| 22 | ); | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/ExecutionMode.php b/vendor/doctrine/dbal/src/Driver/OCI8/ExecutionMode.php new file mode 100644 index 0000000..8efb936 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/ExecutionMode.php | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Encapsulates the execution mode that is shared between the connection and its statements. | ||
| 9 | * | ||
| 10 | * @internal This class is not covered by the backward compatibility promise | ||
| 11 | */ | ||
| 12 | final class ExecutionMode | ||
| 13 | { | ||
| 14 | private bool $isAutoCommitEnabled = true; | ||
| 15 | |||
| 16 | public function enableAutoCommit(): void | ||
| 17 | { | ||
| 18 | $this->isAutoCommitEnabled = true; | ||
| 19 | } | ||
| 20 | |||
| 21 | public function disableAutoCommit(): void | ||
| 22 | { | ||
| 23 | $this->isAutoCommitEnabled = false; | ||
| 24 | } | ||
| 25 | |||
| 26 | public function isAutoCommitEnabled(): bool | ||
| 27 | { | ||
| 28 | return $this->isAutoCommitEnabled; | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Middleware/InitializeSession.php b/vendor/doctrine/dbal/src/Driver/OCI8/Middleware/InitializeSession.php new file mode 100644 index 0000000..b825a1a --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Middleware/InitializeSession.php | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8\Middleware; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver; | ||
| 8 | use Doctrine\DBAL\Driver\Connection; | ||
| 9 | use Doctrine\DBAL\Driver\Middleware; | ||
| 10 | use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; | ||
| 11 | use SensitiveParameter; | ||
| 12 | |||
| 13 | final class InitializeSession implements Middleware | ||
| 14 | { | ||
| 15 | public function wrap(Driver $driver): Driver | ||
| 16 | { | ||
| 17 | return new class ($driver) extends AbstractDriverMiddleware { | ||
| 18 | /** | ||
| 19 | * {@inheritDoc} | ||
| 20 | */ | ||
| 21 | public function connect( | ||
| 22 | #[SensitiveParameter] | ||
| 23 | array $params, | ||
| 24 | ): Connection { | ||
| 25 | $connection = parent::connect($params); | ||
| 26 | |||
| 27 | $connection->exec( | ||
| 28 | 'ALTER SESSION SET' | ||
| 29 | . " NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'" | ||
| 30 | . " NLS_TIME_FORMAT = 'HH24:MI:SS'" | ||
| 31 | . " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'" | ||
| 32 | . " NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZH:TZM'" | ||
| 33 | . " NLS_NUMERIC_CHARACTERS = '.,'", | ||
| 34 | ); | ||
| 35 | |||
| 36 | return $connection; | ||
| 37 | } | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Result.php b/vendor/doctrine/dbal/src/Driver/OCI8/Result.php new file mode 100644 index 0000000..609e651 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Result.php | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\Exception; | ||
| 8 | use Doctrine\DBAL\Driver\FetchUtils; | ||
| 9 | use Doctrine\DBAL\Driver\OCI8\Exception\Error; | ||
| 10 | use Doctrine\DBAL\Driver\Result as ResultInterface; | ||
| 11 | |||
| 12 | use function oci_cancel; | ||
| 13 | use function oci_error; | ||
| 14 | use function oci_fetch_all; | ||
| 15 | use function oci_fetch_array; | ||
| 16 | use function oci_num_fields; | ||
| 17 | use function oci_num_rows; | ||
| 18 | |||
| 19 | use const OCI_ASSOC; | ||
| 20 | use const OCI_FETCHSTATEMENT_BY_COLUMN; | ||
| 21 | use const OCI_FETCHSTATEMENT_BY_ROW; | ||
| 22 | use const OCI_NUM; | ||
| 23 | use const OCI_RETURN_LOBS; | ||
| 24 | use const OCI_RETURN_NULLS; | ||
| 25 | |||
| 26 | final class Result implements ResultInterface | ||
| 27 | { | ||
| 28 | /** | ||
| 29 | * @internal The result can be only instantiated by its driver connection or statement. | ||
| 30 | * | ||
| 31 | * @param resource $statement | ||
| 32 | */ | ||
| 33 | public function __construct(private readonly mixed $statement) | ||
| 34 | { | ||
| 35 | } | ||
| 36 | |||
| 37 | public function fetchNumeric(): array|false | ||
| 38 | { | ||
| 39 | return $this->fetch(OCI_NUM); | ||
| 40 | } | ||
| 41 | |||
| 42 | public function fetchAssociative(): array|false | ||
| 43 | { | ||
| 44 | return $this->fetch(OCI_ASSOC); | ||
| 45 | } | ||
| 46 | |||
| 47 | public function fetchOne(): mixed | ||
| 48 | { | ||
| 49 | return FetchUtils::fetchOne($this); | ||
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * {@inheritDoc} | ||
| 54 | */ | ||
| 55 | public function fetchAllNumeric(): array | ||
| 56 | { | ||
| 57 | return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW); | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * {@inheritDoc} | ||
| 62 | */ | ||
| 63 | public function fetchAllAssociative(): array | ||
| 64 | { | ||
| 65 | return $this->fetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW); | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * {@inheritDoc} | ||
| 70 | */ | ||
| 71 | public function fetchFirstColumn(): array | ||
| 72 | { | ||
| 73 | return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0]; | ||
| 74 | } | ||
| 75 | |||
| 76 | public function rowCount(): int | ||
| 77 | { | ||
| 78 | $count = oci_num_rows($this->statement); | ||
| 79 | |||
| 80 | if ($count !== false) { | ||
| 81 | return $count; | ||
| 82 | } | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | public function columnCount(): int | ||
| 88 | { | ||
| 89 | $count = oci_num_fields($this->statement); | ||
| 90 | |||
| 91 | if ($count !== false) { | ||
| 92 | return $count; | ||
| 93 | } | ||
| 94 | |||
| 95 | return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | public function free(): void | ||
| 99 | { | ||
| 100 | oci_cancel($this->statement); | ||
| 101 | } | ||
| 102 | |||
| 103 | /** @throws Exception */ | ||
| 104 | private function fetch(int $mode): mixed | ||
| 105 | { | ||
| 106 | $result = oci_fetch_array($this->statement, $mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS); | ||
| 107 | |||
| 108 | if ($result === false && oci_error($this->statement) !== false) { | ||
| 109 | throw Error::new($this->statement); | ||
| 110 | } | ||
| 111 | |||
| 112 | return $result; | ||
| 113 | } | ||
| 114 | |||
| 115 | /** @return array<mixed> */ | ||
| 116 | private function fetchAll(int $mode, int $fetchStructure): array | ||
| 117 | { | ||
| 118 | oci_fetch_all( | ||
| 119 | $this->statement, | ||
| 120 | $result, | ||
| 121 | 0, | ||
| 122 | -1, | ||
| 123 | $mode | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS, | ||
| 124 | ); | ||
| 125 | |||
| 126 | return $result; | ||
| 127 | } | ||
| 128 | } | ||
diff --git a/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php b/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php new file mode 100644 index 0000000..408f0dd --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Driver\OCI8; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\OCI8\Exception\Error; | ||
| 8 | use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex; | ||
| 9 | use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
| 10 | use Doctrine\DBAL\ParameterType; | ||
| 11 | |||
| 12 | use function is_int; | ||
| 13 | use function oci_bind_by_name; | ||
| 14 | use function oci_execute; | ||
| 15 | use function oci_new_descriptor; | ||
| 16 | |||
| 17 | use const OCI_B_BIN; | ||
| 18 | use const OCI_B_BLOB; | ||
| 19 | use const OCI_COMMIT_ON_SUCCESS; | ||
| 20 | use const OCI_D_LOB; | ||
| 21 | use const OCI_NO_AUTO_COMMIT; | ||
| 22 | use const OCI_TEMP_BLOB; | ||
| 23 | use const SQLT_CHR; | ||
| 24 | |||
| 25 | final class Statement implements StatementInterface | ||
| 26 | { | ||
| 27 | /** | ||
| 28 | * @internal The statement can be only instantiated by its driver connection. | ||
| 29 | * | ||
| 30 | * @param resource $connection | ||
| 31 | * @param resource $statement | ||
| 32 | * @param array<int,string> $parameterMap | ||
| 33 | */ | ||
| 34 | public function __construct( | ||
| 35 | private readonly mixed $connection, | ||
| 36 | private readonly mixed $statement, | ||
| 37 | private readonly array $parameterMap, | ||
| 38 | private readonly ExecutionMode $executionMode, | ||
| 39 | ) { | ||
| 40 | } | ||
| 41 | |||
| 42 | public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
| 43 | { | ||
| 44 | if (is_int($param)) { | ||
| 45 | if (! isset($this->parameterMap[$param])) { | ||
| 46 | throw UnknownParameterIndex::new($param); | ||
| 47 | } | ||
| 48 | |||
| 49 | $param = $this->parameterMap[$param]; | ||
| 50 | } | ||
| 51 | |||
| 52 | if ($type === ParameterType::LARGE_OBJECT) { | ||
| 53 | if ($value !== null) { | ||
| 54 | $lob = oci_new_descriptor($this->connection, OCI_D_LOB); | ||
| 55 | $lob->writeTemporary($value, OCI_TEMP_BLOB); | ||
| 56 | |||
| 57 | $value =& $lob; | ||
| 58 | } else { | ||
| 59 | $type = ParameterType::STRING; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | if ( | ||
| 64 | ! @oci_bind_by_name( | ||
| 65 | $this->statement, | ||
| 66 | $param, | ||
| 67 | $value, | ||
| 68 | -1, | ||
| 69 | $this->convertParameterType($type), | ||
| 70 | ) | ||
| 71 | ) { | ||
| 72 | throw Error::new($this->statement); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Converts DBAL parameter type to oci8 parameter type | ||
| 78 | */ | ||
| 79 | private function convertParameterType(ParameterType $type): int | ||
| 80 | { | ||
| 81 | return match ($type) { | ||
| 82 | ParameterType::BINARY => OCI_B_BIN, | ||
| 83 | ParameterType::LARGE_OBJECT => OCI_B_BLOB, | ||
| 84 | default => SQLT_CHR, | ||
| 85 | }; | ||
| 86 | } | ||
| 87 | |||
| 88 | public function execute(): Result | ||
| 89 | { | ||
| 90 | if ($this->executionMode->isAutoCommitEnabled()) { | ||
| 91 | $mode = OCI_COMMIT_ON_SUCCESS; | ||
| 92 | } else { | ||
| 93 | $mode = OCI_NO_AUTO_COMMIT; | ||
| 94 | } | ||
| 95 | |||
| 96 | $ret = @oci_execute($this->statement, $mode); | ||
| 97 | if (! $ret) { | ||
| 98 | throw Error::new($this->statement); | ||
| 99 | } | ||
| 100 | |||
| 101 | return new Result($this->statement); | ||
| 102 | } | ||
| 103 | } | ||
