transactionDepth example


  protected $name;

  public function __construct(Connection $connection$name = NULL) {
    $this->connection = $connection;
    // If there is no transaction depth, then no transaction has started. Name     // the transaction 'drupal_transaction'.     if (!$depth = $connection->transactionDepth()) {
      $this->name = 'drupal_transaction';
    }
    // Within transactions, savepoints are used. Each savepoint requires a     // name. So if no name is present we need to create one.     elseif (!$name) {
      $this->name = 'savepoint_' . $depth;
    }
    else {
      $this->name = $name;
    }
    $this->connection->pushTransaction($this->name);
  }
public function escapeLike($string) {
    return addcslashes($string, '\%_');
  }

  /** * Determines if there is an active transaction open. * * @return bool * TRUE if we're currently in a transaction, FALSE otherwise. */
  public function inTransaction() {
    return ($this->transactionDepth() > 0);
  }

  /** * Determines the current transaction depth. * * @return int * The current transaction depth. */
  public function transactionDepth() {
    return count($this->transactionLayers);
  }

  

  protected function transactionOuterLayer($suffix$rollback = FALSE, $ddl_statement = FALSE) {
    $depth = $this->connection->transactionDepth();
    $txn = $this->connection->startTransaction();

    // Insert a single row into the testing table.     $this->connection->insert('test')
      ->fields([
        'name' => 'David' . $suffix,
        'age' => '24',
      ])
      ->execute();

    $this->assertTrue($this->connection->inTransaction(), 'In transaction before calling nested transaction.');

    
Home | Imprint | This part of the site doesn't use cookies.