Skip to content

Commit

Permalink
Merge branch '3.3.x' into 3.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jul 2, 2022
2 parents 541e9dd + 82fa2f1 commit dcc101f
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 121 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
dependencies:
- "highest"
include:
Expand All @@ -67,6 +68,7 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"
dependency-versions: "${{ matrix.dependencies }}"

- name: "Print SQLite version"
Expand All @@ -92,6 +94,7 @@ jobs:
php-version:
- "7.4"
- "8.1"
- "8.2"
oracle-version:
- "21"
include:
Expand Down Expand Up @@ -127,6 +130,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/oci8.xml --coverage-clover=coverage.xml"
Expand All @@ -147,6 +152,7 @@ jobs:
php-version:
- "7.4"
- "8.1"
- "8.2"
oracle-version:
- "21"
include:
Expand Down Expand Up @@ -182,6 +188,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_oci.xml --coverage-clover=coverage.xml"
Expand All @@ -208,6 +216,8 @@ jobs:
include:
- php-version: "8.1"
postgres-version: "14"
- php-version: "8.2"
postgres-version: "14"

services:
postgres:
Expand Down Expand Up @@ -236,6 +246,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_pgsql.xml --coverage-clover=coverage.xml"
Expand Down Expand Up @@ -276,6 +288,12 @@ jobs:
- php-version: "8.1"
mariadb-version: "10.7"
extension: "pdo_mysql"
- php-version: "8.2"
mariadb-version: "10.7"
extension: "mysqli"
- php-version: "8.2"
mariadb-version: "10.7"
extension: "pdo_mysql"

services:
mariadb:
Expand Down Expand Up @@ -306,6 +324,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
Expand Down Expand Up @@ -354,6 +374,12 @@ jobs:
extension: "pdo_mysql"
custom-entrypoint: >-
--entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
- php-version: "8.2"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.2"
mysql-version: "8.0"
extension: "pdo_mysql"

services:
mysql:
Expand Down Expand Up @@ -384,6 +410,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Copy TLS-related files"
run: 'docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/ca.pem" . && docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/client-cert.pem" . && docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/client-key.pem" .'
Expand All @@ -408,6 +436,7 @@ jobs:
php-version:
- "7.4"
- "8.1"
- "8.2"
extension:
- "sqlsrv"
- "pdo_sqlsrv"
Expand Down Expand Up @@ -452,6 +481,8 @@ jobs:

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2022.1",
"phpstan/phpstan": "1.7.13",
"phpstan/phpstan": "1.7.15",
"phpstan/phpstan-strict-rules": "^1.2",
"phpunit/phpunit": "9.5.20",
"psalm/plugin-phpunit": "0.16.1",
"squizlabs/php_codesniffer": "3.7.0",
"phpunit/phpunit": "9.5.21",
"psalm/plugin-phpunit": "0.17.0",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^5.2|^6.0",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0",
"vimeo/psalm": "4.23.0"
"vimeo/psalm": "4.24.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
Expand Down
11 changes: 0 additions & 11 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@
This issue is fixed in 4.0
-->
<file name="src/Schema/Index.php"/>
<!--
See https://github.com/vimeo/psalm/issues/5325
-->
<file name="tests/Driver/OCI8/ExecutionModeTest.php"/>
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
<file name="src/Portability/Converter.php"/>
<!-- See https://github.com/psalm/psalm-plugin-phpunit/issues/107 -->
Expand Down Expand Up @@ -538,13 +534,6 @@
<file name="src/Query/QueryBuilder.php"/>
</errorLevel>
</ReferenceConstraintViolation>
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
<ReservedWord>
<errorLevel type="suppress">
<directory name="src"/>
<directory name="tests"/>
</errorLevel>
</ReservedWord>
<TooManyArguments>
<errorLevel type="suppress">
<!--
Expand Down
29 changes: 0 additions & 29 deletions src/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php

This file was deleted.

84 changes: 33 additions & 51 deletions src/Driver/IBMDB2/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCopyStreamToStream;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCreateTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotWriteToTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
Expand All @@ -16,10 +15,8 @@
use function db2_execute;
use function error_get_last;
use function fclose;
use function fwrite;
use function is_int;
use function is_resource;
use function ksort;
use function stream_copy_to_stream;
use function stream_get_meta_data;
use function tmpfile;
Expand All @@ -36,13 +33,13 @@ final class Statement implements StatementInterface
private $stmt;

/** @var mixed[] */
private array $bindParam = [];
private array $parameters = [];

/**
* Map of LOB parameter positions to the tuples containing reference to the variable bound to the driver statement
* and the temporary file handle bound to the underlying statement
*
* @var mixed[][]
* @var array<int,string|resource|null>
*/
private array $lobs = [];

Expand Down Expand Up @@ -79,17 +76,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
break;

case ParameterType::LARGE_OBJECT:
if (isset($this->lobs[$param])) {
[, $handle] = $this->lobs[$param];
fclose($handle);
}

$handle = $this->createTemporaryFile();
$path = stream_get_meta_data($handle)['uri'];

$this->bind($param, $path, DB2_PARAM_FILE, DB2_BINARY);

$this->lobs[$param] = [&$variable, $handle];
$this->lobs[$param] = &$variable;
break;

default:
Expand All @@ -108,9 +95,9 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
*/
private function bind($position, &$variable, int $parameterType, int $dataType): void
{
$this->bindParam[$position] =& $variable;
$this->parameters[$position] =& $variable;

if (! db2_bind_param($this->stmt, $position, 'variable', $parameterType, $dataType)) {
if (! db2_bind_param($this->stmt, $position, '', $parameterType, $dataType)) {
throw StatementError::new($this->stmt);
}
}
Expand All @@ -120,29 +107,11 @@ private function bind($position, &$variable, int $parameterType, int $dataType):
*/
public function execute($params = null): ResultInterface
{
if ($params === null) {
ksort($this->bindParam);
$handles = $this->bindLobs();

$params = [];
$result = @db2_execute($this->stmt, $params ?? $this->parameters);

foreach ($this->bindParam as $value) {
$params[] = $value;
}
}

foreach ($this->lobs as [$source, $target]) {
if (is_resource($source)) {
$this->copyStreamToStream($source, $target);

continue;
}

$this->writeStringToStream($source, $target);
}

$result = @db2_execute($this->stmt, $params);

foreach ($this->lobs as [, $handle]) {
foreach ($handles as $handle) {
fclose($handle);
}

Expand All @@ -155,6 +124,31 @@ public function execute($params = null): ResultInterface
return new Result($this->stmt);
}

/**
* @return list<resource>
*
* @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);
}
}

return $handles;
}

/**
* @return resource
*
Expand Down Expand Up @@ -183,16 +177,4 @@ private function copyStreamToStream($source, $target): void
throw CannotCopyStreamToStream::new(error_get_last());
}
}

/**
* @param resource $target
*
* @throws Exception
*/
private function writeStringToStream(string $string, $target): void
{
if (@fwrite($target, $string) === false) {
throw CannotWriteToTemporaryFile::new(error_get_last());
}
}
}
10 changes: 7 additions & 3 deletions src/Driver/OCI8/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
}

if ($type === ParameterType::LARGE_OBJECT) {
$lob = oci_new_descriptor($this->connection, OCI_D_LOB);
$lob->writeTemporary($variable, OCI_TEMP_BLOB);
if ($variable !== null) {
$lob = oci_new_descriptor($this->connection, OCI_D_LOB);
$lob->writeTemporary($variable, OCI_TEMP_BLOB);

$variable =& $lob;
$variable =& $lob;
} else {
$type = ParameterType::STRING;
}
}

return oci_bind_by_name(
Expand Down
13 changes: 13 additions & 0 deletions src/Platforms/MySQL/CollationMetadataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Platforms\MySQL;

/**
* @internal
*/
interface CollationMetadataProvider
{
public function getCollationCharset(string $collation): ?string;
}
Loading

0 comments on commit dcc101f

Please sign in to comment.