8000 Fix the DBAL session handler version check for Postgresql by stof · Pull Request #19369 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix the DBAL session handler version check for Postgresql #19369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Platforms\SQLServer2008Platform;

/**
Expand Down Expand Up @@ -241,9 +242,30 @@ private function getMergeSql()
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :data, $this->timeCol = :time;";
case 'sqlite' === $platform:
return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time)";
case 'postgresql' === $platform && version_compare($this->con->getServerVersion(), '9.5', '>='):
case 'postgresql' === $platform && version_compare($this->getServerVersion(), '9.5', '>='):
return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ".
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->timeCol)";
}
}

private function getServerVersion()
{
$params = $this->con->getParams();

if (isset($params['serverVersion'])) {
return $params['serverVersion']; // Explicit platform version requested (supersedes auto-detection), so we respect it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: these long comments on the side of the code are a bit "strange" and, if I recall it correctly, not frequently used in Symfony. We usually put them just above the commented code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see 1376e14

}

$wrappedConnection = $this->con->getWrappedConnection();

if ($wrappedConnection instanceof ServerInfoAwareConnection) {
return $wrappedConnection->getServerVersion();
}

if ($wrappedConnection instanceof \PDO) { // Support DBAL 2.4 by accessing it directly when using PDO PgSQL
return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION);
}

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.
}
}
0