You are here

public function DatabaseConnection_sqlsrv::rollback in Drupal driver for SQL Server and SQL Azure 7.2

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

Overriden.

Overrides DatabaseConnection::rollback

File

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

Class

DatabaseConnection_sqlsrv
Summary of DatabaseConnection_sqlsrv

Code

public function rollback($savepoint_name = 'drupal_transaction') {
  if (!$this
    ->supportsTransactions()) {
    return;
  }
  if (!$this
    ->inTransaction()) {
    throw new DatabaseTransactionNoActiveException();
  }

  // A previous rollback to an earlier savepoint may mean that the savepoint
  // in question has already been accidentally committed.
  if (!isset($this->transactionLayers[$savepoint_name])) {
    throw new DatabaseTransactionNoActiveException();
  }

  // We need to find the point we're rolling back to, all other savepoints
  // before are no longer needed. If we rolled back other active savepoints,
  // we need to throw an exception.
  $rolled_back_other_active_savepoints = FALSE;
  while ($savepoint = array_pop($this->transactionLayers)) {
    if ($savepoint['name'] == $savepoint_name) {

      // If it is the last the transaction in the stack, then it is not a
      // savepoint, it is the transaction itself so we will need to roll back
      // the transaction rather than a savepoint.
      if (empty($this->transactionLayers)) {
        break;
      }
      if ($savepoint['started'] == TRUE) {
        $this
          ->query_direct('ROLLBACK TRANSACTION ' . $savepoint['name']);
      }
      $this
        ->popCommittableTransactions();
      if ($rolled_back_other_active_savepoints) {
        throw new DatabaseTransactionOutOfOrderException();
      }
      return;
    }
    else {
      $rolled_back_other_active_savepoints = TRUE;
    }
  }
  $this->connection
    ->rollback();

  // Restore original transaction isolation level
  if ($level = static::DefaultTransactionIsolationLevelInStatement()) {
    if ($savepoint['settings']
      ->Get_IsolationLevel() != DatabaseTransactionIsolationLevel::Ignore()) {
      if ($level != $savepoint['settings']
        ->Get_IsolationLevel()) {
        $this
          ->query_direct("SET TRANSACTION ISOLATION LEVEL {$level}");
      }
    }
  }
  if ($rolled_back_other_active_savepoints) {
    throw new DatabaseTransactionOutOfOrderException();
  }
}