8000 [Cache] Remove database server version detection · symfonyaml/symfony@842c3c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 842c3c2

Browse files
committed
[Cache] Remove database server version detection
1 parent 8f85593 commit 842c3c2

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

UPGRADE-7.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Cache
5454
-----
5555

5656
* Add parameter `\Closure $isSameDatabase` to `DoctrineDbalAdapter::configureSchema()`
57+
* Drop support for Postgres < 9.5 and SQL Server < 2008 in `DoctrineDbalAdapter`
5758

5859
Config
5960
------

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
use Doctrine\DBAL\ArrayParameterType;
1515
use Doctrine\DBAL\Configuration;
1616
use Doctrine\DBAL\Connection;
17-
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1817
use Doctrine\DBAL\DriverManager;
1918
use Doctrine\DBAL\Exception as DBALException;
2019
use Doctrine\DBAL\Exception\TableNotFoundException;
2120
use Doctrine\DBAL\ParameterType;
2221
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
2322
use Doctrine\DBAL\Schema\Schema;
24-
use Doctrine\DBAL\ServerVersionProvider;
2523
use Doctrine\DBAL\Tools\DsnParser;
2624
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2725
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
@@ -35,7 +33,6 @@ class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface
3533
private MarshallerInterface $marshaller;
3634
private Connection $conn;
3735
private string $platformName;
38-
private string $serverVersion;
3936
private string $table = 'cache_items';
4037
private string $idCol = 'item_id';
4138
private string $dataCol = 'item_data';
@@ -236,27 +233,27 @@ protected function doSave(array $values, int $lifetime): array|bool
236233
$platformName = $this->getPlatformName();
237234
$insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?)";
238235

239-
switch (true) {
240-
case 'mysql' === $platformName:
236+
switch ($platformName) {
237+
case 'mysql':
241238
$sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
242239
break;
243-
case 'oci' === $platformName:
240+
case 'oci':
244241
// DUAL is Oracle specific dummy table
245242
$sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
246243
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
247244
"WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
248245
break;
249-
case 'sqlsrv' === $platformName && version_compare($this->getServerVersion(), '10', '>='):
246+
case 'sqlsrv':
250247
// MERGE is only available since SQL Server 2008 and must be terminated by semicolon
251248
// It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
252249
$sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
253250
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
254251
"WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
255252
break;
256-
case 'sqlite' === $platformName:
253+
case 'sqlite':
257254
$sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
258255
break;
259-
case 'pgsql' === $platformName && version_compare($this->getServerVersion(), '9.5', '>='):
256+
case 'pgsql':
260257
$sql = $insertSql." ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
261258
break;
262259
default:
@@ -366,22 +363,6 @@ private function getPlatformName(): string
366363
};
367364
}
368365

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-
385366
private function addTableToSchema(Schema $schema): void
386367
{
387368
$types = [

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add parameter `$isSameDatabase` to `DoctrineDbalAdapter::configureSchema()`
8+
* Drop support for Postgres < 9.5 and SQL Server < 2008 in `DoctrineDbalAdapter`
89

910
6.4
1011
---

0 commit comments

Comments
 (0)
0