From 77308490d28e7707cecf5acdfd5f2e40669d716f Mon Sep 17 00:00:00 2001 From: Stephan Schuler Date: Thu, 22 Aug 2024 14:10:28 +0200 Subject: [PATCH] fix: Add MySqlPlatform for DBAL version <= 3.2 Doctrine uses `MySqlPlatform` as common parent class for all mysql-ish platforms up until DBAL version 3.2. Startig with DBAL version 3.3, the common class is `AbstractMySQLPlatform`. This is especially important for all DBAL versions matching semver "^2.13". Existing: @see https://github.com/doctrine/dbal/blob/3.2.2/src/Platforms/MySQLPlatform.php @see https://github.com/doctrine/dbal/blob/3.3.0/src/Platforms/AbstractMySQLPlatform.php Missing: @see https://github.com/doctrine/dbal/blob/3.2.2/src/Platforms/AbstractMySQLPlatform.php @see https://github.com/doctrine/dbal/blob/3.3.0/src/Platforms/MySQLPlatform.php --- src/Upsert.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Upsert.php b/src/Upsert.php index 72a3d0d..7869b2f 100644 --- a/src/Upsert.php +++ b/src/Upsert.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use RuntimeException; @@ -121,22 +122,24 @@ protected function buildQuery(string $identifiers, string $columns, string $valu return match (true) { $platform instanceof PostgreSQLPlatform => <<table}" ({$columns}) -VALUES ({$values}) -ON CONFLICT ({$identifiers}) DO UPDATE SET {$updates} -POSTGRESQL + INSERT INTO "{$this->table}" ({$columns}) + VALUES ({$values}) + ON CONFLICT ({$identifiers}) DO UPDATE SET {$updates} + POSTGRESQL , - $platform instanceof AbstractMySQLPlatform => <<table} ({$columns}) -VALUES ({$values}) -ON DUPLICATE KEY UPDATE {$updates} -MYSQL - ,$platform instanceof SqlitePlatform => <<table} ({$columns}) -VALUES ({$values}) -ON CONFLICT({$identifiers}) DO UPDATE SET {$updates} -SQLITE - ,default => throw new RuntimeException( + $platform instanceof AbstractMySQLPlatform || $platform instanceof MySqlPlatform => <<table} ({$columns}) + VALUES ({$values}) + ON DUPLICATE KEY UPDATE {$updates} + MYSQL + , + $platform instanceof SqlitePlatform => <<table} ({$columns}) + VALUES ({$values}) + ON CONFLICT({$identifiers}) DO UPDATE SET {$updates} + SQLITE + , + default => throw new RuntimeException( sprintf('The database platform %s is not supported!', $platform::class), 1_603_199_935 )