diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index 8c2a34a..e38196a 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -101,6 +101,21 @@ public static function open(array &$connection_options = array()) { return $pdo; } + /** + * {@inheritdoc} + */ + public function startTransaction($name = '') { + // Pop off and/or commit any transactions that are on the stack before + // attempting to create and return a new Transaction object. Menu router + // rebuild is the only case in core that creates a new transaction. + if (!empty($this->transactionLayers)) { + foreach ($this->transactionLayers as $savepoint_name) { + $this->popTransaction($savepoint_name); + } + } + + return parent::startTransaction($name); + } public function query($query, array $args = array(), $options = array()) { @@ -274,6 +289,24 @@ public function nextId($existing = 0) { return $id; } + + /** + * Add a new savepoint to mimic InnoDB. + */ + public function addSavepoint() { + if ($this->inTransaction()) { + $this->pushTransaction('mimic_innodb'); + } + } + + /** + * Release the mimic InnoDB savepoint. + */ + public function releaseSavepoint() { + if ($this->inTransaction()) { + $this->popTransaction('mimic_innodb'); + } + } } /** diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Delete.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Delete.php index 110adb3..1e3ef51 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Delete.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Delete.php @@ -9,24 +9,17 @@ use Drupal\Core\Database\Query\Delete as QueryDelete; -class Delete extends QueryDelete { - +class Delete extends QueryDelete { - /** + /** * {@inheritdoc} */ public function execute() { - if ($this->connection->inTransaction()) { - $this->connection->pushTransaction('mimic_innodb_not_released'); - } - + $this->connection->addSavepoint(); $result = parent::execute(); - - if ($this->connection->inTransaction()) { - $this->connection->popTransaction('mimic_innodb_not_released'); - } + $this->connection->releaseSavepoint(); return $result; - } - + } + } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index d73740d..3d510a2 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -60,9 +60,7 @@ public function queryTableInformation($table) { 'sequences' => array(), ); // Don't use {} around information_schema.columns table. - if ($this->connection->inTransaction()) { - $this->connection->pushTransaction('mimic_innodb_not_released'); - } + $this->connection->addSavepoint(); $result = $this->connection->query("SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default LIKE :default))", array( ':schema' => $schema, @@ -70,9 +68,7 @@ public function queryTableInformation($table) { ':default' => '%nextval%', )); - if ($this->connection->inTransaction()) { - $this->connection->popTransaction('mimic_innodb_not_released'); - } + $this->connection->releaseSavepoint(); foreach ($result as $column) { if ($column->data_type == 'bytea') { @@ -111,9 +107,7 @@ public function queryFieldInformation($table, $field) { $schema = $prefixInfo['schema']; $table_name = $prefixInfo['table']; - if ($this->connection->inTransaction()) { - $this->connection->pushTransaction('mimic_innodb_not_released'); - } + $this->connection->addSavepoint(); $checks = $this->connection->query("SELECT conname FROM pg_class cl INNER JOIN pg_constraint co ON co.conrelid = cl.oid INNER JOIN pg_attribute attr ON attr.attrelid = cl.oid AND attr.attnum = ANY (co.conkey) INNER JOIN pg_namespace ns ON cl.relnamespace = ns.oid WHERE co.contype = 'c' AND ns.nspname = :schema AND cl.relname = :table AND attr.attname = :column", array( ':schema' => $schema, @@ -121,9 +115,8 @@ public function queryFieldInformation($table, $field) { ':column' => $field, )); - if ($this->connection->inTransaction()) { - $this->connection->popTransaction('mimic_innodb_not_released'); - } + $this->connection->releaseSavepoint(); + $field_information = $checks->fetchCol(); return $field_information; diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php index b78d756..185cef9 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php @@ -109,15 +109,9 @@ public function orderBy($field, $direction = 'ASC') { * {@inheritdoc} */ public function execute() { - if ($this->connection->inTransaction()) { - $this->connection->pushTransaction('mimic_innodb_not_released'); - } - + $this->connection->addSavepoint(); $result = parent::execute(); - - if ($this->connection->inTransaction()) { - $this->connection->popTransaction('mimic_innodb_not_released'); - } + $this->connection->releaseSavepoint(); return $result; } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php index b3c769b..c6d39cf 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php @@ -11,20 +11,14 @@ class Truncate extends QueryTruncate { - /** + /** * {@inheritdoc} */ public function execute() { - if ($this->connection->inTransaction()) { - $this->connection->pushTransaction('mimic_innodb_not_released'); - } - + $this->connection->addSavepoint(); $result = parent::execute(); - - if ($this->connection->inTransaction()) { - $this->connection->popTransaction('mimic_innodb_not_released'); - } + $this->connection->releaseSavepoint(); return $result; - } + } }