Permalink
Browse files

Bug 739697 - Don't begin a transaction for formhistory.sqlite if ther…

…e's an existing one since we don't support nesting them. r=zpao,rnewman a=tracking-firefox

--HG--
extra : rebase_source : c78eed21037ffbd063230f9f16b1008eebb01310
  • Loading branch information...
1 parent a4e54a7 commit d30a56ad87ea0102e37a98830c8aa8fbdb1761a9 @mnoorenberghe mnoorenberghe committed Apr 6, 2012
Showing with 75 additions and 12 deletions.
  1. +38 −0 services/sync/tests/unit/test_forms_store.js
  2. +37 −12 toolkit/components/satchel/nsFormHistory.js
@@ -85,4 +85,42 @@ function run_test() {
for (let id in store.getAllIDs()) {
do_throw("Shouldn't get any ids!");
}
+
+ _("Add another entry to delete using applyIncomingBatch");
+ let toDelete = {
+ id: Utils.makeGUID(),
+ name: "todelete",
+ value: "entry"
+ };
+ applyEnsureNoFailures([toDelete]);
+ id = "";
+ for (let _id in store.getAllIDs()) {
+ if (id == "")
+ id = _id;
+ else
+ do_throw("Should have only gotten one!");
+ }
+ do_check_true(store.itemExists(id));
+ // mark entry as deleted
+ toDelete.id = id;
+ toDelete.deleted = true;
+ applyEnsureNoFailures([toDelete]);
+ for (let id in store.getAllIDs()) {
+ do_throw("Shouldn't get any ids!");
+ }
+
+ _("Add an entry to wipe");
+ applyEnsureNoFailures([{
+ id: Utils.makeGUID(),
+ name: "towipe",
+ value: "entry"
+ }]);
+
+ Utils.runInTransaction(Svc.Form.DBConnection, function() {
+ store.wipe();
+ });
+
+ for (let id in store.getAllIDs()) {
+ do_throw("Shouldn't get any ids!");
+ }
}
@@ -248,9 +248,13 @@ FormHistory.prototype = {
let stmt;
let query = "DELETE FROM moz_formhistory WHERE id = :id";
let params = { id : id };
+ let existingTransactionInProgress;
try {
- this.dbConnection.beginTransaction();
+ // Don't start a transaction if one is already in progress since we can't nest them.
+ existingTransactionInProgress = this.dbConnection.transactionInProgress;
+ if (!existingTransactionInProgress)
+ this.dbConnection.beginTransaction();
this.moveToDeletedTable("VALUES (:guid, :timeDeleted)", {
guid: guid,
timeDeleted: Date.now()
@@ -261,15 +265,17 @@ FormHistory.prototype = {
stmt.execute();
this.sendStringNotification("removeEntry", name, value, guid);
} catch (e) {
- this.dbConnection.rollbackTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.rollbackTransaction();
this.log("removeEntry failed: " + e);
throw e;
} finally {
if (stmt) {
stmt.reset();
}
}
- this.dbConnection.commitTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.commitTransaction();
},
@@ -281,9 +287,13 @@ FormHistory.prototype = {
let stmt;
let query = "DELETE FROM moz_formhistory WHERE fieldname = :fieldname";
let params = { fieldname : name };
+ let existingTransactionInProgress;
try {
- this.dbConnection.beginTransaction();
+ // Don't start a transaction if one is already in progress since we can't nest them.
+ existingTransactionInProgress = this.dbConnection.transactionInProgress;
+ if (!existingTransactionInProgress)
+ this.dbConnection.beginTransaction();
this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory " +
"WHERE fieldname = :fieldname", {
@@ -295,15 +305,17 @@ FormHistory.prototype = {
stmt.execute();
this.sendStringNotification("removeEntriesForName", name);
} catch (e) {
- this.dbConnection.rollbackTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.rollbackTransaction();
this.log("removeEntriesForName failed: " + e);
throw e;
} finally {
if (stmt) {
stmt.reset();
}
}
- this.dbConnection.commitTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.commitTransaction();
},
@@ -314,9 +326,13 @@ FormHistory.prototype = {
let stmt;
let query = "DELETE FROM moz_formhistory";
+ let existingTransactionInProgress;
try {
- this.dbConnection.beginTransaction();
+ // Don't start a transaction if one is already in progress since we can't nest them.
+ existingTransactionInProgress = this.dbConnection.transactionInProgress;
+ if (!existingTransactionInProgress)
+ this.dbConnection.beginTransaction();
this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory", {
timeDeleted: Date.now()
@@ -326,15 +342,17 @@ FormHistory.prototype = {
stmt.execute();
this.sendNotification("removeAllEntries", null);
} catch (e) {
- this.dbConnection.rollbackTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.rollbackTransaction();
this.log("removeAllEntries failed: " + e);
throw e;
} finally {
if (stmt) {
stmt.reset();
}
}
- this.dbConnection.commitTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.commitTransaction();
},
@@ -375,8 +393,13 @@ FormHistory.prototype = {
beginTime : beginTime,
endTime : endTime
};
+ let existingTransactionInProgress;
+
try {
- this.dbConnection.beginTransaction();
+ // Don't start a transaction if one is already in progress since we can't nest them.
+ existingTransactionInProgress = this.dbConnection.transactionInProgress;
+ if (!existingTransactionInProgress)
+ this.dbConnection.beginTransaction();
this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory " +
"WHERE firstUsed >= :beginTime AND firstUsed <= :endTime", {
@@ -388,15 +411,17 @@ FormHistory.prototype = {
stmt.executeStep();
this.sendIntNotification("removeEntriesByTimeframe", beginTime, endTime);
} catch (e) {
- this.dbConnection.rollbackTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.rollbackTransaction();
this.log("removeEntriesByTimeframe failed: " + e);
throw e;
} finally {
if (stmt) {
stmt.reset();
}
}
- this.dbConnection.commitTransaction();
+ if (!existingTransactionInProgress)
+ this.dbConnection.commitTransaction();
},
moveToDeletedTable : function moveToDeletedTable(values, params) {

0 comments on commit d30a56a

Please sign in to comment.