public function DatabaseConnection_sqlsrv::nextId in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 sqlsrv/database.inc \DatabaseConnection_sqlsrv::nextId()
- 7 sqlsrv/database.inc \DatabaseConnection_sqlsrv::nextId()
Override of DatabaseConnection::nextId().
@status tested
Overrides DatabaseConnection::nextId
File
- sqlsrv/
database.inc, line 681 - Database interface code for Microsoft SQL Server.
Class
- DatabaseConnection_sqlsrv
- Summary of 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_direct('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.
}
}
// Refactored to use OUTPUT because under high concurrency LAST_INSERTED_ID does not work properly.
return $this
->query_direct('INSERT INTO {sequences} OUTPUT (Inserted.[value]) DEFAULT VALUES')
->fetchField();
}