You are here

private function LegacyPdoSessionHandler::getMergeSql in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php \Symfony\Component\HttpFoundation\Session\Storage\Handler\LegacyPdoSessionHandler::getMergeSql()

Returns a merge/upsert (i.e. insert or update) SQL query when supported by the database.

Return value

string|null The SQL string or null when not supported

1 call to LegacyPdoSessionHandler::getMergeSql()
LegacyPdoSessionHandler::write in vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php

File

vendor/symfony/http-foundation/Session/Storage/Handler/LegacyPdoSessionHandler.php, line 238

Class

LegacyPdoSessionHandler
Session handler using a PDO connection to read and write data.

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler

Code

private function getMergeSql() {
  $driver = $this->pdo
    ->getAttribute(\PDO::ATTR_DRIVER_NAME);
  switch ($driver) {
    case 'mysql':
      return "INSERT INTO {$this->table} ({$this->idCol}, {$this->dataCol}, {$this->timeCol}) VALUES (:id, :data, :time) " . "ON DUPLICATE KEY UPDATE {$this->dataCol} = VALUES({$this->dataCol}), {$this->timeCol} = VALUES({$this->timeCol})";
    case 'oci':

      // 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";
    case 'sqlsrv' === $driver && version_compare($this->pdo
      ->getAttribute(\PDO::ATTR_SERVER_VERSION), '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
      return "MERGE INTO {$this->table} WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src 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;";
    case 'sqlite':
      return "INSERT OR REPLACE INTO {$this->table} ({$this->idCol}, {$this->dataCol}, {$this->timeCol}) VALUES (:id, :data, :time)";
  }
}