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:
  Properly handle MySQL error code 4031 from PHP 8.4 (doctrine#6363)
  Add SmallFloat type (doctrine#6471)
  CI: Add MySQL 9, reduce test matrix (doctrine#6462)
  Fix update/delete aliases in documentation (doctrine#6470)
  Complete sentence
  Docs: update custom platform example to use middlewares (doctrine#6460)
  ci: nightly - php-8.1 only + workflow_dispatch
  ci: nightly - php-8.1 min version (doctrine#6457)
  mariadb: add nightly workflow to facilitate mariadb "nightlies" (doctrine#6435)
  • Loading branch information
derrabus committed Jul 23, 2024
2 parents 7d3b1ef + 886decf commit 162caab
Show file tree
Hide file tree
Showing 30 changed files with 317 additions and 45 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.3"
mysql-version:
- "8.0"
- "9.0"
extension:
- "mysqli"
- "pdo_mysql"
Expand All @@ -361,18 +362,19 @@ jobs:
php-version: "8.1"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.2"
- php-version: "8.1"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.3"
- php-version: "8.1"
mysql-version: "8.0"
extension: "pdo_mysql"
- php-version: "8.1"
# Workaround for https://bugs.mysql.com/114876
- php-version: "8.3"
mysql-version: "8.4"
extension: "mysqli"
custom-entrypoint: >-
--entrypoint sh mysql:8.4 -c "exec docker-entrypoint.sh mysqld --mysql-native-password=ON"
- php-version: "8.1"
- php-version: "8.3"
mysql-version: "8.4"
extension: "pdo_mysql"
custom-entrypoint: >-
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Continuous Integration (Nightly)"

on:
schedule:
- cron: "12 3 * * *"
workflow_dispatch:

env:
fail-fast: true

jobs:
phpunit-mariadb:
name: "PHPUnit with MariaDB"
runs-on: "ubuntu-24.04"

strategy:
matrix:
php-version:
- "8.3"
mariadb-version:
- "earliest"
- "verylatest"
extension:
- "mysqli"
- "pdo_mysql"

services:
mariadb:
image: "quay.io/mariadb-foundation/mariadb-devel:${{ matrix.mariadb-version }}"
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes
MARIADB_DATABASE: "doctrine_tests"

options: >-
--health-cmd "healthcheck.sh --connect --innodb_initialized"
ports:
- "3306:3306"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
ini-values: "zend.assertions=1"
extensions: "${{ matrix.extension }}"

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

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

- name: Tell the MariaDB Folks if it failed
if: ${{ failure() }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.MARIADB_ZULIP_API_KEY }}
email: "[email protected]"
organization-url: "https://mariadb.zulipchat.com"
to: "Buildbot"
type: "stream"
topic: "CI - Doctrine/DBAL"
content: "There was an error running Doctrine on MariaDB:${{ matrix.mariadb-version }} - URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}."
34 changes: 24 additions & 10 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,34 @@ database vendor and version best. Otherwise it is not guaranteed
that the compatibility in terms of SQL dialect and feature support
between Doctrine DBAL and the database server will always be given.

If you want to overwrite parts of your platform you can do so when
creating a connection. There is a ``platform`` option you can pass
an instance of the platform you want the connection to use:
If you want to overwrite parts of your platform you can do so by
using a middleware:

::

<?php
$myPlatform = new MyPlatform();
$options = [
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite',
'platform' => $myPlatform,
];
$conn = DriverManager::getConnection($options);
class CustomSQLitePlatform extends SqlitePlatform {}

class CustomDriver extends AbstractDriverMiddleware
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider)
{
return new CustomSQLitePlatform();
}
}

class CustomMiddleware implements Driver\Middleware
{
public function wrap(Driver $driver): Driver
{
return new CustomDriver($driver);
}
}

$config = new Doctrine\DBAL\Configuration();
$config->setMiddlewares([new CustomMiddleware()]);

$connection = DriverManager::getConnection($params, $config);

This way you can optimize your schema or generated SQL code with
features that might not be portable for instance, however are
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/query-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ user-input:
<?php
$queryBuilder
->update('users', 'u')
->update('users u')
->set('u.logins', 'u.logins + 1')
->set('u.last_login', '?')
->setParameter(0, $userInputLastLogin)
Expand Down
26 changes: 22 additions & 4 deletions docs/en/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,21 @@ or ``null`` if no data is present.
it approximates precision which can lead to false assumptions in
applications.

smallfloat
++++++++++

Maps and converts single precision floating-point values.
This type is suitable for storing numeric data with approximate precision, where 4-byte (32-bit) storage is sufficient.
Single precision values typically have a wide range, accommodating most numerical requirements with a precision of up to 7 decimal digits.
Values retrieved from the database are always converted to PHP's ``float``/``double`` type or ``null`` if no data is present.

float
+++++

Maps and converts numeric data with floating-point precision.
If you only need an approximate precision for numbers with fractions, you should
consider using this type.
Values retrieved from the database are always converted to PHP's
Maps and converts double precision floating-point values.
This type is suitable for storing numeric data with higher precision, requiring 8-byte (64-bit) storage.
Double precision values typically offer an extensive range, meeting the demands of more precise calculations
with a precision of up to 15 decimal digits. Values retrieved from the database are always converted to PHP's
``float``/``double`` type or ``null`` if no data is present.

String types
Expand Down Expand Up @@ -572,6 +580,16 @@ Please also notice the mapping specific footnotes for additional information.
| | +--------------------------+ | |
| | | **SQLite** | | |
+-------------------+---------------+--------------------------+---------+----------------------------------------------------------+
| **smallfloat** | ``float`` | **MySQL** | *all* | ``FLOAT`` ``UNSIGNED`` [10] |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``REAL`` |
| | +--------------------------+ | |
| | | **Oracle** | | |
| | +--------------------------+ | |
| | | **SQL Server** | | |
| | +--------------------------+ | |
| | | **SQLite** | | |
+-------------------+---------------+--------------------------+---------+----------------------------------------------------------+
| **float** | ``float`` | **MySQL** | *all* | ``DOUBLE PRECISION`` ``UNSIGNED`` [10] |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``DOUBLE PRECISION`` |
Expand Down
3 changes: 2 additions & 1 deletion src/Driver/API/MySQL/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function convert(Exception $exception, ?Query $query): DriverException
2002,
2005,
2054 => new ConnectionException($exception, $query),
2006 => new ConnectionLost($exception, $query),
2006,
4031 => new ConnectionLost($exception, $query),
1048,
1121,
1138,
Expand Down
10 changes: 9 additions & 1 deletion src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,14 @@ public function getFloatDeclarationSQL(array $column): string
return 'DOUBLE PRECISION' . $this->getUnsignedDeclaration($column);
}

/**
* {@inheritDoc}
*/
public function getSmallFloatDeclarationSQL(array $column): string
{
return 'FLOAT' . $this->getUnsignedDeclaration($column);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -720,7 +728,7 @@ protected function initializeDoctrineTypeMappings(): void
'datetime' => Types::DATETIME_MUTABLE,
'decimal' => Types::DECIMAL,
'double' => Types::FLOAT,
'float' => Types::FLOAT,
'float' => Types::SMALLFLOAT,
'int' => Types::INTEGER,
'integer' => Types::INTEGER,
'json' => Types::JSON,
Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,12 @@ public function getFloatDeclarationSQL(array $column): string
return 'DOUBLE PRECISION';
}

/** @param mixed[] $column */
public function getSmallFloatDeclarationSQL(array $column): string
{
return 'REAL';
}

/**
* Gets the default transaction isolation level of the platform.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function initializeDoctrineTypeMappings(): void
'decimal' => Types::DECIMAL,
'double' => Types::FLOAT,
'integer' => Types::INTEGER,
'real' => Types::FLOAT,
'real' => Types::SMALLFLOAT,
'smallint' => Types::SMALLINT,
'time' => Types::TIME_MUTABLE,
'timestamp' => Types::DATETIME_MUTABLE,
Expand Down
1 change: 1 addition & 0 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ protected function initializeDoctrineTypeMappings(): void
'nvarchar2' => Types::STRING,
'pls_integer' => Types::BOOLEAN,
'raw' => Types::BINARY,
'real' => Types::SMALLFLOAT,
'rowid' => Types::STRING,
'timestamp' => Types::DATETIME_MUTABLE,
'timestamptz' => Types::DATETIMETZ_MUTABLE,
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ protected function initializeDoctrineTypeMappings(): void
'double' => Types::FLOAT,
'double precision' => Types::FLOAT,
'float' => Types::FLOAT,
'float4' => Types::FLOAT,
'float4' => Types::SMALLFLOAT,
'float8' => Types::FLOAT,
'inet' => Types::STRING,
'int' => Types::INTEGER,
Expand All @@ -717,7 +717,7 @@ protected function initializeDoctrineTypeMappings(): void
'serial' => Types::INTEGER,
'serial4' => Types::INTEGER,
'serial8' => Types::BIGINT,
'real' => Types::FLOAT,
'real' => Types::SMALLFLOAT,
'smallint' => Types::SMALLINT,
'text' => Types::TEXT,
'time' => Types::TIME_MUTABLE,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ protected function initializeDoctrineTypeMappings(): void
'ntext' => Types::TEXT,
'numeric' => Types::DECIMAL,
'nvarchar' => Types::STRING,
'real' => Types::FLOAT,
'real' => Types::SMALLFLOAT,
'smalldatetime' => Types::DATETIME_MUTABLE,
'smallint' => Types::SMALLINT,
'smallmoney' => Types::INTEGER,
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected function initializeDoctrineTypeMappings(): void
'ntext' => 'string',
'numeric' => 'decimal',
'nvarchar' => 'string',
'real' => 'float',
'real' => 'smallfloat',
'serial' => 'integer',
'smallint' => 'smallint',
'string' => 'string',
Expand Down
14 changes: 7 additions & 7 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ public function addSelect(string $expression, string ...$expressions): self
*
* <code>
* $qb = $conn->createQueryBuilder()
* ->delete('users')
* ->where('users.id = :user_id')
* ->delete('users u')
* ->where('u.id = :user_id')
* ->setParameter(':user_id', 1);
* </code>
*
Expand All @@ -662,9 +662,9 @@ public function delete(string $table): self
*
* <code>
* $qb = $conn->createQueryBuilder()
* ->update('counters')
* ->set('counters.value', 'counters.value + 1')
* ->where('counters.id = ?');
* ->update('counters c')
* ->set('c.value', 'c.value + 1')
* ->where('c.id = ?');
* </code>
*
* @param string $table The table whose rows are subject to the update.
Expand Down Expand Up @@ -841,7 +841,7 @@ public function rightJoin(string $fromAlias, string $join, string $alias, ?strin
*
* <code>
* $qb = $conn->createQueryBuilder()
* ->update('counters', 'c')
* ->update('counters c')
* ->set('c.value', 'c.value + 1')
* ->where('c.id = ?');
* </code>
Expand Down Expand Up @@ -877,7 +877,7 @@ public function set(string $key, string $value): self
* $or->add($qb->expr()->eq('c.id', 1));
* $or->add($qb->expr()->eq('c.id', 2));
*
* $qb->update('counters', 'c')
* $qb->update('counters c')
* ->set('c.value', 'c.value + 1')
* ->where($or);
* </code>
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* The abstract asset allows to reset the name of all assets without publishing this to the public userland.
*
* This encapsulation hack is necessary to keep a consistent state of the database schema. Say we have a list of tables
* array($tableName => Table($tableName)); if you want to rename the table, you have to make sure
* array($tableName => Table($tableName)); if you want to rename the table, you have to make sure this does not get
* recreated during schema migration.
*/
abstract class AbstractAsset
{
Expand Down
7 changes: 7 additions & 0 deletions src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column

break;

case 'float':
if ($precision === 63) {
$type = 'smallfloat';
}

break;

case 'varchar':
case 'varchar2':
case 'nvarchar2':
Expand Down
Loading

0 comments on commit 162caab

Please sign in to comment.