Skip to content

Commit e0cbba9

Browse files
committed
choose the correctly cased class name for the SQLite platform
1 parent 561265a commit e0cbba9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Store/DoctrineDbalStore.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Configuration;
1515
use Doctrine\DBAL\Connection;
1616
use Doctrine\DBAL\DriverManager;
17+
use Doctrine\DBAL\Exception;
1718
use Doctrine\DBAL\Exception as DBALException;
1819
use Doctrine\DBAL\Exception\TableNotFoundException;
1920
use Doctrine\DBAL\ParameterType;
@@ -242,9 +243,16 @@ private function getCurrentTimestampStatement(): string
242243
{
243244
$platform = $this->conn->getDatabasePlatform();
244245

246+
if (interface_exists(Exception::class)) {
247+
// DBAL 4+
248+
$sqlitePlatformClass = 'Doctrine\DBAL\Platforms\SQLitePlatform';
249+
} else {
250+
$sqlitePlatformClass = 'Doctrine\DBAL\Platforms\SqlitePlatform';
251+
}
252+
245253
return match (true) {
246254
$platform instanceof \Doctrine\DBAL\Platforms\AbstractMySQLPlatform => 'UNIX_TIMESTAMP()',
247-
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'strftime(\'%s\',\'now\')',
255+
$platform instanceof $sqlitePlatformClass => 'strftime(\'%s\',\'now\')',
248256
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
249257
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
250258
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
@@ -259,9 +267,16 @@ private function platformSupportsTableCreationInTransaction(): bool
259267
{
260268
$platform = $this->conn->getDatabasePlatform();
261269

270+
if (interface_exists(Exception::class)) {
271+
// DBAL 4+
272+
$sqlitePlatformClass = 'Doctrine\DBAL\Platforms\SQLitePlatform';
273+
} else {
274+
$sqlitePlatformClass = 'Doctrine\DBAL\Platforms\SqlitePlatform';
275+
}
276+
262277
return match (true) {
263278
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform,
264-
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform,
279+
$platform instanceof $sqlitePlatformClass,
265280
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => true,
266281
default => false,
267282
};

Tests/Store/DoctrineDbalStoreTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Configuration;
1515
use Doctrine\DBAL\Connection;
1616
use Doctrine\DBAL\DriverManager;
17+
use Doctrine\DBAL\Exception;
1718
use Doctrine\DBAL\Exception\TableNotFoundException;
1819
use Doctrine\DBAL\Platforms\AbstractPlatform;
1920
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
@@ -176,7 +177,13 @@ public static function providePlatforms(): \Generator
176177
yield [\Doctrine\DBAL\Platforms\PostgreSQL94Platform::class];
177178
}
178179

179-
yield [\Doctrine\DBAL\Platforms\SqlitePlatform::class];
180+
if (interface_exists(Exception::class)) {
181+
// DBAL 4+
182+
yield [\Doctrine\DBAL\Platforms\SQLitePlatform::class];
183+
} else {
184+
yield [\Doctrine\DBAL\Platforms\SqlitePlatform::class];
185+
}
186+
180187
yield [\Doctrine\DBAL\Platforms\SQLServerPlatform::class];
181188

182189
// DBAL < 4

0 commit comments

Comments
 (0)