Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Bug 739697 - Don't begin a transaction for formhistory.sqlite if ther…
Browse files Browse the repository at this point in the history
…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
mnoorenberghe committed Apr 6, 2012
1 parent a4e54a7 commit d30a56a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
38 changes: 38 additions & 0 deletions services/sync/tests/unit/test_forms_store.js
Expand Up @@ -85,4 +85,42 @@ function run_test() {
for (let id in store.getAllIDs()) { for (let id in store.getAllIDs()) {
do_throw("Shouldn't get any ids!"); 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!");
}
} }
49 changes: 37 additions & 12 deletions toolkit/components/satchel/nsFormHistory.js
Expand Up @@ -248,9 +248,13 @@ FormHistory.prototype = {
let stmt; let stmt;
let query = "DELETE FROM moz_formhistory WHERE id = :id"; let query = "DELETE FROM moz_formhistory WHERE id = :id";
let params = { id : id }; let params = { id : id };
let existingTransactionInProgress;


try { 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)", { this.moveToDeletedTable("VALUES (:guid, :timeDeleted)", {
guid: guid, guid: guid,
timeDeleted: Date.now() timeDeleted: Date.now()
Expand All @@ -261,15 +265,17 @@ FormHistory.prototype = {
stmt.execute(); stmt.execute();
this.sendStringNotification("removeEntry", name, value, guid); this.sendStringNotification("removeEntry", name, value, guid);
} catch (e) { } catch (e) {
this.dbConnection.rollbackTransaction(); if (!existingTransactionInProgress)
this.dbConnection.rollbackTransaction();
this.log("removeEntry failed: " + e); this.log("removeEntry failed: " + e);
throw e; throw e;
} finally { } finally {
if (stmt) { if (stmt) {
stmt.reset(); stmt.reset();
} }
} }
this.dbConnection.commitTransaction(); if (!existingTransactionInProgress)
this.dbConnection.commitTransaction();
}, },




Expand All @@ -281,9 +287,13 @@ FormHistory.prototype = {
let stmt; let stmt;
let query = "DELETE FROM moz_formhistory WHERE fieldname = :fieldname"; let query = "DELETE FROM moz_formhistory WHERE fieldname = :fieldname";
let params = { fieldname : name }; let params = { fieldname : name };
let existingTransactionInProgress;


try { 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( this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory " + "SELECT guid, :timeDeleted FROM moz_formhistory " +
"WHERE fieldname = :fieldname", { "WHERE fieldname = :fieldname", {
Expand All @@ -295,15 +305,17 @@ FormHistory.prototype = {
stmt.execute(); stmt.execute();
this.sendStringNotification("removeEntriesForName", name); this.sendStringNotification("removeEntriesForName", name);
} catch (e) { } catch (e) {
this.dbConnection.rollbackTransaction(); if (!existingTransactionInProgress)
this.dbConnection.rollbackTransaction();
this.log("removeEntriesForName failed: " + e); this.log("removeEntriesForName failed: " + e);
throw e; throw e;
} finally { } finally {
if (stmt) { if (stmt) {
stmt.reset(); stmt.reset();
} }
} }
this.dbConnection.commitTransaction(); if (!existingTransactionInProgress)
this.dbConnection.commitTransaction();
}, },




Expand All @@ -314,9 +326,13 @@ FormHistory.prototype = {


let stmt; let stmt;
let query = "DELETE FROM moz_formhistory"; let query = "DELETE FROM moz_formhistory";
let existingTransactionInProgress;


try { 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( this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory", { "SELECT guid, :timeDeleted FROM moz_formhistory", {
timeDeleted: Date.now() timeDeleted: Date.now()
Expand All @@ -326,15 +342,17 @@ FormHistory.prototype = {
stmt.execute(); stmt.execute();
this.sendNotification("removeAllEntries", null); this.sendNotification("removeAllEntries", null);
} catch (e) { } catch (e) {
this.dbConnection.rollbackTransaction(); if (!existingTransactionInProgress)
this.dbConnection.rollbackTransaction();
this.log("removeAllEntries failed: " + e); this.log("removeAllEntries failed: " + e);
throw e; throw e;
} finally { } finally {
if (stmt) { if (stmt) {
stmt.reset(); stmt.reset();
} }
} }
this.dbConnection.commitTransaction(); if (!existingTransactionInProgress)
this.dbConnection.commitTransaction();
}, },




Expand Down Expand Up @@ -375,8 +393,13 @@ FormHistory.prototype = {
beginTime : beginTime, beginTime : beginTime,
endTime : endTime endTime : endTime
}; };
let existingTransactionInProgress;

try { 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( this.moveToDeletedTable(
"SELECT guid, :timeDeleted FROM moz_formhistory " + "SELECT guid, :timeDeleted FROM moz_formhistory " +
"WHERE firstUsed >= :beginTime AND firstUsed <= :endTime", { "WHERE firstUsed >= :beginTime AND firstUsed <= :endTime", {
Expand All @@ -388,15 +411,17 @@ FormHistory.prototype = {
stmt.executeStep(); stmt.executeStep();
this.sendIntNotification("removeEntriesByTimeframe", beginTime, endTime); this.sendIntNotification("removeEntriesByTimeframe", beginTime, endTime);
} catch (e) { } catch (e) {
this.dbConnection.rollbackTransaction(); if (!existingTransactionInProgress)
this.dbConnection.rollbackTransaction();
this.log("removeEntriesByTimeframe failed: " + e); this.log("removeEntriesByTimeframe failed: " + e);
throw e; throw e;
} finally { } finally {
if (stmt) { if (stmt) {
stmt.reset(); stmt.reset();
} }
} }
this.dbConnection.commitTransaction(); if (!existingTransactionInProgress)
this.dbConnection.commitTransaction();
}, },


moveToDeletedTable : function moveToDeletedTable(values, params) { moveToDeletedTable : function moveToDeletedTable(values, params) {
Expand Down

0 comments on commit d30a56a

Please sign in to comment.