Skip to content

Commit

Permalink
[HttpFoundation] fixed PDO session handler for Oracle (closes #5829)
Browse files Browse the repository at this point in the history
  • Loading branch information
MFoster authored and fabpot committed Nov 9, 2012
1 parent a30383d commit c2a8a0b
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -168,7 +168,9 @@ public function write($id, $data)
$encoded = base64_encode($data);

try {
if ('mysql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
$driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);

if ('mysql' === $driver) {
// MySQL would report $stmt->rowCount() = 0 on UPDATE when the data is left unchanged
// it could result in calling createNewSession() whereas the session already exists in
// the DB which would fail as the id is unique
Expand All @@ -180,6 +182,14 @@ public function write($id, $data)
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$stmt->execute();
} elseif ('oci' === $driver) {
$stmt = $this->pdo->prepare("MERGE INTO $dbTable USING DUAL ON($dbIdCol = :id) ".
"WHEN NOT MATCHED THEN INSERT ($dbIdCol, $dbDataCol, $dbTimeCol) VALUES (:id, :data, sysdate) " .
"WHEN MATCHED THEN UPDATE SET $dbDataCol = :data WHERE $dbIdCol = :id");

$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
$stmt->execute();
} else {
$stmt = $this->pdo->prepare("UPDATE $dbTable SET $dbDataCol = :data, $dbTimeCol = :time WHERE $dbIdCol = :id");
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
Expand Down

0 comments on commit c2a8a0b

Please sign in to comment.