Skip to content

fix: use named parameters #54172

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

Closed
wants to merge 1 commit into from
Closed
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
56 changes: 28 additions & 28 deletions src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,24 @@ protected function doSave(array $values, int $lifetime)
}

$platformName = $this->getPlatformName();
$insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?)";
$insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:idCol, :dataCol, :lifetimeCol, :timeCol)";

switch (true) {
case 'mysql' === $platformName:
$sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
break;
case 'oci' === $platformName:
// DUAL is Oracle specific dummy table
$sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
"WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
$sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = :idCol) ".
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:idCol, :dataCol, :lifetimeCol, :timeCol) ".
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :dataCol, $this->lifetimeCol = :lifetimeCol, $this->timeCol = :timeCol";
break;
case 'sqlsrv' === $platformName && version_compare($this->getServerVersion(), '10', '>='):
// 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
$sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
"WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
$sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = :idCol) ".
"WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:idCol, :dataCol, :lifetimeCol, :timeCol) ".
"WHEN MATCHED THEN UPDATE SET $this->dataCol = :dataCol, $this->lifetimeCol = :lifetimeCol, $this->timeCol = :timeCol";
break;
case 'sqlite' === $platformName:
$sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
Expand All @@ -296,7 +296,7 @@ protected function doSave(array $values, int $lifetime)
break;
default:
$platformName = null;
$sql = "UPDATE $this->table SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ? WHERE $this->idCol = ?";
$sql = "UPDATE $this->table SET $this->dataCol = :dataCol, $this->lifetimeCol = :lifetimeCol, $this->timeCol = :timeCol WHERE $this->idCol = :idCol";
break;
}

Expand All @@ -313,35 +313,35 @@ protected function doSave(array $values, int $lifetime)

if ('sqlsrv' === $platformName || 'oci' === $platformName) {
$bind = static function ($id, $data) use ($stmt) {
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $id);
$stmt->bindValue(3, $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue(6, $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue('idCol', $id);
$stmt->bindValue('idCol', $id);
$stmt->bindValue('dataCol', $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue('dataCol', $data, ParameterType::LARGE_OBJECT);
};
$stmt->bindValue(4, $lifetime, ParameterType::INTEGER);
$stmt->bindValue(5, $now, ParameterType::INTEGER);
$stmt->bindValue(7, $lifetime, ParameterType::INTEGER);
$stmt->bindValue(8, $now, ParameterType::INTEGER);
$stmt->bindValue('lifetimeCol', $lifetime, ParameterType::INTEGER);
$stmt->bindValue('timeCol', $now, ParameterType::INTEGER);
$stmt->bindValue('lifetimeCol', $lifetime, ParameterType::INTEGER);
$stmt->bindValue('timeCol', $now, ParameterType::INTEGER);
} elseif (null !== $platformName) {
$bind = static function ($id, $data) use ($stmt) {
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue('idCol', $id);
$stmt->bindValue('dataCol', $data, ParameterType::LARGE_OBJECT);
};
$stmt->bindValue(3, $lifetime, ParameterType::INTEGER);
$stmt->bindValue(4, $now, ParameterType::INTEGER);
$stmt->bindValue('lifetimeCol', $lifetime, ParameterType::INTEGER);
$stmt->bindValue('timeCol', $now, ParameterType::INTEGER);
} else {
$stmt->bindValue(2, $lifetime, ParameterType::INTEGER);
$stmt->bindValue(3, $now, ParameterType::INTEGER);
$stmt->bindValue('lifetimeCol', $lifetime, ParameterType::INTEGER);
$stmt->bindValue('timeCol', $now, ParameterType::INTEGER);

$insertStmt = $this->conn->prepare($insertSql);
$insertStmt->bindValue(3, $lifetime, ParameterType::INTEGER);
$insertStmt->bindValue(4, $now, ParameterType::INTEGER);
$insertStmt->bindValue('lifetimeCol', $lifetime, ParameterType::INTEGER);
$insertStmt->bindValue('timeCol', $now, ParameterType::INTEGER);

$bind = static function ($id, $data) use ($stmt, $insertStmt) {
$stmt->bindValue(1, $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue(4, $id);
$insertStmt->bindValue(1, $id);
$insertStmt->bindValue(2, $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue('dataCol', $data, ParameterType::LARGE_OBJECT);
$stmt->bindValue('idCol', $id);
$insertStmt->bindValue('idCol', $id);
$insertStmt->bindValue('dataCol', $data, ParameterType::LARGE_OBJECT);
};
}

Expand Down