You are here

public function Connection::rollback in Drupal driver for SQL Server and SQL Azure 8.2

Same name in this branch
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::rollback()
  2. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/PDO/Connection.php \Drupal\Driver\Database\sqlsrv\PDO\Connection::rollBack()
Same name and namespace in other branches
  1. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::rollback()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::rollBack()

Overriden.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php, line 863
Definition of Drupal\Driver\Database\sqlsrv\Connection

Class

Connection
Temporary tables: temporary table support is done by means of global temporary tables (#) to avoid the use of DIRECT QUERIES. You can enable and disable the use of direct queries with $this->driver_settings->defaultDirectQuery =…

Namespace

Drupal\Driver\Database\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 = $this->driver_settings
    ->GetDefaultTransactionIsolationLevelInStatement()) {
    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();
  }
}