Bug 1073358 - Sqlite.jsm should return some measure of what happened regardless of whether a row handler was used. r=mak

--HG--
extra : transplant_source : %09%E7%2B%D3%9F%93Qzw%C4IL%EC%23g%B9o%DB%0D%DE
This commit is contained in:
Blair McBride 2014-09-27 01:17:00 +12:00
parent 808ed081be
commit 819cb33deb
2 changed files with 26 additions and 6 deletions

View File

@ -579,6 +579,7 @@ ConnectionData.prototype = Object.freeze({
let userCancelled = false;
let errors = [];
let rows = [];
let handledRow = false;
// Don't incur overhead for serializing params unless the messages go
// somewhere.
@ -604,6 +605,8 @@ ConnectionData.prototype = Object.freeze({
continue;
}
handledRow = true;
try {
onRow(row);
} catch (e if e instanceof StopIteration) {
@ -629,8 +632,9 @@ ConnectionData.prototype = Object.freeze({
switch (reason) {
case Ci.mozIStorageStatementCallback.REASON_FINISHED:
// If there is an onRow handler, we always resolve to null.
let result = onRow ? null : rows;
// If there is an onRow handler, we always instead resolve to a
// boolean indicating whether the onRow handler was called or not.
let result = onRow ? handledRow : rows;
deferred.resolve(result);
break;
@ -638,7 +642,7 @@ ConnectionData.prototype = Object.freeze({
// It is not an error if the user explicitly requested cancel via
// the onRow handler.
if (userCancelled) {
let result = onRow ? null : rows;
let result = onRow ? handledRow : rows;
deferred.resolve(result);
} else {
deferred.reject(new Error("Statement was cancelled."));

View File

@ -283,12 +283,13 @@ add_task(function test_on_row_exception_ignored() {
}
let i = 0;
yield c.execute("SELECT * FROM DIRS", null, function onRow(row) {
let hasResult = yield c.execute("SELECT * FROM DIRS", null, function onRow(row) {
i++;
throw new Error("Some silly error.");
});
do_check_eq(hasResult, true);
do_check_eq(i, 10);
yield c.close();
@ -304,7 +305,7 @@ add_task(function test_on_row_stop_iteration() {
}
let i = 0;
let result = yield c.execute("SELECT * FROM dirs", null, function onRow(row) {
let hasResult = yield c.execute("SELECT * FROM dirs", null, function onRow(row) {
i++;
if (i == 5) {
@ -312,12 +313,27 @@ add_task(function test_on_row_stop_iteration() {
}
});
do_check_null(result);
do_check_eq(hasResult, true);
do_check_eq(i, 5);
yield c.close();
});
// Ensure execute resolves to false when no rows are selected.
add_task(function test_on_row_stop_iteration() {
let c = yield getDummyDatabase("no_on_row");
let i = 0;
let hasResult = yield c.execute(`SELECT * FROM dirs WHERE path="nonexistent"`, null, function onRow(row) {
i++;
});
do_check_eq(hasResult, false);
do_check_eq(i, 0);
yield c.close();
});
add_task(function test_invalid_transaction_type() {
let c = yield getDummyDatabase("invalid_transaction_type");