12
edits
(→Querying multiple tables: Copy edited (e.g. ref. <https://en.wiktionary.org/wiki/Cartesian_product#Noun>). Expanded.) |
(→Querying Places database examples: Copy edited (e.g. ref. <en.wikipedia.org/wiki/C%2B%2B> and <en.wikipedia.org/wiki/JavaScript>). "information" in an uncountable noun in this context. Expanded.) |
||
| Line 152: | Line 152: | ||
== Querying Places database examples == | == Querying Places database examples == | ||
This section contains an example of how to create a statement to query the Places database. This is for quick reference, further | This section contains an example of how to create a statement to query the Places database. This is for quick reference, and further information is available in the [https://developer.mozilla.org/en/Storage mozStorage developers documentation]. | ||
C++ code: | |||
<pre> | <pre> | ||
nsCOMPtr<mozIStorageStatement> statement; | nsCOMPtr<mozIStorageStatement> statement; | ||
| Line 176: | Line 176: | ||
</pre> | </pre> | ||
JavaScript code: | |||
<pre> | <pre> | ||
var stmt = createStatement( | var stmt = createStatement( | ||
| Line 192: | Line 192: | ||
</pre> | </pre> | ||
Places is using some precompiled statement to speed up the most used queries creation. Those statements are created at Places init, so it's important to | Places is using some precompiled statement to speed up the most used queries creation. Those statements are created at Places init, so it's important to choose which queries need a precompiled statement, since every new addition can hit Ts. Precompiled statements can cause leaks if not correctly destroyed, so when creating a new one, remember to add it to the array in ::FinalizeStatements() method. | ||
When querying with a precompiled statement it is important to use a | When querying with a precompiled statement it is important to use a mozStorageStatementScoper. It will ensure the statement is correctly reset on scope exiting: | ||
<pre> | <pre> | ||
{ // init of scope | { // init of scope | ||
| Line 209: | Line 209: | ||
} | } | ||
} // end of scope | } // end of scope | ||
// precompiled statement gets | // precompiled statement gets reset here | ||
</pre> | </pre> | ||
In JavaScript instead, remember to use statement.reset() when you need to reuse a statement changing parameters, and statement.finalize() when you won't need it anymore. | |||
<pre> | <pre> | ||
var stmt = createStatement( | var stmt = createStatement( | ||
edits