Skip to content

Commit

Permalink
Merge branch '4.1.x' into 5.0.x
Browse files Browse the repository at this point in the history
* 4.1.x: (25 commits)
  Simplify signature of fetchTableOptionsByTable
  Add MariaDb1010Platform for fetchTableOptionsByTable
  PHPUnit 10.5.21 (doctrine#6447)
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Default to distinct union queries (doctrine#6439)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
  Add `QueryBuilder` support for `UNION` clause (doctrine#6369)
  CI: Update MariaDB versions (doctrine#6426)
  CI MariaDB: add 11.4, remove 11.0 (doctrine#6432)
  Display warnings when running PHPUnit in CI (doctrine#6431)
  Fix typo in the portability documentation (doctrine#6430)
  Fix MariaDB fetching of default table character-set (doctrine#6361) (doctrine#6425)
  Fix the portability documentation (doctrine#6429)
  Update tests/Platforms/AbstractPlatformTestCase.php
  Update tests/Platforms/AbstractPlatformTestCase.php
  add test
  Fix: Skip type comparison if disableTypeComments is true
  Remove redundant variable (doctrine#6326)
  Fix test names to reflect their actual purpose
  ...
  • Loading branch information
derrabus committed Jun 19, 2024
2 parents aee1de3 + df2fc59 commit 819ac6a
Show file tree
Hide file tree
Showing 27 changed files with 829 additions and 57 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
if: "${{ matrix.extension == 'sqlite3' }}"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/oci8${{ matrix.oracle-version < 23 && '-21' || '' }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/oci8${{ matrix.oracle-version < 23 && '-21' || '' }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_oci${{ matrix.oracle-version < 23 && '-21' || '' }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_oci${{ matrix.oracle-version < 23 && '-21' || '' }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -262,7 +262,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand All @@ -284,19 +284,19 @@ jobs:
- "10.5" # Oldest version supported by DBAL, LTS (Jun 2025)
- "10.6" # LTS (Jul 2026)
- "10.11" # LTS (Feb 2028)
- "11.0" # STS (Jun 2024)
- "11.1" # STS (Aug 2024)
- "11.2" # STS (Nov 2024)
- "11.3" # STS (Feb 2025)
- "11.4" # LTS (May 2029)
extension:
- "mysqli"
- "pdo_mysql"
include:
- php-version: "8.2"
mariadb-version: "11.2"
mariadb-version: "11.4"
extension: "mysqli"
- php-version: "8.3"
mariadb-version: "11.2"
mariadb-version: "11.4"
extension: "pdo_mysql"

services:
Expand All @@ -307,7 +307,7 @@ jobs:
MYSQL_DATABASE: "doctrine_tests"

options: >-
--health-cmd "mariadb-admin ping --silent || mysqladmin ping --silent"
--health-cmd "healthcheck.sh --connect --innodb_initialized || mysqladmin ping --protocol tcp --silent"
ports:
- "3306:3306"
Expand All @@ -332,7 +332,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -415,7 +415,7 @@ jobs:
if: "${{ endsWith(matrix.config-file-suffix, 'tls') }}"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}${{ matrix.config-file-suffix }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}${{ matrix.config-file-suffix }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -482,7 +482,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -553,7 +553,7 @@ jobs:
composer-options: "--ignore-platform-req=php+"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/ibm_db2.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/ibm_db2.xml --coverage-clover=coverage.xml --display-warnings"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v4"
Expand Down Expand Up @@ -588,7 +588,7 @@ jobs:
composer-options: "--prefer-dist"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_sqlite.xml"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_sqlite.xml --display-warnings"

upload_coverage:
name: "Upload coverage to Codecov"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.2",
"phpstan/phpstan": "1.11.1",
"phpstan/phpstan": "1.11.5",
"phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "10.5.20",
"phpunit/phpunit": "10.5.21",
"psalm/plugin-phpunit": "0.19.0",
"slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.9.2",
Expand Down
1 change: 1 addition & 0 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ MariaDB

- ``MariaDBPlatform`` for version 10.5.2 and above.
- ``MariaDb1060Platform`` for version 10.6 and above.
- ``MariaDB1010Platform`` for version 10.10 and above.

Oracle
^^^^^^
Expand Down
13 changes: 7 additions & 6 deletions docs/en/reference/portability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ Using the following code block in your initialization will:
<?php
use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Portability\Connection as PortableConnection;
use Doctrine\DBAL\Portability\Middleware as PortableMiddleware;
$params = [
// vendor specific configuration
$configuration = new Configuration();
$configuration->setMiddlewares([
// Other middlewares
//...
'wrapperClass' => PortableConnection::class,
'portability' => PortableConnection::PORTABILITY_ALL,
'fetch_case' => ColumnCase::LOWER,
];
new PortableMiddleware(PortableConnection::PORTABILITY_ALL, ColumnCase::LOWER),
]);
This sort of portability handling is pretty expensive because all the result
rows and columns have to be looped inside PHP before being returned to you.
Expand Down
53 changes: 53 additions & 0 deletions docs/en/reference/query-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,59 @@ user-input:
->setParameter(0, $userInputLastLogin)
;
UNION-Clause
~~~~~~~~~~~~

To combine multiple ``SELECT`` queries into one result-set you can pass SQL Part strings
or QueryBuilder instances to one of the following methods:

* ``union(string|QueryBuilder $part)``
* ``addUnion(string|QueryBuilder $part, UnionType $type = UnionType::DISTINCT)``

.. code-block:: php
<?php
$queryBuilder
->union('SELECT 1 AS field')
->addUnion('SELECT 2 AS field')
->addUnion('SELECT 3 AS field')
->addUnion('SELECT 3 as field');
$queryBuilder
->union('SELECT 1 AS field')
->addUnion('SELECT 2 AS field', UnionType::ALL)
->addUnion('SELECT 3 AS field', UnionType::ALL)
->addUnion('SELECT 3 as field', UnionType::ALL);
$queryBuilder
->union('SELECT 1 AS field')
->addUnion('SELECT 2 AS field', UnionType::ALL)
->addUnion('SELECT 3 AS field', UnionType::ALL)
->addUnion('SELECT 3 as field', UnionType::DISTINCT);
$subQueryBuilder1
->select('id AS field')
->from('a_table');
$subQueryBuilder2
->select('id AS field')
->from('a_table');
$queryBuilder
->union($subQueryBuilder1)
->addUnion($subQueryBuilder2, UnionType::DISTINCT);
$subQueryBuilder1
->select('id AS field')
->from('a_table');
$subQueryBuilder2
->select('id AS field')
->from('a_table');
$queryBuilder
->union($subQueryBuilder1)
->addUnion($subQueryBuilder2,UnionType::ALL)
->orderBy('field', 'DESC')
->setMaxResults(100);
Building Expressions
--------------------

Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ parameters:

# Required for Psalm compatibility
- '~^Property Doctrine\\DBAL\\Tests\\Types\\BaseDateTypeTestCase\:\:\$currentTimezone \(non-empty-string\) does not accept string\.$~'

# This is a rather complicated closure setup. We understand this, so PHPStan doesn't have to.
-
message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null, callable\(T\)\: T\)\: \(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null\), Closure\(callable\|null, callable\)\: \(callable\(T\)\: T\) given\.$#'
path: src/Portability/Converter.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\MariaDB1010Platform;
use Doctrine\DBAL\Platforms\MariaDB1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL84Platform;
Expand All @@ -34,6 +35,10 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
$version = $versionProvider->getServerVersion();
if (stripos($version, 'mariadb') !== false) {
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
if (version_compare($mariaDbVersion, '10.10.0', '>=')) {
return new MariaDB1010Platform();
}

if (version_compare($mariaDbVersion, '10.6.0', '>=')) {
return new MariaDB1060Platform();
}
Expand Down
1 change: 0 additions & 1 deletion src/Driver/OCI8/Middleware/InitializeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function connect(
'ALTER SESSION SET'
. " NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
. " NLS_TIME_FORMAT = 'HH24:MI:SS'"
. " NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
. " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
. " NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZH:TZM'"
. " NLS_NUMERIC_CHARACTERS = '.,'",
Expand Down
26 changes: 26 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,30 @@ private function indexAssetsByLowerCaseName(array $assets): array

return $result;
}

public function fetchTableOptionsByTable(bool $includeTableName): string
{
$sql = <<<'SQL'
SELECT t.TABLE_NAME,
t.ENGINE,
t.AUTO_INCREMENT,
t.TABLE_COMMENT,
t.CREATE_OPTIONS,
t.TABLE_COLLATION,
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ccsa
ON ccsa.COLLATION_NAME = t.TABLE_COLLATION
SQL;

$conditions = ['t.TABLE_SCHEMA = ?'];

if ($includeTableName) {
$conditions[] = 't.TABLE_NAME = ?';
}

$conditions[] = "t.TABLE_TYPE = 'BASE TABLE'";

return $sql . ' WHERE ' . implode(' AND ', $conditions);
}
}
38 changes: 34 additions & 4 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder;
use Doctrine\DBAL\SQL\Builder\DefaultUnionSQLBuilder;
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\SQL\Builder\UnionSQLBuilder;
use Doctrine\DBAL\SQL\Parser;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
Expand Down Expand Up @@ -770,6 +772,11 @@ public function createSelectSQLBuilder(): SelectSQLBuilder
return new DefaultSelectSQLBuilder($this, 'FOR UPDATE', 'SKIP LOCKED');
}

public function createUnionSQLBuilder(): UnionSQLBuilder
{
return new DefaultUnionSQLBuilder($this);
}

/**
* @internal
*
Expand Down Expand Up @@ -816,8 +823,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr
}
}

$columnSql = [];
$columns = [];
$columns = [];

foreach ($table->getColumns() as $column) {
$columnData = $this->columnToArray($column);
Expand Down Expand Up @@ -847,7 +853,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr
}
}

return array_merge($sql, $columnSql);
return $sql;
}

/**
Expand Down Expand Up @@ -945,7 +951,7 @@ public function getInlineColumnCommentSQL(string $comment): string
* @param mixed[][] $columns
* @param mixed[] $options
*
* @return array<int, string>
* @return list<string>
*/
protected function _getCreateTableSQL(string $name, array $columns, array $options = []): array
{
Expand Down Expand Up @@ -2211,6 +2217,30 @@ public function columnsEqual(Column $column1, Column $column2): bool
return $column1->getComment() === $column2->getComment();
}

/**
* Returns the union select query part surrounded by parenthesis if possible for platform.
*/
public function getUnionSelectPartSQL(string $subQuery): string
{
return sprintf('(%s)', $subQuery);
}

/**
* Returns the `UNION ALL` keyword.
*/
public function getUnionAllSQL(): string
{
return 'UNION ALL';
}

/**
* Returns the compatible `UNION DISTINCT` keyword.
*/
public function getUnionDistinctSQL(): string
{
return 'UNION';
}

/**
* Creates the schema manager that can be used to inspect and change the underlying
* database schema according to the dialect of the platform.
Expand Down
10 changes: 9 additions & 1 deletion src/Platforms/Keywords/MySQL84Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Platforms\Keywords;

use function array_diff;
use function array_merge;

/**
Expand All @@ -14,12 +15,19 @@ class MySQL84Keywords extends MySQLKeywords
/**
* {@inheritDoc}
*
* @link https://dev.mysql.com/doc/refman/8.4/en/keywords.html#keywords-new-in-current-series
* @link https://dev.mysql.com/doc/refman/8.4/en/keywords.html
*/
protected function getKeywords(): array
{
$keywords = parent::getKeywords();

// Removed Keywords and Reserved Words
$keywords = array_diff($keywords, [
'MASTER_BIND',
'MASTER_SSL_VERIFY_SERVER_CERT',
]);

// New Keywords and Reserved Words
$keywords = array_merge($keywords, [
'AUTO',
'BERNOULLI',
Expand Down
Loading

0 comments on commit 819ac6a

Please sign in to comment.