Skip to content

Commit

Permalink
Merge branch '3.2.x' into 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 6, 2021
2 parents 6655575 + 1ee1bf3 commit 05dfa97
Show file tree
Hide file tree
Showing 65 changed files with 498 additions and 508 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/stale.yml
@@ -0,0 +1,24 @@
name: 'Close stale pull requests'
on:
schedule:
- cron: '0 3 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
stale-pr-message: >
There hasn't been any activity on this pull request in the past year, so
it has been marked as stale and it will be closed automatically if no
further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.
close-pr-message: >
This pull request was closed due to a year of no activity.
days-before-stale: -1
days-before-pr-stale: 365
days-before-pr-close: 7
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -40,9 +40,9 @@
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2021.1",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan-phpunit": "0.12.22",
"phpstan/phpstan-strict-rules": "0.12.11",
"phpstan/phpstan": "1.0.2",
"phpstan/phpstan-phpunit": "1.0.0",
"phpstan/phpstan-strict-rules": "1.0.0",
"phpunit/phpunit": "9.5.10",
"psalm/plugin-phpunit": "0.16.1",
"squizlabs/php_codesniffer": "3.6.1",
Expand Down
24 changes: 20 additions & 4 deletions phpstan.neon.dist
Expand Up @@ -84,9 +84,19 @@ parameters:
paths:
- src/Driver/OCI8/Result.php

# https://github.com/phpstan/phpstan/issues/5608
# PHPStan fails to parse this type alias which is meant for Psalm only.
-
message: '~^Circular definition detected in type alias (Override)?Params\.$~'
message: '~^Invalid type definition detected in type alias (Override)?Params\.$~'
paths:
- src/DriverManager.php

-
message: '~Template type T of method Doctrine\\DBAL\\DriverManager::getConnection\(\) is not referenced in a parameter\.~'
paths:
- src/DriverManager.ph

-
message: '~Method Doctrine\\DBAL\\DriverManager::createDriver\(\) should return Doctrine\\DBAL\\Driver but returns object\.~'
paths:
- src/DriverManager.php

Expand Down Expand Up @@ -118,9 +128,15 @@ parameters:

# https://github.com/phpstan/phpstan-src/pull/700
-
message: '~^Parameter #2 \$count of function array_fill expects int<0, max>, int given\.$~'
message: '~Method Doctrine\\DBAL\\Driver\\Mysqli\\Result::rowCount\(\) should return int but returns int\|string\.~'
paths:
- src/Driver/Mysqli/Statement.php
- src/Driver/Mysqli/Result.php

# These properties are accessed via var_dump()
-
message: '~Property Doctrine\\DBAL\\Tests\\Tools\\TestAsset\\.*::\$.* is never read, only written\.~'
path: tests/Tools/TestAsset/*.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
10 changes: 9 additions & 1 deletion src/Connection.php
Expand Up @@ -822,7 +822,15 @@ public function iterateColumn(string $query, array $params = [], array $types =
*/
public function prepare(string $sql): Statement
{
return new Statement($sql, $this);
$connection = $this->getWrappedConnection();

try {
$statement = $connection->prepare($sql);
} catch (Driver\Exception $e) {
throw $this->convertExceptionDuringQuery($e, $sql);
}

return new Statement($this, $statement, $sql);
}

/**
Expand Down
64 changes: 22 additions & 42 deletions src/Driver/IBMDB2/Connection.php
Expand Up @@ -5,22 +5,19 @@
namespace Doctrine\DBAL\Driver\IBMDB2;

use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Exception\NoIdentityValue;
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionError;
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed;
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use stdClass;

use function assert;
use function db2_autocommit;
use function db2_commit;
use function db2_connect;
use function db2_escape_string;
use function db2_exec;
use function db2_last_insert_id;
use function db2_num_rows;
use function db2_pconnect;
use function db2_prepare;
use function db2_rollback;
use function db2_server_info;
Expand All @@ -32,46 +29,29 @@
final class Connection implements ConnectionInterface
{
/** @var resource */
private $conn;
private $connection;

/**
* @internal The connection can be only instantiated by its driver.
*
* @param array<string,mixed> $driverOptions
*
* @throws Exception
* @param resource $connection
*/
public function __construct(
string $database,
bool $persistent,
string $username,
string $password,
array $driverOptions = []
) {
if ($persistent) {
$conn = db2_pconnect($database, $username, $password, $driverOptions);
} else {
$conn = db2_connect($database, $username, $password, $driverOptions);
}

if ($conn === false) {
throw ConnectionFailed::new();
}

$this->conn = $conn;
public function __construct($connection)
{
$this->connection = $connection;
}

public function getServerVersion(): string
{
$serverInfo = db2_server_info($this->conn);
$serverInfo = db2_server_info($this->connection);
assert($serverInfo instanceof stdClass);

return $serverInfo->DBMS_VER;
}

public function prepare(string $sql): Statement
{
$stmt = @db2_prepare($this->conn, $sql);
$stmt = @db2_prepare($this->connection, $sql);

if ($stmt === false) {
throw PrepareFailed::new(error_get_last());
Expand All @@ -92,7 +72,7 @@ public function quote(string $value): string

public function exec(string $sql): int
{
$stmt = @db2_exec($this->conn, $sql);
$stmt = @db2_exec($this->connection, $sql);

if ($stmt === false) {
throw StatementError::new();
Expand All @@ -106,41 +86,41 @@ public function exec(string $sql): int
*/
public function lastInsertId()
{
$lastInsertId = db2_last_insert_id($this->conn);
$lastInsertId = db2_last_insert_id($this->connection);

if ($lastInsertId === null) {
throw Exception\NoIdentityValue::new();
throw NoIdentityValue::new();
}

return $lastInsertId;
return db2_last_insert_id($this->connection);
}

public function beginTransaction(): void
{
if (db2_autocommit($this->conn, DB2_AUTOCOMMIT_OFF) !== true) {
throw ConnectionError::new($this->conn);
if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_OFF) !== true) {
throw ConnectionError::new($this->connection);
}
}

public function commit(): void
{
if (! db2_commit($this->conn)) {
throw ConnectionError::new($this->conn);
if (! db2_commit($this->connection)) {
throw ConnectionError::new($this->connection);
}

if (db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON) !== true) {
throw ConnectionError::new($this->conn);
if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) {
throw ConnectionError::new($this->connection);
}
}

public function rollBack(): void
{
if (! db2_rollback($this->conn)) {
throw ConnectionError::new($this->conn);
if (! db2_rollback($this->connection)) {
throw ConnectionError::new($this->connection);
}

if (db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON) !== true) {
throw ConnectionError::new($this->conn);
if (db2_autocommit($this->connection, DB2_AUTOCOMMIT_ON) !== true) {
throw ConnectionError::new($this->connection);
}
}
}
25 changes: 18 additions & 7 deletions src/Driver/IBMDB2/Driver.php
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\DBAL\Driver\IBMDB2;

use Doctrine\DBAL\Driver\AbstractDB2Driver;
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed;

final class Driver extends AbstractDB2Driver
{
Expand All @@ -13,12 +14,22 @@ final class Driver extends AbstractDB2Driver
*/
public function connect(array $params): Connection
{
return new Connection(
DataSourceName::fromConnectionParameters($params)->toString(),
isset($params['persistent']) && $params['persistent'] === true,
$params['user'] ?? '',
$params['password'] ?? '',
$params['driverOptions'] ?? []
);
$dataSourceName = DataSourceName::fromConnectionParameters($params)->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);
}
}

0 comments on commit 05dfa97

Please sign in to comment.