summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/database/query.inc15
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.