DatabaseConnection::rollback

public function DatabaseConnection::rollback

public DatabaseConnection::rollback($savepoint_name = 'drupal_transaction')

Rolls back the transaction entirely or to a named savepoint.

This method throws an exception if no transaction is active.

Parameters

$savepoint_name: The name of the savepoint. The default, 'drupal_transaction', will roll the entire transaction back.

Throws

DatabaseTransactionNoActiveException

See also

DatabaseTransaction::rollback()

File

includes/database/database.inc, line 1033
Core systems for the database layer.

Class

DatabaseConnection
Base Database API class.

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 == $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;
      }
      $this->query('ROLLBACK TO SAVEPOINT ' . $savepoint);
      $this->popCommittableTransactions();
      if ($rolled_back_other_active_savepoints) {
        throw new DatabaseTransactionOutOfOrderException();
      }
      return;
    }
    else {
      $rolled_back_other_active_savepoints = TRUE;
    }
  }
  parent::rollBack();
  if ($rolled_back_other_active_savepoints) {
    throw new DatabaseTransactionOutOfOrderException();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!database!database.inc/function/DatabaseConnection::rollback/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部