Skip to content

Commit

Permalink
Fixing DbalSessionHandler to work with a Oracle "limitation" or bug?
Browse files Browse the repository at this point in the history
  • Loading branch information
nuncanada authored and fabpot committed Aug 1, 2015
1 parent 041c489 commit c314659
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -159,6 +159,14 @@ public function write($sessionId, $data)
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$mergeStmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
$mergeStmt->bindValue(':time', time(), \PDO::PARAM_INT);

//Oracle has a bug that will intermitently happen if you
//have only 1 bind on a CLOB field for 2 different statements
//(INSERT and UPDATE in this case)
if ('oracle' == $this->con->getDatabasePlatform()->getName()) {
$mergeStmt->bindParam(':data2', $encoded, \PDO::PARAM_STR);
}

$mergeStmt->execute();

return true;
Expand Down Expand Up @@ -224,7 +232,7 @@ private function getMergeSql()
// DUAL is Oracle specific dummy table
return "MERGE INTO $this->table USING DUAL ON ($this->idCol = :id) ".
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ".
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :data, $this->timeCol = :time";
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :data2, $this->timeCol = :time";
case $this->con->getDatabasePlatform() instanceof SQLServer2008Platform:
// MERGE is only available since SQL Server 2008 and must be terminated by semicolon
// It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
Expand Down

0 comments on commit c314659

Please sign in to comment.