13
13
14
14
use Doctrine \DBAL \Connection ;
15
15
use Doctrine \DBAL \Driver \DriverException ;
16
+ use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
16
17
use Doctrine \DBAL \Platforms \SQLServer2008Platform ;
17
18
18
19
/**
@@ -241,9 +242,30 @@ private function getMergeSql()
241
242
"WHEN MATCHED THEN UPDATE SET $ this ->dataCol = :data, $ this ->timeCol = :time; " ;
242
243
case 'sqlite ' === $ platform :
243
244
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 ' , '>= ' ):
245
246
return "INSERT INTO $ this ->table ( $ this ->idCol , $ this ->dataCol , $ this ->timeCol ) VALUES (:id, :data, :time) " .
246
247
"ON CONFLICT ( $ this ->idCol ) DO UPDATE SET ( $ this ->dataCol , $ this ->timeCol ) = (EXCLUDED. $ this ->dataCol , EXCLUDED. $ this ->timeCol ) " ;
247
248
}
248
249
}
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
+ }
249
271
}
0 commit comments