You are here

public function DatabaseConnection_sqlsrv::nextId in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 7.3 sqlsrv/database.inc \DatabaseConnection_sqlsrv::nextId()
  2. 7.2 sqlsrv/database.inc \DatabaseConnection_sqlsrv::nextId()

Override of DatabaseConnection::nextId().

@status tested

Overrides DatabaseConnection::nextId

File

sqlsrv/database.inc, line 436
Database interface code for Microsoft SQL Server.

Class

DatabaseConnection_sqlsrv

Code

public function nextId($existing = 0) {

  // If an exiting value is passed, for its insertion into the sequence table.
  if ($existing > 0) {
    try {
      $this
        ->query('SET IDENTITY_INSERT {sequences} ON; INSERT INTO {sequences} (value) VALUES(:existing); SET IDENTITY_INSERT {sequences} OFF', array(
        ':existing' => $existing,
      ));
    } catch (Exception $e) {

      // Doesn't matter if this fails, it just means that this value is already
      // present in the table.
    }
  }
  return $this
    ->query('INSERT INTO {sequences} DEFAULT VALUES', array(), array(
    'return' => Database::RETURN_INSERT_ID,
  ));
}