Confirmed users
595
edits
No edit summary |
|||
| Line 230: | Line 230: | ||
== Asynchronous statements == | == Asynchronous statements == | ||
Asynchronous statements are executed by mozStorage in a separate thread, and they are managed as a FIFO queue. Thanks to the separate threads using such a statement is a good idea, since it won't lock the UI. But at the same time we can't rely on immediate database values, since we have to wait for it to be executed (see [https://developer.mozilla.org/En/MozIStorageStatementCallback mozIStorageStatementCallback]) | |||
To execute a single async statement in Cpp: | |||
<pre> | |||
nsCOMPtr<YourStatementCallback> callback = | |||
new YourStatementCallback(); | |||
// this is needed to cancel a pending statement, we don't use it actually | |||
nsCOMPtr<mozIStoragePendingStatement> canceler; | |||
rv = stmt->ExecuteAsync(callback, getter_AddRefs(canceler)); | |||
NS_ENSURE_SUCCESS(rv, rv); | |||
</pre> | |||
while in JS: | |||
<pre> | |||
var stmt = dbConn.createStatement("UPDATE ...") | |||
dbConn.executeAsync(stmt, mozIStorageStatementCallback_obj); | |||
</pre> | |||
It is also possible to execute multiple async statements at once using database connection executeAsync: | |||
<pre> | |||
let statements = []; | |||
statememnts.push(dbConn.createStatement("UPDATE ...")); | |||
statememnts.push(dbConn.createStatement("UPDATE ...")); | |||
dbConn.executeAsync(statements, statements.length, mozIStorageStatementCallback_obj); | |||
</pre> | |||
== Perf hints == | == Perf hints == | ||