Closed Bug 1073358 Opened 10 years ago Closed 10 years ago

Sqlite.jsm should return some measure of what happened regardless of whether a row handler was used

Categories

(Toolkit :: General, defect)

defect
Not set
normal
Points:
2

Tracking

()

RESOLVED FIXED
mozilla35
Iteration:
35.2

People

(Reporter: Unfocused, Assigned: Unfocused)

References

Details

(Keywords: dev-doc-complete)

Attachments

(1 file, 1 obsolete file)

When using Sqlite.jsm's execute()/executeCached(), if you pass in a row handler, the promise returned always resolves to null. This is so large result sets aren't kept in memory. However, there are cases where it is useful to get some form of result returned, so you don't need to hook up something special in your row handler to track things. 

In bug 1067899 I have on such example use case.

Returning the entire result set is obviously bad. However, returning the number of rows is lightweight and gives adequate information about what happened - without needing to hook up some tracking in your row handler.
Marco: This is blocking bug 1067899. It's smallish, but it should be done in isolation.
Assignee: nobody → bmcbride
Status: NEW → ASSIGNED
Points: --- → 2
Flags: qe-verify-
Flags: needinfo?(mmucci)
Flags: firefox-backlog+
Attached patch Patch v1 (obsolete) — Splinter Review
Attachment #8495691 - Flags: review?(mak77)
Added to IT 35.2
Iteration: --- → 35.2
Flags: needinfo?(mmucci)
Comment on attachment 8495691 [details] [diff] [review]
Patch v1

Review of attachment 8495691 [details] [diff] [review]:
-----------------------------------------------------------------

I think it's confusing and not very useful to return the number of rows, because if one is executing an update or a delete, he might exect it to return the number of affected rows, and we don't have that information at hand.

My idea is that instead we return a bool, stating whether the onrow handler has been called at least once.

::: toolkit/modules/Sqlite.jsm
@@ +631,5 @@
>          self._pendingStatements.delete(index);
>  
>          switch (reason) {
>            case Ci.mozIStorageStatementCallback.REASON_FINISHED:
>              // If there is an onRow handler, we always resolve to null.

please remember to update this comment
Attachment #8495691 - Flags: review?(mak77) → review-
please also update here

https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Sqlite.jsm

"If onRow is specified, the returned promise will be resolved with null. Else, the resolved value will be an array of mozIStorageRow."

should just take a few seconds.
Attached patch Patch v1.1Splinter Review
Attachment #8495691 - Attachment is obsolete: true
Attachment #8495913 - Flags: review?(mak77)
Comment on attachment 8495913 [details] [diff] [review]
Patch v1.1

Review of attachment 8495913 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/modules/tests/xpcshell/test_sqlite.js
@@ +282,5 @@
>      yield c.executeCached(sql, ["dir" + i]);
>    }
>  
>    let i = 0;
> +  let result = yield c.execute("SELECT * FROM DIRS", null, function onRow(row) {

nit: hasResult

@@ +317,3 @@
>    do_check_eq(i, 5);
>  
>    yield c.close();

could you please add a simple test that checks also the false case? like a SELECT * FROM dirs WHERE path = "nonexistent"?
Attachment #8495913 - Flags: review?(mak77) → review+
https://hg.mozilla.org/mozilla-central/rev/6351ff630f1a
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: