Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It'll be faster if you pull the <code>createStatement</code> out of the loop, and reuse it, rebinding the parameters each time. The <a href="https://developer.mozilla.org/en/Storage" rel="nofollow">docs for storage</a> say: "Note: If you need to execute a statement multiple times, caching the result of createStatement will give you a noticeable performance improvement because the SQL query does not need to be parsed each time."</p> <p>So instead of:</p> <pre><code>for (var i = 0; i &lt; anchors.length; i++) { var statement = conn.createStatement("select * from links where url=?1"); statement.bindStringParameter(0, anchors[i].href); // ... do stuff with results </code></pre> <p>write:</p> <pre><code>var statement = conn.createStatement("select * from links where url=?1"); for (var i = 0; i &lt; anchors.length; i++) { statement.bindStringParameter(0, anchors[i].href); // ... do stuff with results </code></pre> <p>Edit: Also, if you're using a recent Firefox, you can use their asynchronous API to avoid delaying the UI. Instead of calling <code>executeStep</code>, use <a href="https://developer.mozilla.org/en/mozIStorageStatement#executeAsync%28%29" rel="nofollow">executeAsync</a> instead.</p> <pre><code>statement.executeAsync({ handleResult: function(aResultSet) { // ... do stuff with results }, handleError: function(aError) { print("Error: " + aError.message); }, handleCompletion: function(aReason) { if (aReason != Components.interfaces.mozIStorageStatementCallback.REASON_FINISHED) print("Query canceled or aborted!"); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload