14
14
use Doctrine \DBAL \ArrayParameterType ;
15
15
use Doctrine \DBAL \Configuration ;
16
16
use Doctrine \DBAL \Connection ;
17
- use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
18
17
use Doctrine \DBAL \DriverManager ;
19
18
use Doctrine \DBAL \Exception as DBALException ;
20
19
use Doctrine \DBAL \Exception \TableNotFoundException ;
21
20
use Doctrine \DBAL \ParameterType ;
22
21
use Doctrine \DBAL \Schema \DefaultSchemaManagerFactory ;
23
22
use Doctrine \DBAL \Schema \Schema ;
24
- use Doctrine \DBAL \ServerVersionProvider ;
25
23
use Doctrine \DBAL \Tools \DsnParser ;
26
24
use Symfony \Component \Cache \Exception \InvalidArgumentException ;
27
25
use Symfony \Component \Cache \Marshaller \DefaultMarshaller ;
@@ -35,7 +33,6 @@ class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface
35
33
private MarshallerInterface $ marshaller ;
36
34
private Connection $ conn ;
37
35
private string $ platformName ;
38
- private string $ serverVersion ;
39
36
private string $ table = 'cache_items ' ;
40
37
private string $ idCol = 'item_id ' ;
41
38
private string $ dataCol = 'item_data ' ;
@@ -236,27 +233,27 @@ protected function doSave(array $values, int $lifetime): array|bool
236
233
$ platformName = $ this ->getPlatformName ();
237
234
$ insertSql = "INSERT INTO $ this ->table ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (?, ?, ?, ?) " ;
238
235
239
- switch (true ) {
240
- case 'mysql ' === $ platformName :
236
+ switch ($ platformName ) {
237
+ case 'mysql ' :
241
238
$ sql = $ insertSql ." ON DUPLICATE KEY UPDATE $ this ->dataCol = VALUES( $ this ->dataCol ), $ this ->lifetimeCol = VALUES( $ this ->lifetimeCol ), $ this ->timeCol = VALUES( $ this ->timeCol ) " ;
242
239
break ;
243
- case 'oci ' === $ platformName :
240
+ case 'oci ' :
244
241
// DUAL is Oracle specific dummy table
245
242
$ sql = "MERGE INTO $ this ->table USING DUAL ON ( $ this ->idCol = ?) " .
246
243
"WHEN NOT MATCHED THEN INSERT ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (?, ?, ?, ?) " .
247
244
"WHEN MATCHED THEN UPDATE SET $ this ->dataCol = ?, $ this ->lifetimeCol = ?, $ this ->timeCol = ? " ;
248
245
break ;
249
- case 'sqlsrv ' === $ platformName && version_compare ( $ this -> getServerVersion (), ' 10 ' , ' >= ' ) :
246
+ case 'sqlsrv ' :
250
247
// MERGE is only available since SQL Server 2008 and must be terminated by semicolon
251
248
// It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
252
249
$ sql = "MERGE INTO $ this ->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ( $ this ->idCol = ?) " .
253
250
"WHEN NOT MATCHED THEN INSERT ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (?, ?, ?, ?) " .
254
251
"WHEN MATCHED THEN UPDATE SET $ this ->dataCol = ?, $ this ->lifetimeCol = ?, $ this ->timeCol = ?; " ;
255
252
break ;
256
- case 'sqlite ' === $ platformName :
253
+ case 'sqlite ' :
257
254
$ sql = 'INSERT OR REPLACE ' .substr ($ insertSql , 6 );
258
255
break ;
259
- case 'pgsql ' === $ platformName && version_compare ( $ this -> getServerVersion (), ' 9.5 ' , ' >= ' ) :
256
+ case 'pgsql ' :
260
257
$ sql = $ insertSql ." ON CONFLICT ( $ this ->idCol ) DO UPDATE SET ( $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) = (EXCLUDED. $ this ->dataCol , EXCLUDED. $ this ->lifetimeCol , EXCLUDED. $ this ->timeCol ) " ;
261
258
break ;
262
259
default :
@@ -366,22 +363,6 @@ private function getPlatformName(): string
366
363
};
367
364
}
368
365
369
- private function getServerVersion (): string
370
- {
371
- if (isset ($ this ->serverVersion )) {
372
- return $ this ->serverVersion ;
373
- }
374
-
375
- if ($ this ->conn instanceof ServerVersionProvider || $ this ->conn instanceof ServerInfoAwareConnection) {
376
- return $ this ->serverVersion = $ this ->conn ->getServerVersion ();
377
- }
378
-
379
- // The condition should be removed once support for DBAL <3.3 is dropped
380
- $ conn = method_exists ($ this ->conn , 'getNativeConnection ' ) ? $ this ->conn ->getNativeConnection () : $ this ->conn ->getWrappedConnection ();
381
-
382
- return $ this ->serverVersion = $ conn ->getAttribute (\PDO ::ATTR_SERVER_VERSION );
383
- }
384
-
385
366
private function addTableToSchema (Schema $ schema ): void
386
367
{
387
368
$ types = [
0 commit comments