diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-05-29 21:51:22 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-05-29 21:51:22 -0700 |
commit | 33d4ce4bde8f25634587666354cf14e0b60bf116 (patch) | |
tree | 320e3cb38c86eb7f71e101f73c726763f1718920 /includes/database/mysql | |
parent | 86bf589b563b698e507075ae47c36e92584ab9fc (diff) | |
download | brdo-33d4ce4bde8f25634587666354cf14e0b60bf116.tar.gz brdo-33d4ce4bde8f25634587666354cf14e0b60bf116.tar.bz2 |
Issue #1007830 by drunken monkey, Damien Tournoud, bfroehle: Fixed Nested transactions throw exceptions on ddl changes.
Diffstat (limited to 'includes/database/mysql')
-rw-r--r-- | includes/database/mysql/database.inc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc index 262cc6051..47ef8d52e 100644 --- a/includes/database/mysql/database.inc +++ b/includes/database/mysql/database.inc @@ -133,6 +133,55 @@ class DatabaseConnection_mysql extends DatabaseConnection { catch (PDOException $e) { } } + + /** + * Overridden to work around issues to MySQL not supporting transactional DDL. + */ + public function popTransaction($name) { + if (!$this->supportsTransactions()) { + return; + } + if (!$this->inTransaction()) { + throw new DatabaseTransactionNoActiveException(); + } + + // Commit everything since SAVEPOINT $name. + while ($savepoint = array_pop($this->transactionLayers)) { + if ($savepoint != $name) { + continue; + } + + // If there are no more layers left then we should commit. + if (empty($this->transactionLayers)) { + if (!PDO::commit()) { + throw new DatabaseTransactionCommitFailedException(); + } + } + else { + // Attempt to release this savepoint in the standard way. + try { + $this->query('RELEASE SAVEPOINT ' . $name); + } + catch (PDOException $e) { + // However, in MySQL (InnoDB), savepoints are automatically committed + // when tables are altered or created (DDL transactions are not + // supported). This can cause exceptions due to trying to release + // savepoints which no longer exist. + // + // To avoid exceptions when no actual error has occurred, we silently + // succeed for PDOExceptions with error code 42000 ("Syntax error or + // access rule violation"). + if ($e->getCode() != '42000') { + throw $e; + } + // If one SAVEPOINT was released automatically, then all were. + // Therefore, we keep just the topmost transaction. + $this->transactionLayers = array('drupal_transaction'); + } + break; + } + } + } } |