Unverified Commit 3d8c5756 authored by Sergei Morozov's avatar Sergei Morozov

Merge branch '2.11.x' into 3.0.x

parents 0d7999ee 3cfb57d4
......@@ -70,15 +70,14 @@ install:
$destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip"
Invoke-WebRequest $source -OutFile $destination
7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip > $null
$DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/xdebug/stable.txt").Content
$source = "https://xdebug.org/files/php_xdebug-$($DLLVersion)-$($env:php)-vc15-nts-x86_64.dll"
$destination = "c:\tools\php\ext\php_xdebug.dll"
Invoke-WebRequest $source -OutFile $destination
$DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/pcov/stable.txt").Content
Invoke-WebRequest https://windows.php.net/downloads/pecl/releases/pcov/$($DLLVersion)/php_pcov-$($DLLVersion)-7.3-nts-vc15-$($env:platform).zip -OutFile pcov.zip
7z x -y pcov.zip > $null
Remove-Item c:\tools\php\* -include .zip
cd c:\tools\php
Add-Content php.ini "`nextension=php_sqlsrv.dll"
Add-Content php.ini "`nextension=php_pdo_sqlsrv.dll"
Add-Content php.ini "`nzend_extension=php_xdebug.dll"
Add-Content php.ini "`nextension=php_pcov.dll"
Add-Content php.ini "`n"
# download Composer
......@@ -119,8 +118,12 @@ test_script:
$env:phpunit_config = "ci\appveyor\$($env:db).$($env:driver).appveyor.xml"
}
vendor\bin\phpunit -c $($env:phpunit_config)
vendor\bin\phpunit -c $($env:phpunit_config) --coverage-clover clover.xml
if ($LastExitCode -ne 0) {
$host.SetShouldExit($LastExitCode)
}
after_test:
- appveyor DownloadFile https://codecov.io/bash -FileName codecov.sh
- bash codecov.sh -f clover.xml
coverage_clover: clover.xml
json_path: /tmp/coveralls-upload.json
......@@ -8,12 +8,7 @@ cache:
before_install:
- phpenv config-rm xdebug.ini || true
- |
if [ "x$COVERAGE" == "xyes" ]; then
pecl install pcov-1.0.6
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.2.0/php-coveralls.phar --output-document="${HOME}/bin/coveralls"
chmod +x ${HOME}/bin/coveralls
fi
- pecl install pcov
before_script:
- |
......@@ -30,80 +25,72 @@ install:
- travis_retry composer -n install --prefer-dist $COMPOSER_FLAGS
script:
- |
if [ "x$COVERAGE" == "xyes" ]; then
./vendor/bin/phpunit --configuration ci/travis/$DB.travis.xml --coverage-clover clover.xml
else
./vendor/bin/phpunit --configuration ci/travis/$DB.travis.xml
fi
- ./vendor/bin/phpunit --configuration ci/travis/$DB.travis.xml --coverage-clover clover.xml
after_script:
- |
if [ "x$COVERAGE" == "xyes" ]; then
travis_retry coveralls -v
fi
after_success:
- bash <(curl -s https://codecov.io/bash)
jobs:
include:
- stage: Smoke Testing
php: 7.4
env: DB=sqlite COVERAGE=yes
env: DB=sqlite
- stage: Test
php: 7.3
env: DB=mysql.docker IMAGE=mysql:5.7 COVERAGE=yes
env: DB=mysql.docker IMAGE=mysql:5.7
- stage: Test
php: 7.3
env: DB=mysql.docker IMAGE=mysql:8.0 COVERAGE=yes
env: DB=mysql.docker IMAGE=mysql:8.0
- stage: Test
php: 7.3
env: DB=mysqli.docker IMAGE=mysql:5.7 COVERAGE=yes
env: DB=mysqli.docker IMAGE=mysql:5.7
- stage: Test
php: 7.3
env: DB=mysqli.docker IMAGE=mysql:8.0 COVERAGE=yes
env: DB=mysqli.docker IMAGE=mysql:8.0
- stage: Test
php: 7.3
env: DB=mariadb.docker IMAGE=mariadb:10.0 COVERAGE=yes
env: DB=mariadb.docker IMAGE=mariadb:10.0
- stage: Test
php: 7.3
env: DB=mariadb.docker IMAGE=mariadb:10.1 COVERAGE=yes
env: DB=mariadb.docker IMAGE=mariadb:10.1
- stage: Test
php: 7.3
env: DB=mariadb.docker IMAGE=mariadb:10.2 COVERAGE=yes
env: DB=mariadb.docker IMAGE=mariadb:10.2
- stage: Test
php: 7.3
env: DB=mariadb.docker IMAGE=mariadb:10.3 COVERAGE=yes
env: DB=mariadb.docker IMAGE=mariadb:10.3
- stage: Test
php: 7.3
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.0 COVERAGE=yes
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.0
- stage: Test
php: 7.3
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.1 COVERAGE=yes
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.1
- stage: Test
php: 7.3
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.2 COVERAGE=yes
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.2
- stage: Test
php: 7.3
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3 COVERAGE=yes
env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3
- stage: Test
php: 7.3
env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.4
addons:
postgresql: "9.4"
- stage: Test
php: 7.3
env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.5
addons:
postgresql: "9.5"
- stage: Test
php: 7.3
env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.6
addons:
postgresql: "9.6"
- stage: Test
php: 7.3
env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=10.0
sudo: required
addons:
postgresql: "10"
......@@ -111,13 +98,13 @@ jobs:
- bash ./ci/travis/install-postgres-10.sh
- stage: Test
php: 7.3
env: DB=pgsql POSTGRESQL_VERSION=11.0 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=11.0
sudo: required
before_script:
- bash ./ci/travis/install-postgres-11.sh
- stage: Test
php: 7.3
env: DB=sqlsrv COVERAGE=yes
env: DB=sqlsrv
sudo: required
before_script:
- bash ./ci/travis/install-sqlsrv-dependencies.sh
......@@ -125,7 +112,7 @@ jobs:
- bash ./ci/travis/install-mssql.sh
- stage: Test
php: 7.3
env: DB=pdo_sqlsrv COVERAGE=yes
env: DB=pdo_sqlsrv
sudo: required
before_script:
- bash ./ci/travis/install-sqlsrv-dependencies.sh
......@@ -133,7 +120,7 @@ jobs:
- bash ./ci/travis/install-mssql.sh
- stage: Test
php: 7.3
env: DB=ibm_db2 COVERAGE=yes
env: DB=ibm_db2
sudo: required
before_script:
- bash ./ci/travis/install-db2.sh
......
......@@ -4,7 +4,7 @@
|:----------------:|:----------:|
| [![Build status][Master image]][Master] | [![Build status][2.10 image]][2.10] |
| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.10 image]][ContinuousPHP] |
| [![Code Coverage][Coverage image]][Coveralls Master] | [![Code Coverage][Coverage 2.10 image]][Coveralls 2.10] |
| [![Code Coverage][Coverage image]][CodeCov Master] | [![Code Coverage][Coverage 2.10 image]][CodeCov 2.10] |
| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.10 image]][AppVeyor 2.10] |
Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction.
......@@ -16,18 +16,18 @@ Powerful database abstraction layer with many features for database schema intro
* [Issue Tracker](https://github.com/doctrine/dbal/issues)
[Master image]: https://img.shields.io/travis/doctrine/dbal/master.svg?style=flat-square
[Coverage image]: https://coveralls.io/repos/github/doctrine/dbal/badge.svg?branch=master
[Coverage image]: https://codecov.io/gh/doctrine/dbal/branch/master/graph/badge.svg
[ContinuousPHP image]: https://img.shields.io/continuousphp/git-hub/doctrine/dbal/master.svg?style=flat-square
[Master]: https://travis-ci.org/doctrine/dbal
[Coveralls Master]: https://coveralls.io/github/doctrine/dbal?branch=master
[CodeCov Master]: https://codecov.io/gh/doctrine/dbal/branch/master
[AppVeyor master]: https://ci.appveyor.com/project/doctrine/dbal/branch/master
[AppVeyor master image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/master?svg=true
[ContinuousPHP]: https://continuousphp.com/git-hub/doctrine/dbal
[2.10 image]: https://img.shields.io/travis/doctrine/dbal/2.10.x.svg?style=flat-square
[Coverage 2.10 image]: https://coveralls.io/repos/github/doctrine/dbal/badge.svg?branch=2.10.x
[Coverage 2.10 image]: https://codecov.io/gh/doctrine/dbal/branch/2.10.x/graph/badge.svg
[ContinuousPHP 2.10 image]: https://img.shields.io/continuousphp/git-hub/doctrine/dbal/2.10.x.svg?style=flat-square
[2.10]: https://github.com/doctrine/dbal/tree/2.10.x
[Coveralls 2.10]: https://coveralls.io/github/doctrine/dbal?branch=2.10.x
[CodeCov 2.10]: https://codecov.io/gh/doctrine/dbal/branch/2.10.x
[AppVeyor 2.10]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.10.x
[AppVeyor 2.10 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.10.x?svg=true
......@@ -164,14 +164,23 @@ Please use other database client applications for import, e.g.:
# Upgrade to 2.11
## Deprecated `ArrayStatement` and `ResultCacheStatement` classes.
The `ArrayStatement` and `ResultCacheStatement` classes are deprecated. In a future major release they will be renamed and marked internal as implementation details of the caching layer.
## Deprecated `ResultStatement` interface
1. The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead.
2. `ResultStatement::closeCursor()` is deprecated in favor of `Result::free()`.
## Deprecated `FetchMode` and the corresponding methods
1. The `FetchMode` class and the `setFetchMode()` method of the `Connection` and `Statement` interfaces are deprecated.
2. The `Statement::fetch()` method is deprecated in favor of `fetchNumeric()`, `fetchAssociative()` and `fetchOne()`.
3. The `Statement::fetchAll()` method is deprecated in favor of `fetchAllNumeric()` and `fetchAllAssociative()`. There is no currently replacement for `Statement::fetchAll(FETCH_MODE::COLUMN)`. In a future major version, `fetchColumn()` will be used as a replacement.
4. The `Statement::fetchColumn()` method is deprecated in favor of `fetchOne()`.
2. The `Statement::fetch()` method is deprecated in favor of `Result::fetchNumeric()`, `::fetchAssociative()` and `::fetchOne()`.
3. The `Statement::fetchAll()` method is deprecated in favor of `Result::fetchAllNumeric()`, `::fetchAllAssociative()` and `::fetchFirstColumn()`.
4. The `Statement::fetchColumn()` method is deprecated in favor of `Result::fetchOne()`.
5. The `Connection::fetchArray()` and `fetchAssoc()` method are deprecated in favor of `fetchNumeric()` and `fetchAssociative()` respectively.
6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `iterateNumeric()`, `iterateAssociative()` and `iterateColumn()`.
6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `Result::iterateNumeric()`, `::iterateAssociative()` and `::iterateColumn()`.
7. Fetching data in mixed mode (`FetchMode::MIXED`) is deprecated.
## Deprecated `Connection::project()`
......
......@@ -4,7 +4,7 @@ declare(strict_types=1);
use Doctrine\DBAL\DriverManager;
(static function () : void {
(static function (): void {
// workaround for https://bugs.php.net/bug.php?id=77120
DriverManager::getConnection([
'driver' => 'oci8',
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d0353e4743c583bb533aa3b933473d29",
"content-hash": "81a912bd9d2a1715150a2d63fe40cef0",
"packages": [
{
"name": "doctrine/cache",
......@@ -462,16 +462,16 @@
},
{
"name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v0.5.0",
"version": "v0.6.2",
"source": {
"type": "git",
"url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
"reference": "e749410375ff6fb7a040a68878c656c2e610b132"
"reference": "8001af8eb107fbfcedc31a8b51e20b07d85b457a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132",
"reference": "e749410375ff6fb7a040a68878c656c2e610b132",
"url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/8001af8eb107fbfcedc31a8b51e20b07d85b457a",
"reference": "8001af8eb107fbfcedc31a8b51e20b07d85b457a",
"shasum": ""
},
"require": {
......@@ -524,27 +524,27 @@
"stylecheck",
"tests"
],
"time": "2018-10-26T13:21:45+00:00"
"time": "2020-01-29T20:22:20+00:00"
},
{
"name": "doctrine/coding-standard",
"version": "7.0.2",
"version": "8.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/coding-standard.git",
"reference": "d8a60ec4da68025c42795b714f66e277dd3e11de"
"reference": "742200e29fb8ffd58ba9abec8a9ec33db0884677"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/coding-standard/zipball/d8a60ec4da68025c42795b714f66e277dd3e11de",
"reference": "d8a60ec4da68025c42795b714f66e277dd3e11de",
"url": "https://api.github.com/repos/doctrine/coding-standard/zipball/742200e29fb8ffd58ba9abec8a9ec33db0884677",
"reference": "742200e29fb8ffd58ba9abec8a9ec33db0884677",
"shasum": ""
},
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"php": "^7.2",
"slevomat/coding-standard": "^6.0",
"squizlabs/php_codesniffer": "^3.5.3"
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2",
"php": "^7.2 || ^8.0",
"slevomat/coding-standard": "^6.3.8",
"squizlabs/php_codesniffer": "^3.5.5"
},
"type": "phpcodesniffer-standard",
"extra": {
......@@ -552,11 +552,6 @@
"dev-master": "7.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Sniffs\\": "lib/Doctrine/Sniffs"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
......@@ -585,7 +580,7 @@
"standard",
"style"
],
"time": "2019-12-11T07:59:21+00:00"
"time": "2020-06-02T17:58:43+00:00"
},
{
"name": "doctrine/instantiator",
......@@ -2637,16 +2632,16 @@
},
{
"name": "slevomat/coding-standard",
"version": "6.3.7",
"version": "6.3.8",
"source": {
"type": "git",
"url": "https://github.com/slevomat/coding-standard.git",
"reference": "1f7bd4b5c11cf4a164a400c937483785b0f4eb9e"
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/1f7bd4b5c11cf4a164a400c937483785b0f4eb9e",
"reference": "1f7bd4b5c11cf4a164a400c937483785b0f4eb9e",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/500f55b5e2dee1dcef8e88f2038990acdba29f1c",
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c",
"shasum": ""
},
"require": {
......@@ -2690,7 +2685,7 @@
"type": "tidelift"
}
],
"time": "2020-05-25T13:39:15+00:00"
"time": "2020-05-27T06:28:47+00:00"
},
{
"name": "squizlabs/php_codesniffer",
......
......@@ -35,15 +35,13 @@ the default cache instance:
new QueryCacheProfile(0, "some key", $cache);
In order for the data to actually be cached its necessary to ensure that the entire
result set is read (the easiest way to ensure this is to use ``fetchAll``) and the statement
object is closed:
result set is read (the easiest way to ensure this is to use one of the ``fetchAll*()`` methods):
::
<?php
$stmt = $conn->executeCacheQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
$data = $stmt->fetchAllAssociative();
$stmt->closeCursor(); // at this point the result is cached
.. warning::
......
......@@ -22,7 +22,9 @@
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<exclude name="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants.DisallowedLateStaticBindingForConstant"/>
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterLastControlStructure"/>
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<!-- https://github.com/slevomat/coding-standard/issues/867 -->
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing.IncorrectLinesCountAfterLastControlStructure"/>
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/issues/2937 -->
......
......@@ -2,15 +2,17 @@
declare(strict_types=1);
namespace Doctrine\DBAL;
namespace Doctrine\DBAL\Abstraction;
use Doctrine\DBAL\Driver\ResultStatement as DriverResultStatement;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Traversable;
/**
* DBAL-level ResultStatement interface.
* Abstraction-level statement execution result. Provides additional methods on top
* of the driver-level interface.
*/
interface ResultStatement extends DriverResultStatement
interface Result extends DriverResult
{
/**
* Returns an iterator over the result set rows represented as numeric arrays.
......@@ -19,7 +21,7 @@ interface ResultStatement extends DriverResultStatement
*
* @throws DBALException
*/
public function iterateNumeric() : Traversable;
public function iterateNumeric(): Traversable;
/**
* Returns an iterator over the result set rows represented as associative arrays.
......@@ -28,7 +30,7 @@ interface ResultStatement extends DriverResultStatement
*
* @throws DBALException
*/
public function iterateAssociative() : Traversable;
public function iterateAssociative(): Traversable;
/**
* Returns an iterator over the values of the first column of the result set.
......@@ -37,5 +39,5 @@ interface ResultStatement extends DriverResultStatement
*
* @throws DBALException
*/
public function iterateColumn() : Traversable;
public function iterateColumn(): Traversable;
}
......@@ -3,12 +3,17 @@
namespace Doctrine\DBAL\Cache;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ResultStatement;
use function array_values;
use function count;
use function reset;
class ArrayStatement implements ResultStatement
/**
* @deprecated
*/
class ArrayStatement implements ResultStatement, Result
{
/** @var mixed[] */
private $data;
......@@ -34,10 +39,12 @@ class ArrayStatement implements ResultStatement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
unset($this->data);
$this->free();
return true;
}
......@@ -50,7 +57,7 @@ class ArrayStatement implements ResultStatement
return $this->columnCount;
}
public function rowCount() : int
public function rowCount(): int
{
if ($this->data === null) {
return 0;
......@@ -98,7 +105,7 @@ class ArrayStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return FetchUtils::fetchAllNumeric($this);
}
......@@ -106,7 +113,7 @@ class ArrayStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return FetchUtils::fetchAllAssociative($this);
}
......@@ -114,9 +121,14 @@ class ArrayStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchFirstColumn($this);
}
public function free(): void
{
return FetchUtils::fetchColumn($this);
$this->data = [];
}
/**
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Cache;
use Doctrine\Common\Cache\Cache;
use function hash;
use function serialize;
use function sha1;
......
......@@ -5,7 +5,9 @@ namespace Doctrine\DBAL\Cache;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ResultStatement;
use function array_map;
use function array_values;
......@@ -21,8 +23,10 @@ use function array_values;
*
* Also you have to realize that the cache will load the whole result into memory at once to ensure 2.
* This means that the memory usage for cached results might increase by using this feature.
*
* @deprecated
*/
class ResultCacheStatement implements ResultStatement
class ResultCacheStatement implements ResultStatement, Result
{
/** @var Cache */
private $resultCache;
......@@ -39,14 +43,7 @@ class ResultCacheStatement implements ResultStatement
/** @var ResultStatement */
private $statement;
/**
* Did we reach the end of the statement?
*
* @var bool
*/
private $emptied = false;
/** @var array<int,array<string,mixed>> */
/** @var array<int,array<string,mixed>>|null */
private $data;
/**
......@@ -65,23 +62,12 @@ class ResultCacheStatement implements ResultStatement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
$this->statement->closeCursor();
if (! $this->emptied || $this->data === null) {
return true;
}
$data = $this->resultCache->fetch($this->cacheKey);
if ($data === false) {
$data = [];
}
$data[$this->realKey] = $this->data;
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);
$this->free();
return true;
}
......@@ -94,7 +80,7 @@ class ResultCacheStatement implements ResultStatement
return $this->statement->columnCount();
}
public function rowCount() : int
public function rowCount(): int
{
return $this->statement->rowCount();
}
......@@ -132,7 +118,7 @@ class ResultCacheStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
$this->store(
$this->statement->fetchAllAssociative()
......@@ -144,7 +130,7 @@ class ResultCacheStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
$this->store(
$this->statement->fetchAllAssociative()
......@@ -156,9 +142,14 @@ class ResultCacheStatement implements ResultStatement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchFirstColumn($this);
}
public function free(): void
{
return FetchUtils::fetchColumn($this);
$this->data = null;
}
/**
......@@ -180,7 +171,7 @@ class ResultCacheStatement implements ResultStatement
return $row;
}
$this->emptied = true;
$this->saveToCache();
return false;
}
......@@ -188,9 +179,27 @@ class ResultCacheStatement implements ResultStatement
/**
* @param array<int,array<string,mixed>> $data
*/
private function store(array $data) : void
private function store(array $data): void
{
$this->data = $data;
$this->emptied = true;
$this->data = $data;
$this->saveToCache();
}
private function saveToCache(): void
{
if ($this->data === null) {
return;
}
$data = $this->resultCache->fetch($this->cacheKey);
if ($data === false) {
$data = [];
}
$data[$this->realKey] = $this->data;
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
}
}
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\Schema\AbstractAsset;
use function preg_match;
/**
......@@ -101,7 +102,7 @@ class Configuration
/**
* @param string $filterExpression
*/
private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable
private function buildSchemaAssetsFilterFromExpression($filterExpression): callable
{
return static function ($assetName) use ($filterExpression) {
if ($assetName instanceof AbstractAsset) {
......@@ -115,7 +116,7 @@ class Configuration
/**
* Sets the callable to use to filter schema assets.
*/
public function setSchemaAssetsFilter(?callable $callable = null) : ?callable
public function setSchemaAssetsFilter(?callable $callable = null): ?callable
{
$this->_attributes['filterSchemaAssetsExpression'] = null;
......@@ -125,7 +126,7 @@ class Configuration
/**
* Returns the callable to use to filter schema assets.
*/
public function getSchemaAssetsFilter() : ?callable
public function getSchemaAssetsFilter(): ?callable
{
return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null;
}
......
......@@ -22,6 +22,7 @@ use Doctrine\DBAL\Types\Type;
use Exception;
use Throwable;
use Traversable;
use function array_key_exists;
use function assert;
use function count;
......@@ -375,7 +376,7 @@ class Connection implements DriverConnection
*
* @throws DBALException If an invalid platform was specified for this connection.
*/
private function detectDatabasePlatform() : void
private function detectDatabasePlatform(): void
{
$version = $this->getDatabasePlatformVersion();
......@@ -616,7 +617,7 @@ class Connection implements DriverConnection
array &$columns,
array &$values,
array &$conditions
) : void {
): void {
$platform = $this->getDatabasePlatform();
foreach ($identifier as $columnName => $value) {
......@@ -836,7 +837,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function fetchAllNumeric(string $query, array $params = [], array $types = []) : array
public function fetchAllNumeric(string $query, array $params = [], array $types = []): array
{
try {
return $this->executeQuery($query, $params, $types)->fetchAllNumeric();
......@@ -856,7 +857,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function fetchAllAssociative(string $query, array $params = [], array $types = []) : array
public function fetchAllAssociative(string $query, array $params = [], array $types = []): array
{
try {
return $this->executeQuery($query, $params, $types)->fetchAllAssociative();
......@@ -876,10 +877,10 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function fetchColumn(string $query, array $params = [], array $types = []) : array
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array
{
try {
return $this->executeQuery($query, $params, $types)->fetchColumn();
return $this->executeQuery($query, $params, $types)->fetchFirstColumn();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
}
......@@ -896,7 +897,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function iterateNumeric(string $query, array $params = [], array $types = []) : Traversable
public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable
{
try {
$stmt = $this->executeQuery($query, $params, $types);
......@@ -920,7 +921,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function iterateAssociative(string $query, array $params = [], array $types = []) : Traversable
public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable
{
try {
$stmt = $this->executeQuery($query, $params, $types);
......@@ -944,7 +945,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function iterateColumn(string $query, array $params = [], array $types = []) : Traversable
public function iterateColumn(string $query, array $params = [], array $types = []): Traversable
{
try {
$stmt = $this->executeQuery($query, $params, $types);
......@@ -964,7 +965,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
try {
return new Statement($sql, $this);
......@@ -988,7 +989,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : ResultStatement
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): ResultStatement
{
if ($qcp !== null) {
return $this->executeCacheQuery($query, $params, $types, $qcp);
......@@ -1036,7 +1037,7 @@ class Connection implements DriverConnection
*
* @throws CacheException
*/
public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) : ResultStatement
public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp): ResultStatement
{
$resultCache = $qcp->getResultCacheDriver() ?? $this->_config->getResultCacheImpl();
......@@ -1068,7 +1069,7 @@ class Connection implements DriverConnection
return $stmt;
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$connection = $this->getWrappedConnection();
......@@ -1102,7 +1103,7 @@ class Connection implements DriverConnection
*
* @throws DBALException
*/
public function executeUpdate(string $query, array $params = [], array $types = []) : int
public function executeUpdate(string $query, array $params = [], array $types = []): int
{
$connection = $this->getWrappedConnection();
......@@ -1139,7 +1140,7 @@ class Connection implements DriverConnection
return $result;
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
$connection = $this->getWrappedConnection();
......@@ -1357,7 +1358,7 @@ class Connection implements DriverConnection
/**
* Commits all current nesting transactions.
*/
private function commitAll() : void
private function commitAll(): void
{
while ($this->transactionNestingLevel !== 0) {
if ($this->autoCommit === false && $this->transactionNestingLevel === 1) {
......@@ -1579,7 +1580,7 @@ class Connection implements DriverConnection
* @param mixed[] $params The map/list of named/positional parameters.
* @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types).
*/
private function _bindTypedValues(DriverStatement $stmt, array $params, array $types) : void
private function _bindTypedValues(DriverStatement $stmt, array $params, array $types): void
{
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
if (is_int(key($params))) {
......
......@@ -12,6 +12,7 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use InvalidArgumentException;
use function array_rand;
use function assert;
use function count;
......@@ -223,7 +224,7 @@ class MasterSlaveConnection extends Connection
/**
* {@inheritDoc}
*/
public function executeUpdate(string $query, array $params = [], array $types = []) : int
public function executeUpdate(string $query, array $params = [], array $types = []): int
{
$this->connect('master');
......@@ -303,7 +304,7 @@ class MasterSlaveConnection extends Connection
return parent::insert($tableName, $data, $types);
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
$this->connect('master');
......@@ -340,7 +341,7 @@ class MasterSlaveConnection extends Connection
parent::rollbackSavepoint($savepoint);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$this->connect('master');
assert($this->_conn instanceof DriverConnection);
......@@ -359,7 +360,7 @@ class MasterSlaveConnection extends Connection
return $statement;
}
public function prepare(string $sql) : Statement
public function prepare(string $sql): Statement
{
$this->connect('master');
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Exception;
use Throwable;
use function array_map;
use function bin2hex;
use function count;
......@@ -38,7 +39,7 @@ class DBALException extends Exception
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
}
public static function invalidPlatformSpecified() : self
public static function invalidPlatformSpecified(): self
{
return new self(
"Invalid 'platform' option specified, need to give an instance of " . AbstractPlatform::class . '.'
......@@ -48,7 +49,7 @@ class DBALException extends Exception
/**
* @param mixed $invalidPlatform
*/
public static function invalidPlatformType($invalidPlatform) : self
public static function invalidPlatformType($invalidPlatform): self
{
if (is_object($invalidPlatform)) {
return new self(
......@@ -185,7 +186,7 @@ class DBALException extends Exception
*/
private static function formatParameters(array $params)
{
return '[' . implode(', ', array_map(static function ($param) : string {
return '[' . implode(', ', array_map(static function ($param): string {
if (is_resource($param)) {
return (string) $param;
}
......@@ -286,12 +287,12 @@ class DBALException extends Exception
return new self('Type to be overwritten ' . $name . ' does not exist.');
}
public static function typeNotRegistered(Type $type) : self
public static function typeNotRegistered(Type $type): self
{
return new self(sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type)));
}
public static function typeAlreadyRegistered(Type $type) : self
public static function typeAlreadyRegistered(Type $type): self
{
return new self(
sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type))
......
......@@ -11,6 +11,7 @@ use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use function preg_match;
use function stripos;
use function version_compare;
......@@ -23,8 +24,8 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
/**
* {@inheritdoc}
*
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
* @link https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
* @link https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
*/
public function convertException($message, DriverException $exception)
{
......@@ -141,13 +142,15 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
*
* @throws DBALException
*/
private function getOracleMysqlVersionNumber(string $versionString) : string
private function getOracleMysqlVersionNumber(string $versionString): string
{
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
) === 0) {
if (
preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
) === 0
) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'<major_version>.<minor_version>.<patch_version>'
......@@ -173,13 +176,15 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
*
* @throws DBALException
*/
private function getMariaDbMysqlVersionNumber(string $versionString) : string
private function getMariaDbMysqlVersionNumber(string $versionString): string
{
if (preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
) === 0) {
if (
preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
) === 0
) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>'
......
......@@ -23,7 +23,7 @@ final class EasyConnectString
$this->string = $string;
}
public function __toString() : string
public function __toString(): string
{
return $this->string;
}
......@@ -33,7 +33,7 @@ final class EasyConnectString
*
* @param mixed[] $params
*/
public static function fromArray(array $params) : self
public static function fromArray(array $params): self
{
return new self(self::renderParams($params));
}
......@@ -43,7 +43,7 @@ final class EasyConnectString
*
* @param mixed[] $params
*/
public static function fromConnectionParameters(array $params) : self
public static function fromConnectionParameters(array $params): self
{
if (isset($params['connectstring'])) {
return new self($params['connectstring']);
......@@ -90,7 +90,7 @@ final class EasyConnectString
/**
* @param mixed[] $params
*/
private static function renderParams(array $params) : string
private static function renderParams(array $params): string
{
$chunks = [];
......@@ -110,7 +110,7 @@ final class EasyConnectString
/**
* @param mixed $value
*/
private static function renderValue($value) : string
private static function renderValue($value): string
{
if (is_array($value)) {
return self::renderParams($value);
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use function preg_match;
use function strpos;
use function version_compare;
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use function preg_match;
/**
......@@ -75,11 +76,13 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve
*/
public function createDatabasePlatformForVersion($version)
{
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
) === 0) {
if (
preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
) === 0
) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
use function strpos;
/**
......@@ -25,7 +26,8 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
return new Exception\LockWaitTimeoutException($message, $exception);
}
if (strpos($exception->getMessage(), 'must be unique') !== false ||
if (
strpos($exception->getMessage(), 'must be unique') !== false ||
strpos($exception->getMessage(), 'is not unique') !== false ||
strpos($exception->getMessage(), 'are not unique') !== false ||
strpos($exception->getMessage(), 'UNIQUE constraint failed') !== false
......@@ -33,7 +35,8 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
return new Exception\UniqueConstraintViolationException($message, $exception);
}
if (strpos($exception->getMessage(), 'may not be NULL') !== false ||
if (
strpos($exception->getMessage(), 'may not be NULL') !== false ||
strpos($exception->getMessage(), 'NOT NULL constraint failed') !== false
) {
return new Exception\NotNullConstraintViolationException($message, $exception);
......
......@@ -16,14 +16,14 @@ interface Connection
/**
* Prepares a statement for execution and returns a Statement object.
*/
public function prepare(string $sql) : Statement;
public function prepare(string $sql): Statement;
/**
* Executes an SQL statement, returning a result set as a Statement object.
*
* @throws DBALException
*/
public function query(string $sql) : ResultStatement;
public function query(string $sql): ResultStatement;
/**
* Quotes a string for use in a query.
......@@ -40,7 +40,7 @@ interface Connection
*
* @throws DBALException
*/
public function exec(string $statement) : int;
public function exec(string $statement): int;
/**
* Returns the ID of the last inserted row or sequence value.
......
......@@ -14,9 +14,9 @@ final class FetchUtils
*
* @throws DriverException
*/
public static function fetchOne(ResultStatement $stmt)
public static function fetchOne(Result $result)
{
$row = $stmt->fetchNumeric();
$row = $result->fetchNumeric();
if ($row === false) {
return false;
......@@ -30,11 +30,11 @@ final class FetchUtils
*
* @throws DriverException
*/
public static function fetchAllNumeric(ResultStatement $stmt) : array
public static function fetchAllNumeric(Result $result): array
{
$rows = [];
while (($row = $stmt->fetchNumeric()) !== false) {
while (($row = $result->fetchNumeric()) !== false) {
$rows[] = $row;
}
......@@ -46,11 +46,11 @@ final class FetchUtils
*
* @throws DriverException
*/
public static function fetchAllAssociative(ResultStatement $stmt) : array
public static function fetchAllAssociative(Result $result): array
{
$rows = [];
while (($row = $stmt->fetchAssociative()) !== false) {
while (($row = $result->fetchAssociative()) !== false) {
$rows[] = $row;
}
......@@ -62,11 +62,11 @@ final class FetchUtils
*
* @throws DriverException
*/
public static function fetchColumn(ResultStatement $stmt) : array
public static function fetchFirstColumn(Result $result): array
{
$rows = [];
while (($row = $stmt->fetchOne()) !== false) {
while (($row = $result->fetchOne()) !== false) {
$rows[] = $row;
}
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType;
use stdClass;
use function assert;
use function db2_autocommit;
use function db2_commit;
......@@ -22,6 +23,7 @@ use function db2_rollback;
use function db2_server_info;
use function db2_stmt_errormsg;
use function is_bool;
use const DB2_AUTOCOMMIT_OFF;
use const DB2_AUTOCOMMIT_ON;
......@@ -74,7 +76,7 @@ class DB2Connection implements ServerInfoAwareConnection
return false;
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
$stmt = @db2_prepare($this->conn, $sql);
if ($stmt === false) {
......@@ -84,7 +86,7 @@ class DB2Connection implements ServerInfoAwareConnection
return new DB2Statement($stmt);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$stmt = $this->prepare($sql);
$stmt->execute();
......@@ -106,7 +108,7 @@ class DB2Connection implements ServerInfoAwareConnection
return "'" . $input . "'";
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
$stmt = @db2_exec($this->conn, $statement);
......
......@@ -3,8 +3,10 @@
namespace Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use function assert;
use function db2_bind_param;
use function db2_execute;
......@@ -23,13 +25,14 @@ use function ksort;
use function stream_copy_to_stream;
use function stream_get_meta_data;
use function tmpfile;
use const DB2_BINARY;
use const DB2_CHAR;
use const DB2_LONG;
use const DB2_PARAM_FILE;
use const DB2_PARAM_IN;
class DB2Statement implements Statement
class DB2Statement implements Statement, Result
{
/** @var resource */
private $stmt;
......@@ -108,7 +111,7 @@ class DB2Statement implements Statement
*
* @throws DB2Exception
*/
private function bind($position, &$variable, int $parameterType, int $dataType) : void
private function bind($position, &$variable, int $parameterType, int $dataType): void
{
$this->bindParam[$position] =& $variable;
......@@ -119,6 +122,8 @@ class DB2Statement implements Statement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
......@@ -226,7 +231,7 @@ class DB2Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return FetchUtils::fetchAllNumeric($this);
}
......@@ -234,7 +239,7 @@ class DB2Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return FetchUtils::fetchAllAssociative($this);
}
......@@ -242,16 +247,25 @@ class DB2Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchColumn($this);
return FetchUtils::fetchFirstColumn($this);
}
public function rowCount() : int
public function rowCount(): int
{
return @db2_num_rows($this->stmt);
}
public function free(): void
{
$this->bindParam = [];
db2_free_result($this->stmt);
$this->result = false;
}
/**
* @return resource
*
......@@ -274,7 +288,7 @@ class DB2Statement implements Statement
*
* @throws DB2Exception
*/
private function copyStreamToStream($source, $target) : void
private function copyStreamToStream($source, $target): void
{
if (@stream_copy_to_stream($source, $target) === false) {
throw new DB2Exception('Could not copy source stream to temporary file: ' . error_get_last()['message']);
......@@ -286,7 +300,7 @@ class DB2Statement implements Statement
*
* @throws DB2Exception
*/
private function writeStringToStream(string $string, $target) : void
private function writeStringToStream(string $string, $target): void
{
if (@fwrite($target, $string) === false) {
throw new DB2Exception('Could not write string to temporary file: ' . error_get_last()['message']);
......
......@@ -11,7 +11,7 @@ namespace Doctrine\DBAL\Driver\Mysqli;
*/
final class HostRequired extends MysqliException
{
public static function forPersistentConnection() : self
public static function forPersistentConnection(): self
{
return new self('The "host" parameter is required for a persistent connection');
}
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType;
use mysqli;
use function defined;
use function floor;
use function in_array;
......@@ -20,6 +21,7 @@ use function restore_error_handler;
use function set_error_handler;
use function sprintf;
use function stripos;
use const MYSQLI_INIT_COMMAND;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use const MYSQLI_OPT_LOCAL_INFILE;
......@@ -68,7 +70,7 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
$this->setSecureConnection($params);
$this->setDriverOptions($driverOptions);
set_error_handler(static function () : bool {
set_error_handler(static function (): bool {
return true;
});
......@@ -129,12 +131,12 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
return false;
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
return new MysqliStatement($this->conn, $sql);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$stmt = $this->prepare($sql);
$stmt->execute();
......@@ -150,7 +152,7 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
return "'" . $this->conn->escape_string($input) . "'";
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
if ($this->conn->query($statement) === false) {
throw new MysqliException($this->conn->error, $this->conn->sqlstate, $this->conn->errno);
......@@ -201,7 +203,7 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
* @throws MysqliException When one of of the options is not supported.
* @throws MysqliException When applying doesn't work - e.g. due to incorrect value.
*/
private function setDriverOptions(array $driverOptions = []) : void
private function setDriverOptions(array $driverOptions = []): void
{
$supportedDriverOptions = [
MYSQLI_OPT_CONNECT_TIMEOUT,
......@@ -260,9 +262,10 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
*
* @throws MysqliException
*/
private function setSecureConnection(array $params) : void
private function setSecureConnection(array $params): void
{
if (! isset($params['ssl_key']) &&
if (
! isset($params['ssl_key']) &&
! isset($params['ssl_cert']) &&
! isset($params['ssl_ca']) &&
! isset($params['ssl_capath']) &&
......
......@@ -3,11 +3,13 @@
namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\ParameterType;
use mysqli;
use mysqli_stmt;
use function array_combine;
use function array_fill;
use function assert;
......@@ -21,7 +23,7 @@ use function is_resource;
use function sprintf;
use function str_repeat;
class MysqliStatement implements Statement
class MysqliStatement implements Statement, Result
{
/** @var string[] */
protected static $_paramTypeMap = [
......@@ -201,7 +203,7 @@ class MysqliStatement implements Statement
/**
* Binds parameters with known types previously bound to the statement
*/
private function bindTypedParameters() : void
private function bindTypedParameters(): void
{
$streams = $values = [];
$types = $this->types;
......@@ -244,7 +246,7 @@ class MysqliStatement implements Statement
*
* @throws MysqliException
*/
private function sendLongData(array $streams) : void
private function sendLongData(array $streams): void
{
foreach ($streams as $paramNr => $stream) {
while (! feof($stream)) {
......@@ -352,7 +354,7 @@ class MysqliStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return FetchUtils::fetchAllNumeric($this);
}
......@@ -360,7 +362,7 @@ class MysqliStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return FetchUtils::fetchAllAssociative($this);
}
......@@ -368,23 +370,24 @@ class MysqliStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchColumn($this);
return FetchUtils::fetchFirstColumn($this);
}
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
$this->_stmt->free_result();
$this->result = false;
$this->free();
return true;
}
public function rowCount() : int
public function rowCount(): int
{
if ($this->_columnNames === false) {
return $this->_stmt->affected_rows;
......@@ -400,4 +403,10 @@ class MysqliStatement implements Statement
{
return $this->_stmt->field_count;
}
public function free(): void
{
$this->_stmt->free_result();
$this->result = false;
}
}
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
use const OCI_NO_AUTO_COMMIT;
/**
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType;
use UnexpectedValueException;
use function addcslashes;
use function is_float;
use function is_int;
......@@ -20,6 +21,7 @@ use function oci_server_version;
use function preg_match;
use function sprintf;
use function str_replace;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_NO_AUTO_COMMIT;
......@@ -100,12 +102,12 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
return false;
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
return new OCI8Statement($this->dbh, $sql, $this);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$stmt = $this->prepare($sql);
$stmt->execute();
......@@ -127,7 +129,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
$stmt = $this->prepare($statement);
$stmt->execute();
......
......@@ -3,8 +3,10 @@
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use function assert;
use function count;
use function implode;
......@@ -24,6 +26,7 @@ use function preg_match;
use function preg_quote;
use function sprintf;
use function substr;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
......@@ -40,7 +43,7 @@ use const SQLT_CHR;
/**
* The OCI8 implementation of the Statement interface.
*/
class OCI8Statement implements Statement
class OCI8Statement implements Statement, Result
{
/** @var resource */
protected $_dbh;
......@@ -293,7 +296,7 @@ class OCI8Statement implements Statement
/**
* Converts DBAL parameter type to oci8 parameter type
*/
private function convertParameterType(int $type) : int
private function convertParameterType(int $type): int
{
switch ($type) {
case ParameterType::BINARY:
......@@ -309,17 +312,12 @@ class OCI8Statement implements Statement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
// not having the result means there's nothing to close
if (! $this->result) {
return true;
}
oci_cancel($this->_sth);
$this->result = false;
$this->free();
return true;
}
......@@ -363,7 +361,7 @@ class OCI8Statement implements Statement
return $ret;
}
public function rowCount() : int
public function rowCount(): int
{
$count = oci_num_rows($this->_sth);
......@@ -401,7 +399,7 @@ class OCI8Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW);
}
......@@ -409,7 +407,7 @@ class OCI8Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return $this->fetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW);
}
......@@ -417,11 +415,23 @@ class OCI8Statement implements Statement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0];
}
public function free(): void
{
// not having the result means there's nothing to close
if (! $this->result) {
return;
}
oci_cancel($this->_sth);
$this->result = false;
}
/**
* @return mixed|false
*/
......@@ -442,7 +452,7 @@ class OCI8Statement implements Statement
/**
* @return array<mixed>
*/
private function fetchAll(int $mode, int $fetchStructure) : array
private function fetchAll(int $mode, int $fetchStructure): array
{
// do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\ParameterType;
use PDO;
use function assert;
/**
......@@ -34,7 +35,7 @@ class PDOConnection implements ServerInfoAwareConnection
}
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
try {
return $this->connection->exec($statement);
......@@ -51,7 +52,7 @@ class PDOConnection implements ServerInfoAwareConnection
return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
}
public function prepare(string $sql) : Statement
public function prepare(string $sql): Statement
{
try {
return $this->createStatement(
......@@ -62,7 +63,7 @@ class PDOConnection implements ServerInfoAwareConnection
}
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
try {
$stmt = $this->connection->query($sql);
......@@ -109,7 +110,7 @@ class PDOConnection implements ServerInfoAwareConnection
/**
* Creates a wrapped statement
*/
protected function createStatement(\PDOStatement $stmt) : PDOStatement
protected function createStatement(\PDOStatement $stmt): PDOStatement
{
return new PDOStatement($stmt);
}
......@@ -138,7 +139,7 @@ class PDOConnection implements ServerInfoAwareConnection
return $this->connection->rollBack();
}
public function getWrappedConnection() : PDO
public function getWrappedConnection(): PDO
{
return $this->connection;
}
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use PDO;
use PDOException;
use function defined;
/**
......@@ -31,7 +32,8 @@ class Driver extends AbstractPostgreSQLDriver
$driverOptions
);
if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')
if (
defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')
&& (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
)
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use PDOException;
use function array_merge;
/**
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOStatement;
use Doctrine\DBAL\ParameterType;
use function strpos;
use function substr;
......@@ -43,7 +44,7 @@ class Connection extends PDOConnection
return $val;
}
protected function createStatement(\PDOStatement $stmt) : PDOStatement
protected function createStatement(\PDOStatement $stmt): PDOStatement
{
return new Statement($stmt);
}
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use PDO;
use function is_int;
use function sprintf;
......@@ -75,7 +76,7 @@ class Driver extends AbstractSQLServerDriver
*
* @param string[] $connectionOptions
*/
private function getConnectionOptionsDsn(array $connectionOptions) : string
private function getConnectionOptionsDsn(array $connectionOptions): string
{
$connectionOptionsDsn = '';
......
......@@ -16,7 +16,8 @@ class Statement extends PDOStatement
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
{
if (($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
if (
($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
&& $driverOptions === null
) {
$driverOptions = PDO::SQLSRV_ENCODING_BINARY;
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use PDO;
use function array_slice;
use function assert;
use function func_get_args;
......@@ -101,7 +102,7 @@ class PDOStatement implements Statement
}
}
public function rowCount() : int
public function rowCount(): int
{
return $this->stmt->rowCount();
}
......@@ -133,7 +134,7 @@ class PDOStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return $this->fetchAll(PDO::FETCH_NUM);
}
......@@ -141,7 +142,7 @@ class PDOStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return $this->fetchAll(PDO::FETCH_ASSOC);
}
......@@ -149,7 +150,7 @@ class PDOStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return $this->fetchAll(PDO::FETCH_COLUMN);
}
......@@ -173,7 +174,7 @@ class PDOStatement implements Statement
*
* @throws PDOException
*/
private function fetchAll(int $mode) : array
private function fetchAll(int $mode): array
{
try {
$data = $this->stmt->fetchAll($mode);
......@@ -191,7 +192,7 @@ class PDOStatement implements Statement
*
* @param int $type Parameter type
*/
private function convertParamType(int $type) : int
private function convertParamType(int $type): int
{
if (! isset(self::PARAM_TYPE_MAP[$type])) {
throw new InvalidArgumentException('Invalid parameter type: ' . $type);
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver;
/**
* Driver-level result statement execution result.
*/
interface Result
{
/**
* Returns the next row of the result as a numeric array or FALSE if there are no more rows.
*
* @return array<int,mixed>|false
*
* @throws DriverException
*/
public function fetchNumeric();
/**
* Returns the next row of the result as an associative array or FALSE if there are no more rows.
*
* @return array<string,mixed>|false
*
* @throws DriverException
*/
public function fetchAssociative();
/**
* Returns the first value of the next row of the result or FALSE if there are no more rows.
*
* @return mixed|false
*
* @throws DriverException
*/
public function fetchOne();
/**
* Returns an array containing all of the result rows represented as numeric arrays.
*
* @return array<int,array<int,mixed>>
*
* @throws DriverException
*/
public function fetchAllNumeric(): array;
/**
* Returns an array containing all of the result rows represented as associative arrays.
*
* @return array<int,array<string,mixed>>
*
* @throws DriverException
*/
public function fetchAllAssociative(): array;
/**
* Returns an array containing the values of the first column of the result.
*
* @return array<int,mixed>
*
* @throws DriverException
*/
public function fetchFirstColumn(): array;
/**
* Returns the number of rows affected by the DELETE, INSERT, or UPDATE statement that produced the result.
*
* If the statement executed a SELECT query or a similar platform-specific SQL (e.g. DESCRIBE, SHOW, etc.),
* some database drivers may return the number of rows returned by that query. However, this behaviour
* is not guaranteed for all drivers and should not be relied on in portable applications.
*
* @return int The number of rows.
*/
public function rowCount();
/**
* Returns the number of columns in the result
*
* @return int The number of columns in the result. If the columns cannot be counted,
* this method must return 0.
*/
public function columnCount();
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @deprecated Use Result::free() instead.
*
* @return bool TRUE on success or FALSE on failure.
*/
public function closeCursor();
/**
* Discards the non-fetched portion of the result, enabling the originating statement to be executed again.
*/
public function free(): void;
}
......@@ -12,6 +12,8 @@ interface ResultStatement
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @deprecated Use Result::free() instead.
*
* @return bool TRUE on success or FALSE on failure.
*/
public function closeCursor();
......@@ -34,7 +36,7 @@ interface ResultStatement
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*/
public function rowCount() : int;
public function rowCount(): int;
/**
* Returns the next row of a result set as a numeric array or FALSE if there are no more rows.
......@@ -70,7 +72,7 @@ interface ResultStatement
*
* @throws DriverException
*/
public function fetchAllNumeric() : array;
public function fetchAllNumeric(): array;
/**
* Returns an array containing all of the result set rows represented as associative arrays.
......@@ -79,7 +81,7 @@ interface ResultStatement
*
* @throws DriverException
*/
public function fetchAllAssociative() : array;
public function fetchAllAssociative(): array;
/**
* Returns an array containing the values of the first column of the result set.
......@@ -88,5 +90,5 @@ interface ResultStatement
*
* @throws DriverException
*/
public function fetchColumn() : array;
public function fetchFirstColumn(): array;
}
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver;
use function array_keys;
use function array_map;
use function implode;
......@@ -79,7 +80,7 @@ class Driver extends AbstractSQLAnywhereDriver
';PWD=' . $password .
';' . implode(
';',
array_map(static function ($key, $value) : string {
array_map(static function ($key, $value): string {
return $key . '=' . $value;
}, array_keys($driverOptions), $driverOptions)
);
......
......@@ -4,8 +4,9 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use function assert;
use function is_float;
use function is_int;
......@@ -86,7 +87,7 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection
return true;
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
if (sasql_real_query($this->connection, $statement) === false) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
......@@ -118,12 +119,12 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection
return $this->query('SELECT ' . $name . '.CURRVAL')->fetchOne();
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): Statement
{
return new SQLAnywhereStatement($this->connection, $sql);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$stmt = $this->prepare($sql);
$stmt->execute();
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\AbstractDriverException;
use InvalidArgumentException;
use function sasql_error;
use function sasql_errorcode;
use function sasql_sqlstate;
......
......@@ -4,8 +4,10 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use function array_key_exists;
use function assert;
use function is_int;
......@@ -23,7 +25,7 @@ use function sasql_stmt_result_metadata;
/**
* SAP SQL Anywhere implementation of the Statement interface.
*/
class SQLAnywhereStatement implements Statement
class SQLAnywhereStatement implements Statement, Result
{
/** @var resource The connection resource. */
private $conn;
......@@ -196,7 +198,7 @@ class SQLAnywhereStatement implements Statement
*
* @throws DriverException
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return FetchUtils::fetchAllNumeric($this);
}
......@@ -206,7 +208,7 @@ class SQLAnywhereStatement implements Statement
*
* @throws DriverException
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return FetchUtils::fetchAllAssociative($this);
}
......@@ -216,13 +218,18 @@ class SQLAnywhereStatement implements Statement
*
* @throws DriverException
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchColumn($this);
return FetchUtils::fetchFirstColumn($this);
}
public function rowCount() : int
public function rowCount(): int
{
return sasql_stmt_affected_rows($this->stmt);
}
public function free(): void
{
sasql_stmt_reset($this->stmt);
}
}
......@@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType;
use function is_float;
use function is_int;
use function sprintf;
......@@ -70,12 +71,12 @@ class SQLSrvConnection implements ServerInfoAwareConnection
return false;
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
return new SQLSrvStatement($this->conn, $sql, $this->lastInsertId);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
$stmt = $this->prepare($sql);
$stmt->execute();
......@@ -99,7 +100,7 @@ class SQLSrvConnection implements ServerInfoAwareConnection
return "'" . str_replace("'", "''", $value) . "'";
}
public function exec(string $statement) : int
public function exec(string $statement): int
{
$stmt = sqlsrv_query($this->conn, $statement);
......
......@@ -3,8 +3,10 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\AbstractDriverException;
use function rtrim;
use function sqlsrv_errors;
use const SQLSRV_ERR_ERRORS;
/**
......
......@@ -3,8 +3,10 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use function is_int;
use function is_numeric;
use function sqlsrv_execute;
......@@ -19,6 +21,7 @@ use function sqlsrv_prepare;
use function sqlsrv_rows_affected;
use function SQLSRV_SQLTYPE_VARBINARY;
use function stripos;
use const SQLSRV_ENC_BINARY;
use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_NUMERIC;
......@@ -27,7 +30,7 @@ use const SQLSRV_PARAM_IN;
/**
* SQL Server Statement.
*/
final class SQLSrvStatement implements Statement
final class SQLSrvStatement implements Statement, Result
{
/**
* The SQLSRV Resource.
......@@ -139,22 +142,12 @@ final class SQLSrvStatement implements Statement
/**
* {@inheritdoc}
*
* @deprecated Use free() instead.
*/
public function closeCursor()
{
// not having the result means there's nothing to close
if ($this->stmt === null || ! $this->result) {
return true;
}
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
// @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while (sqlsrv_fetch($this->stmt)) {
}
$this->result = false;
$this->free();
return true;
}
......@@ -283,7 +276,7 @@ final class SQLSrvStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return FetchUtils::fetchAllNumeric($this);
}
......@@ -291,7 +284,7 @@ final class SQLSrvStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return FetchUtils::fetchAllAssociative($this);
}
......@@ -299,12 +292,12 @@ final class SQLSrvStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return FetchUtils::fetchColumn($this);
return FetchUtils::fetchFirstColumn($this);
}
public function rowCount() : int
public function rowCount(): int
{
if ($this->stmt === null) {
return 0;
......@@ -319,6 +312,23 @@ final class SQLSrvStatement implements Statement
return 0;
}
public function free(): void
{
// not having the result means there's nothing to close
if ($this->stmt === null || ! $this->result) {
return;
}
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
// @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while (sqlsrv_fetch($this->stmt)) {
}
$this->result = false;
}
/**
* @return mixed|false
*/
......
......@@ -13,6 +13,7 @@ use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSQLiteDriver;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver;
use Doctrine\DBAL\Driver\SQLAnywhere\Driver as SQLAnywhereDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
use function array_keys;
use function array_map;
use function array_merge;
......@@ -126,7 +127,7 @@ final class DriverManager
array $params,
?Configuration $config = null,
?EventManager $eventManager = null
) : Connection {
): Connection {
// create default config and event manager, if not set
if ($config === null) {
$config = new Configuration();
......@@ -172,7 +173,7 @@ final class DriverManager
*
* @return string[]
*/
public static function getAvailableDrivers() : array
public static function getAvailableDrivers(): array
{
return array_keys(self::$_driverMap);
}
......@@ -184,7 +185,7 @@ final class DriverManager
*
* @throws DBALException
*/
private static function _checkParams(array $params) : void
private static function _checkParams(array $params): void
{
// check existence of mandatory parameters
......@@ -210,7 +211,7 @@ final class DriverManager
*
* @return string The normalized connection URL path
*/
private static function normalizeDatabaseUrlPath(string $urlPath) : string
private static function normalizeDatabaseUrlPath(string $urlPath): string
{
// Trim leading slash from URL path.
return substr($urlPath, 1);
......@@ -227,7 +228,7 @@ final class DriverManager
*
* @throws DBALException
*/
private static function parseDatabaseUrl(array $params) : array
private static function parseDatabaseUrl(array $params): array
{
if (! isset($params['url'])) {
return $params;
......@@ -282,7 +283,7 @@ final class DriverManager
*
* @return mixed[] The resolved connection parameters.
*/
private static function parseDatabaseUrlPath(array $url, array $params) : array
private static function parseDatabaseUrlPath(array $url, array $params): array
{
if (! isset($url['path'])) {
return $params;
......@@ -311,7 +312,7 @@ final class DriverManager
*
* @return mixed[] The resolved connection parameters.
*/
private static function parseDatabaseUrlQuery(array $url, array $params) : array
private static function parseDatabaseUrlQuery(array $url, array $params): array
{
if (! isset($url['query'])) {
return $params;
......@@ -336,7 +337,7 @@ final class DriverManager
*
* @return mixed[] The resolved connection parameters.
*/
private static function parseRegularDatabaseUrlPath(array $url, array $params) : array
private static function parseRegularDatabaseUrlPath(array $url, array $params): array
{
$params['dbname'] = $url['path'];
......@@ -355,7 +356,7 @@ final class DriverManager
*
* @return mixed[] The resolved connection parameters.
*/
private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
private static function parseSqliteDatabaseUrlPath(array $url, array $params): array
{
if ($url['path'] === ':memory:') {
$params['memory'] = true;
......@@ -378,7 +379,7 @@ final class DriverManager
*
* @throws DBALException If parsing failed or resolution is not possible.
*/
private static function parseDatabaseUrlScheme(array $url, array $params) : array
private static function parseDatabaseUrlScheme(array $url, array $params): array
{
if (isset($url['scheme'])) {
// The requested driver from the URL scheme takes precedence
......
......@@ -5,10 +5,12 @@ namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use function array_change_key_case;
use function array_merge;
use function count;
use function implode;
use const CASE_UPPER;
/**
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function func_get_args;
use function is_array;
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function func_get_args;
use function is_array;
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\ForwardCompatibility\Driver;
use Doctrine\DBAL\Driver\ResultStatement as BaseResultStatement;
/**
* Forward compatibility extension for the ResultStatement interface.
*
* @deprecated
*/
interface ResultStatement extends BaseResultStatement
{
}
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\ForwardCompatibility;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as BaseResultStatement;
/**
* Forward compatibility extension for the DBAL ResultStatement interface.
*
* @deprecated
*/
interface ResultStatement extends BaseResultStatement
{
}
......@@ -7,9 +7,11 @@ use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\LockMode;
use Throwable;
use function array_change_key_case;
use function assert;
use function is_int;
use const CASE_LOWER;
/**
......
......@@ -35,7 +35,7 @@ final class DependencyOrderCalculator
/**
* Checks for node (vertex) existence in graph.
*/
public function hasNode(string $hash) : bool
public function hasNode(string $hash): bool
{
return isset($this->nodeList[$hash]);
}
......@@ -45,7 +45,7 @@ final class DependencyOrderCalculator
*
* @param object $node
*/
public function addNode(string $hash, $node) : void
public function addNode(string $hash, $node): void
{
$vertex = new DependencyOrderNode();
......@@ -59,7 +59,7 @@ final class DependencyOrderCalculator
/**
* Adds a new dependency (edge) to the graph using their hashes.
*/
public function addDependency(string $fromHash, string $toHash) : void
public function addDependency(string $fromHash, string $toHash): void
{
$vertex = $this->nodeList[$fromHash];
$edge = new DependencyOrderEdge();
......@@ -78,7 +78,7 @@ final class DependencyOrderCalculator
*
* @return array<object>
*/
public function sort() : array
public function sort(): array
{
foreach ($this->nodeList as $vertex) {
if ($vertex->state !== self::NOT_VISITED) {
......@@ -101,7 +101,7 @@ final class DependencyOrderCalculator
*
* {@internal Highly performance-sensitive method.}
*/
private function visit(DependencyOrderNode $vertex) : void
private function visit(DependencyOrderNode $vertex): void
{
$vertex->state = self::IN_PROGRESS;
......
......@@ -28,6 +28,7 @@ use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use InvalidArgumentException;
use UnexpectedValueException;
use function addcslashes;
use function array_map;
use function array_merge;
......@@ -54,6 +55,7 @@ use function strpos;
use function strtolower;
use function strtoupper;
use function trigger_error;
use const E_USER_DEPRECATED;
/**
......@@ -574,7 +576,7 @@ abstract class AbstractPlatform
/**
* Gets the maximum length of a char field.
*/
public function getCharMaxLength() : int
public function getCharMaxLength(): int
{
return $this->getVarcharMaxLength();
}
......@@ -1550,7 +1552,7 @@ abstract class AbstractPlatform
$options['indexes'] = [];
$options['primary'] = [];
if (($createFlags&self::CREATE_INDEXES) > 0) {
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
if ($index->isPrimary()) {
$options['primary'] = $index->getQuotedColumns($this);
......@@ -1592,7 +1594,7 @@ abstract class AbstractPlatform
$columns[$columnData['name']] = $columnData;
}
if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = [];
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
......@@ -1628,7 +1630,7 @@ abstract class AbstractPlatform
return array_merge($sql, $columnSql);
}
protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string
protected function getCommentOnTableSQL(string $tableName, ?string $comment): string
{
$tableName = new Identifier($tableName);
......@@ -2436,7 +2438,7 @@ abstract class AbstractPlatform
*
* @param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method
*/
public function getIndexFieldDeclarationListSQL($columnsOrIndex) : string
public function getIndexFieldDeclarationListSQL($columnsOrIndex): string
{
if ($columnsOrIndex instanceof Index) {
return implode(', ', $columnsOrIndex->getQuotedColumns($this));
......@@ -2691,7 +2693,7 @@ abstract class AbstractPlatform
*/
public function convertFromBoolean($item)
{
return $item === null ? null: (bool) $item;
return $item === null ? null : (bool) $item;
}
/**
......@@ -3132,7 +3134,7 @@ abstract class AbstractPlatform
/**
* Whether the platform supports indexes with column length definitions.
*/
public function supportsColumnLengthIndexes() : bool
public function supportsColumnLengthIndexes(): bool
{
return false;
}
......@@ -3202,7 +3204,7 @@ abstract class AbstractPlatform
*
* If false, then getDropForeignKeySQL() throws exception.
*/
public function supportsCreateDropForeignKeyConstraints() : bool
public function supportsCreateDropForeignKeyConstraints(): bool
{
return true;
}
......@@ -3646,7 +3648,7 @@ abstract class AbstractPlatform
* @param string $escapeChar should be reused by the caller in the LIKE
* expression.
*/
final public function escapeStringForLike(string $inputString, string $escapeChar) : string
final public function escapeStringForLike(string $inputString, string $escapeChar): string
{
return preg_replace(
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
......@@ -3655,7 +3657,7 @@ abstract class AbstractPlatform
);
}
protected function getLikeWildcardCharacters() : string
protected function getLikeWildcardCharacters(): string
{
return '%_';
}
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use function array_merge;
use function count;
use function current;
......@@ -22,7 +23,7 @@ use function strtoupper;
class DB2Platform extends AbstractPlatform
{
public function getCharMaxLength() : int
public function getCharMaxLength(): int
{
return 254;
}
......@@ -523,7 +524,8 @@ class DB2Platform extends AbstractPlatform
$queryPart = 'ADD COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef);
// Adding non-nullable columns to a table requires a default value to be specified.
if (! empty($columnDef['notnull']) &&
if (
! empty($columnDef['notnull']) &&
! isset($columnDef['default']) &&
empty($columnDef['autoincrement'])
) {
......@@ -626,7 +628,7 @@ class DB2Platform extends AbstractPlatform
* @param string[] $sql The sequence of table alteration statements to fill.
* @param mixed[] $queryParts The sequence of column alteration clauses to fill.
*/
private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts) : void
private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts): void
{
$alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff);
......@@ -668,7 +670,8 @@ class DB2Platform extends AbstractPlatform
$clauses = [];
if ($columnDiff->hasChanged('type') ||
if (
$columnDiff->hasChanged('type') ||
$columnDiff->hasChanged('length') ||
$columnDiff->hasChanged('precision') ||
$columnDiff->hasChanged('scale') ||
......@@ -901,7 +904,7 @@ class DB2Platform extends AbstractPlatform
return Keywords\DB2Keywords::class;
}
public function getListTableCommentsSQL(string $table) : string
public function getListTableCommentsSQL(string $table): string
{
return sprintf(
<<<'SQL'
......
......@@ -9,7 +9,7 @@ namespace Doctrine\DBAL\Platforms\Keywords;
*/
final class MariaDb102Keywords extends MySQLKeywords
{
public function getName() : string
public function getName(): string
{
return 'MariaDb102';
}
......@@ -17,7 +17,7 @@ final class MariaDb102Keywords extends MySQLKeywords
/**
* {@inheritdoc}
*/
protected function getKeywords() : array
protected function getKeywords(): array
{
return [
'ACCESSIBLE',
......
......@@ -9,7 +9,7 @@ namespace Doctrine\DBAL\Platforms\Keywords;
*/
class PostgreSQL100Keywords extends PostgreSQL94Keywords
{
public function getName() : string
public function getName(): string
{
return 'PostgreSQL100';
}
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use function count;
use function implode;
use function str_replace;
......
......@@ -16,17 +16,17 @@ final class MariaDb1027Platform extends MySqlPlatform
*
* @link https://mariadb.com/kb/en/library/json-data-type/
*/
public function getJsonTypeDeclarationSQL(array $field) : string
public function getJsonTypeDeclarationSQL(array $field): string
{
return 'LONGTEXT';
}
protected function getReservedKeywordsClass() : string
protected function getReservedKeywordsClass(): string
{
return Keywords\MariaDb102Keywords::class;
}
protected function initializeDoctrineTypeMappings() : void
protected function initializeDoctrineTypeMappings(): void
{
parent::initializeDoctrineTypeMappings();
......
......@@ -11,6 +11,7 @@ use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\TextType;
use InvalidArgumentException;
use function array_diff_key;
use function array_merge;
use function array_unique;
......@@ -385,7 +386,7 @@ class MySqlPlatform extends AbstractPlatform
' ORDER BY ORDINAL_POSITION ASC';
}
public function getListTableMetadataSQL(string $table, ?string $database = null) : string
public function getListTableMetadataSQL(string $table, ?string $database = null): string
{
return sprintf(
<<<'SQL'
......@@ -589,7 +590,8 @@ SQL
$columnArray = $column->toArray();
// Don't propagate default value changes for unsupported column types.
if ($columnDiff->hasChanged('default') &&
if (
$columnDiff->hasChanged('default') &&
count($columnDiff->changedProperties) === 1 &&
($columnArray['type'] instanceof TextType || $columnArray['type'] instanceof BlobType)
) {
......@@ -1186,7 +1188,7 @@ SQL
return TransactionIsolationLevel::REPEATABLE_READ;
}
public function supportsColumnLengthIndexes() : bool
public function supportsColumnLengthIndexes(): bool
{
return true;
}
......
......@@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\BinaryType;
use InvalidArgumentException;
use function array_merge;
use function count;
use function explode;
......@@ -394,8 +395,10 @@ class OraclePlatform extends AbstractPlatform
$sql[] = $this->getCreateSequenceSQL($column['sequence']);
}
if (! isset($column['autoincrement']) || ! $column['autoincrement'] &&
(! isset($column['autoinc']) || ! $column['autoinc'])) {
if (
! isset($column['autoincrement']) || ! $column['autoincrement'] &&
(! isset($column['autoinc']) || ! $column['autoinc'])
) {
continue;
}
......@@ -818,7 +821,8 @@ SQL
// Do not generate column alteration clause if type is binary and only fixed property has changed.
// Oracle only supports binary type columns with variable length.
// Avoids unnecessary table alteration statements.
if ($column->getType() instanceof BinaryType &&
if (
$column->getType() instanceof BinaryType &&
$columnDiff->hasChanged('fixed') &&
count($columnDiff->changedProperties) === 1
) {
......@@ -1194,7 +1198,7 @@ SQL
return 'BLOB';
}
public function getListTableCommentsSQL(string $table, ?string $database = null) : string
public function getListTableCommentsSQL(string $table, ?string $database = null): string
{
$tableCommentsName = 'user_tab_comments';
$ownerCondition = '';
......
......@@ -11,7 +11,7 @@ use Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords;
*/
class PostgreSQL100Platform extends PostgreSQL94Platform
{
protected function getReservedKeywordsClass() : string
protected function getReservedKeywordsClass(): string
{
return PostgreSQL100Keywords::class;
}
......@@ -19,7 +19,7 @@ class PostgreSQL100Platform extends PostgreSQL94Platform
/**
* {@inheritDoc}
*/
public function getListSequencesSQL($database) : string
public function getListSequencesSQL($database): string
{
return 'SELECT sequence_name AS relname,
sequence_schema AS schemaname,
......
......@@ -15,6 +15,7 @@ use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type;
use UnexpectedValueException;
use function array_diff;
use function array_merge;
use function array_unique;
......@@ -111,7 +112,7 @@ class PostgreSQL94Platform extends AbstractPlatform
if ($startPos !== false) {
$str = $this->getSubstringExpression($str, $startPos);
return 'CASE WHEN (POSITION(' . $substr . ' IN ' . $str . ') = 0) THEN 0 ELSE (POSITION(' . $substr . ' IN ' . $str . ') + ' . ($startPos-1) . ') END';
return 'CASE WHEN (POSITION(' . $substr . ' IN ' . $str . ') = 0) THEN 0 ELSE (POSITION(' . $substr . ' IN ' . $str . ') + ' . ($startPos - 1) . ') END';
}
return 'POSITION(' . $substr . ' IN ' . $str . ')';
......@@ -479,7 +480,8 @@ SQL
$query .= ' NOT DEFERRABLE';
}
if (($foreignKey->hasOption('feferred') && $foreignKey->getOption('feferred') !== false)
if (
($foreignKey->hasOption('feferred') && $foreignKey->getOption('feferred') !== false)
|| ($foreignKey->hasOption('deferred') && $foreignKey->getOption('deferred') !== false)
) {
$query .= ' INITIALLY DEFERRED';
......@@ -904,7 +906,7 @@ SQL
return $this->doConvertBooleans(
$item,
static function ($boolean) : ?int {
static function ($boolean): ?int {
return $boolean === null ? null : (int) $boolean;
}
);
......@@ -1264,7 +1266,7 @@ SQL
/**
* @param mixed[] $field
*/
private function isSerialField(array $field) : bool
private function isSerialField(array $field): bool
{
return isset($field['type'], $field['autoincrement'])
&& $field['autoincrement'] === true
......@@ -1274,7 +1276,7 @@ SQL
/**
* Check whether the type of a column is changed in a way that invalidates the default value for the column
*/
private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool
private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff): bool
{
if ($columnDiff->fromColumn === null) {
return $columnDiff->hasChanged('type');
......@@ -1288,17 +1290,17 @@ SQL
&& ! ($oldTypeIsNumeric && $newTypeIsNumeric && $columnDiff->column->getAutoincrement());
}
private function isNumericType(Type $type) : bool
private function isNumericType(Type $type): bool
{
return $type instanceof IntegerType || $type instanceof BigIntType;
}
private function getOldColumnComment(ColumnDiff $columnDiff) : ?string
private function getOldColumnComment(ColumnDiff $columnDiff): ?string
{
return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null;
}
public function getListTableMetadataSQL(string $table, ?string $schema = null) : string
public function getListTableMetadataSQL(string $table, ?string $schema = null): string
{
if ($schema !== null) {
$table = $schema . '.' . $table;
......
......@@ -16,6 +16,7 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use InvalidArgumentException;
use UnexpectedValueException;
use function array_merge;
use function array_unique;
use function array_values;
......@@ -1406,7 +1407,7 @@ SQL
return $matches[1] . $limitOffsetClause . ' ' . $matches[3];
}
private function getTopClauseSQL(?int $limit, ?int $offset) : string
private function getTopClauseSQL(?int $limit, ?int $offset): string
{
if ($offset > 0) {
return sprintf('TOP %s START AT %d', $limit ?? 'ALL', $offset + 1);
......
......@@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use InvalidArgumentException;
use function array_merge;
use function array_unique;
use function array_values;
......@@ -32,6 +33,7 @@ use function str_replace;
use function strpos;
use function strtoupper;
use function substr_count;
use const PREG_OFFSET_CAPTURE;
/**
......@@ -143,18 +145,18 @@ class SQLServer2012Platform extends AbstractPlatform
return true;
}
public function supportsSequences() : bool
public function supportsSequences(): bool
{
return true;
}
public function getAlterSequenceSQL(Sequence $sequence) : string
public function getAlterSequenceSQL(Sequence $sequence): string
{
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
' INCREMENT BY ' . $sequence->getAllocationSize();
}
public function getCreateSequenceSQL(Sequence $sequence) : string
public function getCreateSequenceSQL(Sequence $sequence): string
{
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
' START WITH ' . $sequence->getInitialValue() .
......@@ -165,7 +167,7 @@ class SQLServer2012Platform extends AbstractPlatform
/**
* {@inheritdoc}
*/
public function getDropSequenceSQL($sequence) : string
public function getDropSequenceSQL($sequence): string
{
if ($sequence instanceof Sequence) {
$sequence = $sequence->getQuotedName($this);
......@@ -1346,7 +1348,8 @@ SQL
$orderByPos = $matches[0][$matchesCount - 1][1];
}
if ($orderByPos === false
if (
$orderByPos === false
|| substr_count($query, '(', $orderByPos) !== substr_count($query, ')', $orderByPos)
) {
if (preg_match('/^SELECT\s+DISTINCT/im', $query) > 0) {
......@@ -1624,7 +1627,7 @@ SQL
return $name . ' ' . $columnDef;
}
protected function getLikeWildcardCharacters() : string
protected function getLikeWildcardCharacters(): string
{
return parent::getLikeWildcardCharacters() . '[]^';
}
......@@ -1657,7 +1660,7 @@ SQL
return strtoupper(dechex(crc32($identifier->getName())));
}
protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string
protected function getCommentOnTableSQL(string $tableName, ?string $comment): string
{
return sprintf(
<<<'SQL'
......@@ -1671,7 +1674,7 @@ SQL
);
}
public function getListTableMetadataSQL(string $table) : string
public function getListTableMetadataSQL(string $table): string
{
return sprintf(
<<<'SQL'
......
......@@ -11,6 +11,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use function array_merge;
use function array_unique;
use function array_values;
......@@ -375,7 +376,7 @@ class SqlitePlatform extends AbstractPlatform
* @param mixed[][] $columns
* @param mixed[] $options
*/
private function getNonAutoincrementPrimaryKeyDefinition(array $columns, array $options) : string
private function getNonAutoincrementPrimaryKeyDefinition(array $columns, array $options): string
{
if (empty($options['primary'])) {
return '';
......@@ -621,7 +622,7 @@ class SqlitePlatform extends AbstractPlatform
return '--' . str_replace("\n", "\n--", $comment) . "\n";
}
private function getInlineTableCommentSQL(string $comment) : string
private function getInlineTableCommentSQL(string $comment): string
{
return $this->getInlineColumnCommentSQL($comment);
}
......@@ -775,7 +776,7 @@ class SqlitePlatform extends AbstractPlatform
return true;
}
public function supportsCreateDropForeignKeyConstraints() : bool
public function supportsCreateDropForeignKeyConstraints(): bool
{
return false;
}
......@@ -967,7 +968,8 @@ class SqlitePlatform extends AbstractPlatform
{
// Suppress changes on integer type autoincrement columns.
foreach ($diff->changedColumns as $oldColumnName => $columnDiff) {
if ($columnDiff->fromColumn === null ||
if (
$columnDiff->fromColumn === null ||
! $columnDiff->column->getAutoincrement() ||
! $columnDiff->column->getType() instanceof Types\IntegerType
) {
......@@ -989,7 +991,8 @@ class SqlitePlatform extends AbstractPlatform
unset($diff->changedColumns[$oldColumnName]);
}
if (! empty($diff->renamedColumns) || ! empty($diff->addedForeignKeys) || ! empty($diff->addedIndexes)
if (
! empty($diff->renamedColumns) || ! empty($diff->addedForeignKeys) || ! empty($diff->addedIndexes)
|| ! empty($diff->changedColumns) || ! empty($diff->changedForeignKeys) || ! empty($diff->changedIndexes)
|| ! empty($diff->removedColumns) || ! empty($diff->removedForeignKeys) || ! empty($diff->removedIndexes)
|| ! empty($diff->renamedIndexes)
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use PDO;
use const CASE_LOWER;
use const CASE_UPPER;
......@@ -85,17 +86,17 @@ class Connection extends \Doctrine\DBAL\Connection
/**
* {@inheritdoc}
*/
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : ResultStatement
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): ResultStatement
{
return new Statement(parent::executeQuery($query, $params, $types, $qcp), $this->converter);
}
public function prepare(string $sql) : DriverStatement
public function prepare(string $sql): DriverStatement
{
return new Statement(parent::prepare($sql), $this->converter);
}
public function query(string $sql) : ResultStatement
public function query(string $sql): ResultStatement
{
return new Statement(parent::query($sql), $this->converter);
}
......
......@@ -90,7 +90,7 @@ final class Converter
*
* @return array<int,array<int,mixed>>
*/
public function convertAllNumeric(array $data) : array
public function convertAllNumeric(array $data): array
{
return ($this->convertAllNumeric)($data);
}
......@@ -100,7 +100,7 @@ final class Converter
*
* @return array<int,array<string,mixed>>
*/
public function convertAllAssociative(array $data) : array
public function convertAllAssociative(array $data): array
{
return ($this->convertAllAssociative)($data);
}
......@@ -110,7 +110,7 @@ final class Converter
*
* @return array<int,mixed>
*/
public function convertFirstColumn(array $data) : array
public function convertFirstColumn(array $data): array
{
return ($this->convertFirstColumn)($data);
}
......@@ -123,7 +123,7 @@ final class Converter
*
* @return callable|null The resulting function or NULL if no conversion is needed
*/
private function createConvertValue(bool $convertEmptyStringToNull, bool $rightTrimString) : ?callable
private function createConvertValue(bool $convertEmptyStringToNull, bool $rightTrimString): ?callable
{
$functions = [];
......@@ -158,7 +158,7 @@ final class Converter
*
* @return callable|null The resulting function or NULL if no conversion is needed
*/
private function createConvertRow(?callable $function, ?int $case) : ?callable
private function createConvertRow(?callable $function, ?int $case): ?callable
{
$functions = [];
......@@ -167,7 +167,7 @@ final class Converter
}
if ($case !== null) {
$functions[] = static function (array $row) use ($case) : array {
$functions[] = static function (array $row) use ($case): array {
return array_change_key_case($row, $case);
};
}
......@@ -182,7 +182,7 @@ final class Converter
* @param callable|null $function The function that will convert each tow
* @param callable $id Identity function
*/
private function createConvert(?callable $function, callable $id) : callable
private function createConvert(?callable $function, callable $id): callable
{
if ($function === null) {
return $id;
......@@ -204,7 +204,7 @@ final class Converter
* @param callable|null $function The function that will transform each value
* @param callable $id Identity function
*/
private function createConvertAll(?callable $function, callable $id) : callable
private function createConvertAll(?callable $function, callable $id): callable
{
if ($function === null) {
return $id;
......@@ -218,9 +218,9 @@ final class Converter
*
* @param callable $function The function that maps each value of the array
*/
private function createMapper(callable $function) : callable
private function createMapper(callable $function): callable
{
return static function (array $array) use ($function) : array {
return static function (array $array) use ($function): array {
return array_map($function, $array);
};
}
......@@ -232,9 +232,9 @@ final class Converter
*
* @return callable|null The composition or NULL if an empty set is provided
*/
private function compose(callable ...$functions) : ?callable
private function compose(callable ...$functions): ?callable
{
return array_reduce($functions, static function (?callable $carry, callable $item) : callable {
return array_reduce($functions, static function (?callable $carry, callable $item): callable {
if ($carry === null) {
return $item;
}
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Portability;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType;
use function assert;
/**
......@@ -75,7 +76,7 @@ class Statement implements DriverStatement
return $this->stmt->execute($params);
}
public function rowCount() : int
public function rowCount(): int
{
assert($this->stmt instanceof DriverStatement);
......@@ -115,7 +116,7 @@ class Statement implements DriverStatement
/**
* {@inheritdoc}
*/
public function fetchAllNumeric() : array
public function fetchAllNumeric(): array
{
return $this->converter->convertAllNumeric(
$this->stmt->fetchAllNumeric()
......@@ -125,7 +126,7 @@ class Statement implements DriverStatement
/**
* {@inheritdoc}
*/
public function fetchAllAssociative() : array
public function fetchAllAssociative(): array
{
return $this->converter->convertAllAssociative(
$this->stmt->fetchAllAssociative()
......@@ -135,10 +136,10 @@ class Statement implements DriverStatement
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
public function fetchFirstColumn(): array
{
return $this->converter->convertFirstColumn(
$this->stmt->fetchColumn()
$this->stmt->fetchFirstColumn()
);
}
}
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query\Expression;
use Countable;
use function array_merge;
use function count;
use function implode;
......@@ -53,7 +54,7 @@ class CompositeExpression implements Countable
* @param self|string $part
* @param self|string ...$parts
*/
public static function and($part, ...$parts) : self
public static function and($part, ...$parts): self
{
return new self(self::TYPE_AND, array_merge([$part], $parts));
}
......@@ -62,7 +63,7 @@ class CompositeExpression implements Countable
* @param self|string $part
* @param self|string ...$parts
*/
public static function or($part, ...$parts) : self
public static function or($part, ...$parts): self
{
return new self(self::TYPE_OR, array_merge([$part], $parts));
}
......@@ -115,7 +116,7 @@ class CompositeExpression implements Countable
* @param self|string $part
* @param self|string ...$parts
*/
public function with($part, ...$parts) : self
public function with($part, ...$parts): self
{
$that = clone $this;
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query\Expression;
use Doctrine\DBAL\Connection;
use function func_get_arg;
use function func_get_args;
use function func_num_args;
......@@ -44,7 +45,7 @@ class ExpressionBuilder
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function and($expression, ...$expressions) : CompositeExpression
public function and($expression, ...$expressions): CompositeExpression
{
return CompositeExpression::and($expression, ...$expressions);
}
......@@ -55,7 +56,7 @@ class ExpressionBuilder
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function or($expression, ...$expressions) : CompositeExpression
public function or($expression, ...$expressions): CompositeExpression
{
return CompositeExpression::or($expression, ...$expressions);
}
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use function array_key_exists;
use function array_keys;
use function array_unshift;
......@@ -491,7 +492,7 @@ class QueryBuilder
*
* @return $this This QueryBuilder instance.
*/
public function distinct() : self
public function distinct(): self
{
$this->sqlParts['distinct'] = true;
......@@ -1188,7 +1189,7 @@ class QueryBuilder
*
* @throws QueryException
*/
private function verifyAllAliasesAreKnown(array $knownAliases) : void
private function verifyAllAliasesAreKnown(array $knownAliases): void
{
foreach ($this->sqlParts['join'] as $fromAlias => $joins) {
if (! isset($knownAliases[$fromAlias])) {
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query;
use Doctrine\DBAL\DBALException;
use function implode;
/**
......
......@@ -19,6 +19,7 @@ use function sprintf;
use function strlen;
use function strpos;
use function substr;
use const PREG_OFFSET_CAPTURE;
/**
......@@ -65,13 +66,13 @@ class SQLParserUtils
*
* @return int[]
*/
private static function getPositionalPlaceholderPositions(string $statement) : array
private static function getPositionalPlaceholderPositions(string $statement): array
{
return self::collectPlaceholders(
$statement,
'?',
self::POSITIONAL_TOKEN,
static function (string $_, int $placeholderPosition, int $fragmentPosition, array &$carry) : void {
static function (string $_, int $placeholderPosition, int $fragmentPosition, array &$carry): void {
$carry[] = $placeholderPosition + $fragmentPosition;
}
);
......@@ -82,13 +83,13 @@ class SQLParserUtils
*
* @return string[]
*/
private static function getNamedPlaceholderPositions(string $statement) : array
private static function getNamedPlaceholderPositions(string $statement): array
{
return self::collectPlaceholders(
$statement,
':',
self::NAMED_TOKEN,
static function (string $placeholder, int $placeholderPosition, int $fragmentPosition, array &$carry) : void {
static function (string $placeholder, int $placeholderPosition, int $fragmentPosition, array &$carry): void {
$carry[$placeholderPosition + $fragmentPosition] = substr($placeholder, 1);
}
);
......@@ -97,7 +98,7 @@ class SQLParserUtils
/**
* @return mixed[]
*/
private static function collectPlaceholders(string $statement, string $match, string $token, callable $collector) : array
private static function collectPlaceholders(string $statement, string $match, string $token, callable $collector): array
{
if (strpos($statement, $match) === false) {
return [];
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function array_map;
use function crc32;
use function dechex;
......@@ -203,7 +204,7 @@ abstract class AbstractAsset
*/
protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30)
{
$hash = implode('', array_map(static function ($column) : string {
$hash = implode('', array_map(static function ($column): string {
return dechex(crc32($column));
}, $columnNames));
......
......@@ -10,6 +10,7 @@ use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Throwable;
use function array_filter;
use function array_intersect;
use function array_map;
......@@ -428,7 +429,7 @@ abstract class AbstractSchemaManager
*/
public function createTable(Table $table)
{
$createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS;
$createFlags = AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS;
$this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
}
......
......@@ -3,11 +3,13 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
use function array_merge;
use function is_numeric;
use function method_exists;
use function sprintf;
use function trigger_error;
use const E_USER_DEPRECATED;
/**
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types;
use function array_intersect_key;
use function array_key_exists;
use function array_keys;
......@@ -248,7 +249,8 @@ class Comparator
/* See if there are any removed indexes in table 2 */
foreach ($table1Indexes as $indexName => $index) {
// See if index is removed in table 2.
if (($index->isPrimary() && ! $table2->hasPrimaryKey()) ||
if (
($index->isPrimary() && ! $table2->hasPrimaryKey()) ||
! $index->isPrimary() && ! $table2->hasIndex($indexName)
) {
$tableDifferences->removedIndexes[$indexName] = $index;
......@@ -447,12 +449,15 @@ class Comparator
// Null values need to be checked additionally as they tell whether to create or drop a default value.
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
if (($properties1['default'] === null) !== ($properties2['default'] === null)
|| $properties1['default'] != $properties2['default']) {
if (
($properties1['default'] === null) !== ($properties2['default'] === null)
|| $properties1['default'] != $properties2['default']
) {
$changedProperties[] = 'default';
}
if (($properties1['type'] instanceof Types\StringType && ! $properties1['type'] instanceof Types\GuidType) ||
if (
($properties1['type'] instanceof Types\StringType && ! $properties1['type'] instanceof Types\GuidType) ||
$properties1['type'] instanceof Types\BinaryType
) {
// check if value of length is set at all, default value assumed otherwise.
......@@ -476,7 +481,8 @@ class Comparator
}
// A null value and an empty string are actually equal for a comment so they should not trigger a change.
if ($properties1['comment'] !== $properties2['comment'] &&
if (
$properties1['comment'] !== $properties2['comment'] &&
! ($properties1['comment'] === null && $properties2['comment'] === '') &&
! ($properties2['comment'] === null && $properties1['comment'] === '')
) {
......@@ -513,7 +519,7 @@ class Comparator
*
* @deprecated
*/
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other): bool
{
if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
return false;
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Types\Type;
use function array_change_key_case;
use function assert;
use function preg_match;
......@@ -11,6 +12,7 @@ use function str_replace;
use function strpos;
use function strtolower;
use function substr;
use const CASE_LOWER;
/**
......@@ -219,7 +221,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function listTableDetails($tableName) : Table
public function listTableDetails($tableName): Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function array_keys;
use function array_map;
use function strrpos;
......@@ -84,7 +85,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*
* @return Identifier[]
*/
private function createIdentifierMap(array $names) : array
private function createIdentifierMap(array $names): array
{
$identifiers = [];
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use InvalidArgumentException;
use function array_filter;
use function array_keys;
use function array_map;
......@@ -348,9 +349,9 @@ class Index extends AbstractAsset implements Constraint
/**
* Returns whether the index has the same column lengths as the other
*/
private function hasSameColumnLengths(self $other) : bool
private function hasSameColumnLengths(self $other): bool
{
$filter = static function (?int $length) : bool {
$filter = static function (?int $length): bool {
return $length !== null;
};
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;
use function array_change_key_case;
use function array_shift;
use function array_values;
......@@ -16,6 +17,7 @@ use function strpos;
use function strtok;
use function strtolower;
use function strtr;
use const CASE_LOWER;
/**
......@@ -146,11 +148,13 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'real':
case 'numeric':
case 'decimal':
if (preg_match(
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
$tableColumn['type'],
$match
) === 1) {
if (
preg_match(
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
$tableColumn['type'],
$match
) === 1
) {
$precision = $match[1];
$scale = $match[2];
$length = null;
......@@ -247,7 +251,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
*
* @param string|null $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
*/
private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?string $columnDefault) : ?string
private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?string $columnDefault): ?string
{
if ($columnDefault === 'NULL' || $columnDefault === null) {
return null;
......@@ -355,7 +359,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* @return string[]|true[]
*/
private function parseCreateOptions(?string $string) : array
private function parseCreateOptions(?string $string): array
{
$options = [];
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Types\Type;
use Throwable;
use function array_change_key_case;
use function array_values;
use function assert;
......@@ -17,6 +18,7 @@ use function strpos;
use function strtolower;
use function strtoupper;
use function trim;
use const CASE_LOWER;
/**
......@@ -398,7 +400,7 @@ SQL;
/**
* {@inheritdoc}
*/
public function listTableDetails($tableName) : Table
public function listTableDetails($tableName): Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -6,6 +6,7 @@ use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use function array_change_key_case;
use function array_filter;
use function array_keys;
......@@ -23,6 +24,7 @@ use function strlen;
use function strpos;
use function strtolower;
use function trim;
use const CASE_LOWER;
/**
......@@ -40,7 +42,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*/
public function getSchemaNames()
{
return $this->_conn->fetchColumn("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'");
return $this->_conn->fetchFirstColumn("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'");
}
/**
......@@ -90,7 +92,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$names = $this->getSchemaNames();
$paths = $this->getSchemaSearchPaths();
$this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) : bool {
$this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names): bool {
return in_array($v, $names, true);
});
}
......@@ -135,27 +137,33 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$foreignColumns = [];
$foreignTable = null;
if (preg_match(
'(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1) {
if (
preg_match(
'(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1
) {
$onUpdate = $match[1];
}
if (preg_match(
'(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1) {
if (
preg_match(
'(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1
) {
$onDelete = $match[1];
}
if (preg_match(
'/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/',
$tableForeignKey['condef'],
$values
) === 1) {
if (
preg_match(
'/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/',
$tableForeignKey['condef'],
$values
) === 1
) {
// PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get
// the idea to trim them here.
$localColumns = array_map('trim', explode(',', $values[1]));
......@@ -364,8 +372,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$jsonb = null;
$dbType = strtolower($tableColumn['type']);
if (strlen($tableColumn['domain_type']) > 0
&& ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
if (
strlen($tableColumn['domain_type']) > 0
&& ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])
) {
$dbType = strtolower($tableColumn['domain_type']);
$tableColumn['complete_type'] = $tableColumn['domain_complete_type'];
}
......@@ -433,11 +443,13 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'numeric':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
if (preg_match(
'([A-Za-z]+\(([0-9]+)\,([0-9]+)\))',
$tableColumn['complete_type'],
$match
) === 1) {
if (
preg_match(
'([A-Za-z]+\(([0-9]+)\,([0-9]+)\))',
$tableColumn['complete_type'],
$match
) === 1
) {
$precision = $match[1];
$scale = $match[2];
$length = null;
......@@ -455,11 +467,13 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
break;
}
if ($tableColumn['default'] !== null && preg_match(
"('([^']+)'::)",
$tableColumn['default'],
$match
) === 1) {
if (
$tableColumn['default'] !== null && preg_match(
"('([^']+)'::)",
$tableColumn['default'],
$match
) === 1
) {
$tableColumn['default'] = $match[1];
}
......@@ -509,7 +523,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* Parses a default value expression as given by PostgreSQL
*/
private function parseDefaultExpression(?string $default) : ?string
private function parseDefaultExpression(?string $default): ?string
{
if ($default === null) {
return $default;
......@@ -521,7 +535,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function listTableDetails($tableName) : Table
public function listTableDetails($tableName): Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Types\Type;
use function assert;
use function is_string;
use function preg_replace;
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Types\Type;
use PDOException;
use Throwable;
use function assert;
use function count;
use function is_string;
......@@ -128,7 +129,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
return $column;
}
private function parseDefaultExpression(string $value) : ?string
private function parseDefaultExpression(string $value): ?string
{
while (preg_match('/^\((.*)\)$/s', $value, $matches)) {
$value = $matches[1];
......@@ -334,7 +335,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
public function listTableDetails($tableName): Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\NamespaceVisitor;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use function array_keys;
use function strpos;
use function strtolower;
......@@ -106,9 +107,11 @@ class Schema extends AbstractAsset
throw SchemaException::tableAlreadyExists($tableName);
}
if ($namespaceName !== null
if (
$namespaceName !== null
&& ! $table->isInDefaultNamespace($this->getName())
&& ! $this->hasNamespace($namespaceName)) {
&& ! $this->hasNamespace($namespaceName)
) {
$this->createNamespace($namespaceName);
}
......@@ -130,9 +133,11 @@ class Schema extends AbstractAsset
throw SchemaException::sequenceAlreadyExists($seqName);
}
if ($namespaceName !== null
if (
$namespaceName !== null
&& ! $sequence->isInDefaultNamespace($this->getName())
&& ! $this->hasNamespace($namespaceName)) {
&& ! $this->hasNamespace($namespaceName)
) {
$this->createNamespace($namespaceName);
}
......
......@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Internal\DependencyOrderCalculator;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function array_merge;
/**
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use function implode;
use function sprintf;
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use function count;
use function sprintf;
......
......@@ -7,6 +7,7 @@ use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\Type;
use function array_change_key_case;
use function array_map;
use function array_reverse;
......@@ -25,6 +26,7 @@ use function strtolower;
use function trim;
use function unlink;
use function usort;
use const CASE_LOWER;
/**
......@@ -119,8 +121,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
if (! empty($tableForeignKeys)) {
$createSql = $this->getCreateTableSQL($table);
if (preg_match_all(
'#
if (
preg_match_all(
'#
(?:CONSTRAINT\s+([^\s]+)\s+)?
(?:FOREIGN\s+KEY[^\)]+\)\s*)?
REFERENCES\s+[^\s]+\s+(?:\([^\)]+\))?
......@@ -129,9 +132,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
(NOT\s+DEFERRABLE|DEFERRABLE)
(?:\s+INITIALLY\s+(DEFERRED|IMMEDIATE))?
)?#isx',
$createSql,
$match
) > 0) {
$createSql,
$match
) > 0
) {
$names = array_reverse($match[1]);
$deferrable = array_reverse($match[2]);
$deferred = array_reverse($match[3]);
......@@ -415,7 +419,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
'onDelete' => $value['on_delete'],
'onUpdate' => $value['on_update'],
'deferrable' => $value['deferrable'],
'deferred'=> $value['deferred'],
'deferred' => $value['deferred'],
];
}
......@@ -434,7 +438,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
'onDelete' => $constraint['onDelete'],
'onUpdate' => $constraint['onUpdate'],
'deferrable' => $constraint['deferrable'],
'deferred'=> $constraint['deferred'],
'deferred' => $constraint['deferred'],
]
);
}
......@@ -467,7 +471,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
return $tableDiff;
}
private function parseColumnCollationFromSQL(string $column, string $sql) : ?string
private function parseColumnCollationFromSQL(string $column, string $sql): ?string
{
$pattern = '{(?:\W' . preg_quote($column) . '\W|\W' . preg_quote($this->_platform->quoteSingleIdentifier($column))
. '\W)[^,(]+(?:\([^()]+\)[^,]*)?(?:(?:DEFAULT|CHECK)\s*(?:\(.*?\))?[^,]*)*COLLATE\s+["\']?([^\s,"\')]+)}is';
......@@ -479,7 +483,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
return $match[1];
}
private function parseTableCommentFromSQL(string $table, string $sql) : ?string
private function parseTableCommentFromSQL(string $table, string $sql): ?string
{
$pattern = '/\s* # Allow whitespace characters at start of line
CREATE\sTABLE # Match "CREATE TABLE"
......@@ -498,7 +502,7 @@ CREATE\sTABLE # Match "CREATE TABLE"
return $comment === '' ? null : $comment;
}
private function parseColumnCommentFromSQL(string $column, string $sql) : ?string
private function parseColumnCommentFromSQL(string $column, string $sql): ?string
{
$pattern = '{[\s(,](?:\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) . '\W|\W' . preg_quote($column)
. '\W)(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i';
......@@ -512,7 +516,7 @@ CREATE\sTABLE # Match "CREATE TABLE"
return $comment === '' ? null : $comment;
}
private function getCreateTableSQL(string $table) : string
private function getCreateTableSQL(string $table): string
{
$sql = $this->_conn->fetchOne(
<<<'SQL'
......@@ -541,7 +545,7 @@ SQL
/**
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
public function listTableDetails($tableName): Table
{
$table = parent::listTableDetails($tableName);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment