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 = ?";
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 = ?;";
break;
case 'sqlite' ===
$platformName:
$sql = 'INSERT OR REPLACE'.
substr($insertSql, 6
);
break;
case 'pgsql' ===
$platformName &&
version_compare($this->
getServerVersion(), '9.5', '>='
):
$sql =
$insertSql." ON CONFLICT (
$this->idCol) DO UPDATE SET (
$this->dataCol,
$this->lifetimeCol,
$this->timeCol) = (EXCLUDED.
$this->dataCol, EXCLUDED.
$this->lifetimeCol, EXCLUDED.
$this->timeCol)";