@@ -347,7 +347,7 @@ public function write($sessionId, $data)
347
347
$ updateStmt ->bindValue (':time ' , time (), \PDO ::PARAM_INT );
348
348
$ updateStmt ->execute ();
349
349
350
- // When MERGE is not supported, like in Postgres, we have to use this approach that can result in
350
+ // When MERGE is not supported, like in Postgres < 9.5 , we have to use this approach that can result in
351
351
// duplicate key errors when the same session is written simultaneously (given the LOCK_NONE behavior).
352
352
// We can just catch such an error and re-execute the update. This is similar to a serializable
353
353
// transaction with retry logic on serialization failures but without the overhead and without possible
@@ -659,11 +659,11 @@ private function getSelectSql()
659
659
*/
660
660
private function getMergeSql ()
661
661
{
662
- switch ($ this -> driver ) {
663
- case 'mysql ' :
662
+ switch (true ) {
663
+ case 'mysql ' === $ this -> driver :
664
664
return "INSERT INTO $ this ->table ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (:id, :data, :lifetime, :time) " .
665
665
"ON DUPLICATE KEY UPDATE $ this ->dataCol = VALUES( $ this ->dataCol ), $ this ->lifetimeCol = VALUES( $ this ->lifetimeCol ), $ this ->timeCol = VALUES( $ this ->timeCol ) " ;
666
- case 'oci ' :
666
+ case 'oci ' === $ this -> driver :
667
667
// DUAL is Oracle specific dummy table
668
668
return "MERGE INTO $ this ->table USING DUAL ON ( $ this ->idCol = :id) " .
669
669
"WHEN NOT MATCHED THEN INSERT ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (:id, :data, :lifetime, :time) " .
@@ -674,8 +674,11 @@ private function getMergeSql()
674
674
return "MERGE INTO $ this ->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ( $ this ->idCol = :id) " .
675
675
"WHEN NOT MATCHED THEN INSERT ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (:id, :data, :lifetime, :time) " .
676
676
"WHEN MATCHED THEN UPDATE SET $ this ->dataCol = :data, $ this ->lifetimeCol = :lifetime, $ this ->timeCol = :time; " ;
677
- case 'sqlite ' :
677
+ case 'sqlite ' === $ this -> driver :
678
678
return "INSERT OR REPLACE INTO $ this ->table ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (:id, :data, :lifetime, :time) " ;
679
+ case 'pgsql ' === $ this ->driver && version_compare ($ this ->pdo ->getAttribute (\PDO ::ATTR_SERVER_VERSION ), '9.5 ' , '>= ' ):
680
+ return "INSERT INTO $ this ->table ( $ this ->idCol , $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) VALUES (:id, :data, :lifetime, :time) " .
681
+ "ON CONFLICT ( $ this ->idCol ) DO UPDATE SET ( $ this ->dataCol , $ this ->lifetimeCol , $ this ->timeCol ) = (:data, :lifetime, :time) WHERE $ this ->idCol = :id " ;
679
682
}
680
683
}
681
684
0 commit comments