From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doctrine/dbal/src/Driver/IBMDB2/Connection.php | 131 +++++++++++++++++ .../dbal/src/Driver/IBMDB2/DataSourceName.php | 80 +++++++++++ vendor/doctrine/dbal/src/Driver/IBMDB2/Driver.php | 41 ++++++ .../IBMDB2/Exception/CannotCopyStreamToStream.php | 27 ++++ .../IBMDB2/Exception/CannotCreateTemporaryFile.php | 27 ++++ .../Driver/IBMDB2/Exception/ConnectionError.php | 29 ++++ .../Driver/IBMDB2/Exception/ConnectionFailed.php | 28 ++++ .../dbal/src/Driver/IBMDB2/Exception/Factory.php | 35 +++++ .../src/Driver/IBMDB2/Exception/PrepareFailed.php | 25 ++++ .../src/Driver/IBMDB2/Exception/StatementError.php | 34 +++++ vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php | 106 ++++++++++++++ .../doctrine/dbal/src/Driver/IBMDB2/Statement.php | 156 +++++++++++++++++++++ 12 files changed, 719 insertions(+) create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Connection.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/DataSourceName.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Driver.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionError.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionFailed.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/Factory.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/PrepareFailed.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/StatementError.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Result.php create mode 100644 vendor/doctrine/dbal/src/Driver/IBMDB2/Statement.php (limited to 'vendor/doctrine/dbal/src/Driver/IBMDB2') 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 @@ +connection); + assert($serverInfo instanceof stdClass); + + return $serverInfo->DBMS_VER; + } + + public function prepare(string $sql): Statement + { + $stmt = @db2_prepare($this->connection, $sql); + + if ($stmt === false) { + throw PrepareFailed::new(error_get_last()); + } + + return new Statement($stmt); + } + + public function query(string $sql): Result + { + return $this->prepare($sql)->execute(); + } + + public function quote(string $value): string + { + return "'" . db2_escape_string($value) . "'"; + } + + public function exec(string $sql): int|string + { + $stmt = @db2_exec($this->connection, $sql); + + if ($stmt === false) { + throw StatementError::new(); + } + + $numRows = db2_num_rows($stmt); + + if ($numRows === false) { + throw StatementError::new(); + } + + return $numRows; + } + + public function lastInsertId(): string + { + $lastInsertId = db2_last_insert_id($this->connection); + + if ($lastInsertId === null) { + throw NoIdentityValue::new(); + } + + return $lastInsertId; + } + + public function beginTransaction(): void + { + if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_OFF) !== true) { + throw ConnectionError::new($this->connection); + } + } + + public function commit(): void + { + if (! db2_commit($this->connection)) { + throw ConnectionError::new($this->connection); + } + + if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) { + throw ConnectionError::new($this->connection); + } + } + + public function rollBack(): void + { + if (! db2_rollback($this->connection)) { + throw ConnectionError::new($this->connection); + } + + if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) { + throw ConnectionError::new($this->connection); + } + } + + /** @return resource */ + public function getNativeConnection() + { + return $this->connection; + } +} diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/DataSourceName.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/DataSourceName.php new file mode 100644 index 0000000..a1e5948 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/DataSourceName.php @@ -0,0 +1,80 @@ +string; + } + + /** + * Creates the object from an array representation + * + * @param array $params + */ + public static function fromArray( + #[SensitiveParameter] + array $params, + ): self { + $chunks = []; + + foreach ($params as $key => $value) { + $chunks[] = sprintf('%s=%s', $key, $value); + } + + return new self(implode(';', $chunks)); + } + + /** + * Creates the object from the given DBAL connection parameters. + * + * @param array $params + */ + public static function fromConnectionParameters(#[SensitiveParameter] + array $params,): self + { + if (isset($params['dbname']) && str_contains($params['dbname'], '=')) { + return new self($params['dbname']); + } + + $dsnParams = []; + + foreach ( + [ + 'host' => 'HOSTNAME', + 'port' => 'PORT', + 'protocol' => 'PROTOCOL', + 'dbname' => 'DATABASE', + 'user' => 'UID', + 'password' => 'PWD', + ] as $dbalParam => $dsnParam + ) { + if (! isset($params[$dbalParam])) { + continue; + } + + $dsnParams[$dsnParam] = $params[$dbalParam]; + } + + return self::fromArray($dsnParams); + } +} diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/Driver.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/Driver.php new file mode 100644 index 0000000..f2f4ed7 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/Driver.php @@ -0,0 +1,41 @@ +toString(); + + $username = $params['user'] ?? ''; + $password = $params['password'] ?? ''; + $driverOptions = $params['driverOptions'] ?? []; + + if (! empty($params['persistent'])) { + $connection = db2_pconnect($dataSourceName, $username, $password, $driverOptions); + } else { + $connection = db2_connect($dataSourceName, $username, $password, $driverOptions); + } + + if ($connection === false) { + throw ConnectionFailed::new(); + } + + return new Connection($connection); + } +} diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php new file mode 100644 index 0000000..c584fb8 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php @@ -0,0 +1,27 @@ +statement); + + if ($row === false && db2_stmt_error($this->statement) !== '02000') { + throw StatementError::new($this->statement); + } + + return $row; + } + + public function fetchAssociative(): array|false + { + $row = @db2_fetch_assoc($this->statement); + + if ($row === false && db2_stmt_error($this->statement) !== '02000') { + throw StatementError::new($this->statement); + } + + return $row; + } + + public function fetchOne(): mixed + { + return FetchUtils::fetchOne($this); + } + + /** + * {@inheritDoc} + */ + public function fetchAllNumeric(): array + { + return FetchUtils::fetchAllNumeric($this); + } + + /** + * {@inheritDoc} + */ + public function fetchAllAssociative(): array + { + return FetchUtils::fetchAllAssociative($this); + } + + /** + * {@inheritDoc} + */ + public function fetchFirstColumn(): array + { + return FetchUtils::fetchFirstColumn($this); + } + + public function rowCount(): int + { + $numRows = @db2_num_rows($this->statement); + + if ($numRows === false) { + throw StatementError::new($this->statement); + } + + return $numRows; + } + + public function columnCount(): int + { + $count = db2_num_fields($this->statement); + + if ($count !== false) { + return $count; + } + + return 0; + } + + public function free(): void + { + db2_free_result($this->statement); + } +} diff --git a/vendor/doctrine/dbal/src/Driver/IBMDB2/Statement.php b/vendor/doctrine/dbal/src/Driver/IBMDB2/Statement.php new file mode 100644 index 0000000..96852da --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/IBMDB2/Statement.php @@ -0,0 +1,156 @@ + + */ + private array $lobs = []; + + /** + * @internal The statement can be only instantiated by its driver connection. + * + * @param resource $stmt + */ + public function __construct(private readonly mixed $stmt) + { + } + + public function bindValue(int|string $param, mixed $value, ParameterType $type): void + { + assert(is_int($param)); + + switch ($type) { + case ParameterType::INTEGER: + $this->bind($param, $value, DB2_PARAM_IN, DB2_LONG); + break; + + case ParameterType::LARGE_OBJECT: + $this->lobs[$param] = &$value; + break; + + default: + $this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR); + break; + } + } + + /** @throws Exception */ + private function bind(int $position, mixed &$variable, int $parameterType, int $dataType): void + { + $this->parameters[$position] =& $variable; + + if (! db2_bind_param($this->stmt, $position, '', $parameterType, $dataType)) { + throw StatementError::new($this->stmt); + } + } + + public function execute(): Result + { + $handles = $this->bindLobs(); + + $result = @db2_execute($this->stmt, $this->parameters); + + foreach ($handles as $handle) { + fclose($handle); + } + + $this->lobs = []; + + if ($result === false) { + throw StatementError::new($this->stmt); + } + + return new Result($this->stmt); + } + + /** + * @return list + * + * @throws Exception + */ + private function bindLobs(): array + { + $handles = []; + + foreach ($this->lobs as $param => $value) { + if (is_resource($value)) { + $handle = $handles[] = $this->createTemporaryFile(); + $path = stream_get_meta_data($handle)['uri']; + + $this->copyStreamToStream($value, $handle); + + $this->bind($param, $path, DB2_PARAM_FILE, DB2_BINARY); + } else { + $this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR); + } + + unset($value); + } + + return $handles; + } + + /** + * @return resource + * + * @throws Exception + */ + private function createTemporaryFile() + { + $handle = @tmpfile(); + + if ($handle === false) { + throw CannotCreateTemporaryFile::new(error_get_last()); + } + + return $handle; + } + + /** + * @param resource $source + * @param resource $target + * + * @throws Exception + */ + private function copyStreamToStream($source, $target): void + { + if (@stream_copy_to_stream($source, $target) === false) { + throw CannotCopyStreamToStream::new(error_get_last()); + } + } +} -- cgit v1.2.3