diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-07-19 13:28:19 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-07-19 13:28:19 +0000 |
commit | a5f23317ef61276828386d90bd7787580b5b9ea9 (patch) | |
tree | 8971a4fa3ef90e784ac9bcb7a284f424c3f1d97f /includes/database/query.inc | |
parent | 9cf185c3917bb0de39ea5ce2d2ddbbc50b3e1d73 (diff) | |
download | brdo-a5f23317ef61276828386d90bd7787580b5b9ea9.tar.gz brdo-a5f23317ef61276828386d90bd7787580b5b9ea9.tar.bz2 |
- Patch #851110 by Damien Tournoud: InsertQuery::execute() needs to rollback the transaction if one insert fail.
Diffstat (limited to 'includes/database/query.inc')
-rw-r--r-- | includes/database/query.inc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc index 9e033304e..55c569e00 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -486,9 +486,18 @@ class InsertQuery extends Query { // we wrap it in a transaction so that it is atomic where possible. On many // databases, such as SQLite, this is also a notable performance boost. $transaction = $this->connection->startTransaction(); - $sql = (string) $this; - foreach ($this->insertValues as $insert_values) { - $last_insert_id = $this->connection->query($sql, $insert_values, $this->queryOptions); + + try { + $sql = (string) $this; + foreach ($this->insertValues as $insert_values) { + $last_insert_id = $this->connection->query($sql, $insert_values, $this->queryOptions); + } + } + catch (Exception $e) { + // One of the INSERTs failed, rollback the whole batch. + $transaction->rollback(); + // Rethrow the exception for the calling code. + throw $e; } // Re-initialize the values array so that we can re-use this query. |