addSavepoint example

if (!empty($table_information->sequences)) {
      $options['sequence_name'] = $table_information->sequences[0];
    }

    // Re-initialize the values array so that we can re-use this query.     $this->insertValues = [];

    // Create a savepoint so we can rollback a failed query. This is so we can     // mimic MySQL and SQLite transactions which don't fail if a single query     // fails. This is important for tables that are created on demand. For     // example, \Drupal\Core\Cache\DatabaseBackend.     $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $options);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$options);
    }
  }

  
      // the foreach statement assigns the element to the existing reference.       $arguments = $this->fromQuery->getArguments();
      foreach ($arguments as $key => $value) {
        $stmt->getClientStatement()->bindParam($key$arguments[$key]);
      }
    }

    // Create a savepoint so we can rollback a failed query. This is so we can     // mimic MySQL and SQLite transactions which don't fail if a single query     // fails. This is important for tables that are created on demand. For     // example, \Drupal\Core\Cache\DatabaseBackend.     $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $this->queryOptions);
      if (isset($table_information->serial_fields[0])) {
        $last_insert_id = $stmt->fetchField();
      }
      $this->connection->releaseSavepoint();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }

    


    if (count($this->condition)) {
      $this->condition->compile($this->connection, $this);

      $arguments = $this->condition->arguments();
      foreach ($arguments as $placeholder => $value) {
        $stmt->getClientStatement()->bindParam($placeholder$arguments[$placeholder]);
      }
    }

    $this->connection->addSavepoint();
    try {
      $stmt->execute(NULL, $this->queryOptions);
      $this->connection->releaseSavepoint();
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }
  }

}
is_string($query) && (
        stripos($query, 'ROLLBACK TO SAVEPOINT ') === 0 ||
        stripos($query, 'RELEASE SAVEPOINT ') === 0 ||
        stripos($query, 'SAVEPOINT ') === 0
      )
    );
    if ($wrap_with_savepoint) {
      // Create a savepoint so we can rollback a failed query. This is so we can       // mimic MySQL and SQLite transactions which don't fail if a single query       // fails. This is important for tables that are created on demand. For       // example, \Drupal\Core\Cache\DatabaseBackend.       $this->addSavepoint();
      try {
        $return = parent::query($query$args$options);
        $this->releaseSavepoint();
      }
      catch (\Exception $e) {
        $this->rollbackSavepoint();
        throw $e;
      }
    }
    else {
      $return = parent::query($query$args$options);
    }
public function __construct(Connection $connection, string $table, array $options = []) {
    // @todo Remove the __construct in Drupal 11.     // @see https://www.drupal.org/project/drupal/issues/3256524     parent::__construct($connection$table$options);
    unset($this->queryOptions['return']);
  }

  /** * {@inheritdoc} */
  public function execute() {
    $this->connection->addSavepoint();
    try {
      $result = parent::execute();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      throw $e;
    }
    $this->connection->releaseSavepoint();

    return $result;
  }

}

    else {
      $key = $this->defaultSchema . '.' . $prefixed_table;
      $quoted_key = '"' . $this->defaultSchema . '"."' . $prefixed_table . '"';
    }

    if (!isset($this->tableInformation[$key])) {
      $table_information = (object) [
        'blob_fields' => [],
        'sequences' => [],
      ];
      $this->connection->addSavepoint();

      try {
        // The bytea columns and sequences for a table can be found in         // pg_attribute, which is significantly faster than querying the         // information_schema. The data type of a field can be found by lookup         // of the attribute ID, and the default value must be extracted from the         // node tree for the attribute definition instead of the historical         // human-readable column, adsrc.         $sql = <<<'EOD' SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS data_type, pg_get_expr(pg_attrdef.adbin, pg_attribute.attrelid) AS column_default FROM pg_attribute LEFT JOIN pg_attrdef ON pg_attrdef.adrelid = pg_attribute.attrelid AND pg_attrdef.adnum = pg_attribute.attnum WHERE pg_attribute.attnum > 0 AND NOT pg_attribute.attisdropped AND pg_attribute.attrelid = :key::regclass AND (format_type(pg_attribute.atttypid, pg_attribute.atttypmod) = 'bytea' OR pg_get_expr(pg_attrdef.adbin, pg_attribute.attrelid) LIKE 'nextval%')
'alias' => $this->connection->escapeAlias($alias_candidate),
      'arguments' => $arguments,
    ];

    return $alias;
  }

  /** * {@inheritdoc} */
  public function execute() {
    $this->connection->addSavepoint();
    try {
      $result = parent::execute();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      throw $e;
    }
    $this->connection->releaseSavepoint();

    return $result;
  }

}
public function __construct(Connection $connection, string $table, array $options = []) {
    // @todo Remove the __construct in Drupal 11.     // @see https://www.drupal.org/project/drupal/issues/3256524     parent::__construct($connection$table$options);
    unset($this->queryOptions['return']);
  }

  /** * {@inheritdoc} */
  public function execute() {
    $this->connection->addSavepoint();
    try {
      $result = parent::execute();
    }
    catch (\Exception $e) {
      $this->connection->rollbackSavepoint();
      throw $e;
    }
    $this->connection->releaseSavepoint();

    return $result;
  }

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