8000 Fix the DBAL session handler version check for Postgresql · symfony/symfony@e98c584 · GitHub
[go: up one dir, main page]

Skip to content

Commit e98c584

Browse files
committed
Fix the DBAL session handler version check for Postgresql
1 parent d303b9d commit e98c584

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\Driver\DriverException;
16+
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1617
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
1718

1819
/**
@@ -241,9 +242,30 @@ private function getMergeSql()
241242
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :data, $this->timeCol = :time;";
242243
case 'sqlite' === $platform:
243244
return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time)";
244-
case 'postgresql' === $platform && version_compare($this->con->getServerVersion(), '9.5', '>='):
245+
case 'postgresql' === $platform && version_compare($this->getServerVersion(), '9.5', '>='):
245246
return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ".
246247
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->timeCol)";
247248
}
248249
}
250+
251+
private function getServerVersion()
252+
{
253+
$params = $this->con->getParams();
254+
255+
if (isset($params['serverVersion'])) {
256+
return $params['serverVersion']; // Explicit platform version requested (supersedes auto-detection), so we respect it.
257+
}
258+
259+
$wrappedConnection = $this->con->getWrappedConnection();
260+
261+
if ($wrappedConnection instanceof ServerInfoAwareConnection) {
262+
return $wrappedConnection->getServerVersion();
263+
}
264+
265+
if ($wrappedConnection instanceof \PDO) { // Support DBAL 2.4 by accessing it directly when using PDO PgSQL
266+
return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION);
267+
}
268+
269+
return ''; // If we cannot guess the version, the empty string will mean we won't use the code for newer versions when doing version checks.
270+
}
249271
}

0 commit comments

Comments
 (0)
0