Bug 1450754 [wpt PR 10272] - Fix customElements.upgrade() tests for <template>, a...
[gecko.git] / storage / mozIStorageAsyncConnection.idl
blobdb7c36be7862327a8588210c0d820fa15951c97d
1 /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 interface mozIStorageAggregateFunction;
9 interface mozIStorageCompletionCallback;
10 interface mozIStorageFunction;
11 interface mozIStorageProgressHandler;
12 interface mozIStorageBaseStatement;
13 interface mozIStorageStatement;
14 interface mozIStorageAsyncStatement;
15 interface mozIStorageStatementCallback;
16 interface mozIStoragePendingStatement;
17 interface nsIFile;
19 /**
20 * mozIStorageAsyncConnection represents an asynchronous database
21 * connection attached to a specific file or to an in-memory data
22 * storage. It is the primary interface for interacting with a
23 * database from the main thread, including creating prepared
24 * statements, executing SQL, and examining database errors.
26 [scriptable, uuid(8bfd34d5-4ddf-4e4b-89dd-9b14f33534c6)]
27 interface mozIStorageAsyncConnection : nsISupports {
28 /**
29 * Transaction behavior constants.
31 const int32_t TRANSACTION_DEFAULT = -1;
32 const int32_t TRANSACTION_DEFERRED = 0;
33 const int32_t TRANSACTION_IMMEDIATE = 1;
34 const int32_t TRANSACTION_EXCLUSIVE = 2;
36 /**
37 * The default behavior for all transactions run on this connection. Defaults
38 * to `TRANSACTION_DEFERRED`, and can be overridden for individual
39 * transactions.
41 attribute int32_t defaultTransactionType;
43 /**
44 * Close this database connection, allowing all pending statements
45 * to complete first.
47 * @param aCallback [optional]
48 * A callback that will be notified when the close is completed,
49 * with the following arguments:
50 * - status: the status of the call
51 * - value: |null|
53 * @throws NS_ERROR_NOT_SAME_THREAD
54 * If called on a thread other than the one that opened it. The
55 * callback will not be dispatched.
56 * @throws NS_ERROR_NOT_INITIALIZED
57 * If called on a connection that has already been closed or was
58 * never properly opened. The callback will still be dispatched
59 * to the main thread despite the returned error.
60 * @note If this call should fail, the callback won't be invoked.
62 void asyncClose([optional] in mozIStorageCompletionCallback aCallback);
64 /**
65 * Forcibly closes a database connection synchronously.
66 * This should only be used when it's required to close and replace the
67 * database synchronously to return control to the consumer, for example in
68 * case of a detected corruption on database opening.
69 * Since this spins the events loop, it should be used only in very particular
70 * and rare situations, or it may cause unexpected consequences (crashes).
72 * @throws NS_ERROR_NOT_SAME_THREAD
73 * If called on a thread other than the one that opened it.
75 [noscript] void spinningSynchronousClose();
77 /**
78 * Clone a database and make the clone read only if needed.
79 * SQL Functions and attached on-disk databases are applied to the new clone.
81 * @param aReadOnly
82 * If true, the returned database should be put into read-only mode.
84 * @param aCallback
85 * A callback that will be notified when the operation is complete,
86 * with the following arguments:
87 * - status: the status of the operation
88 * - value: in case of success, an intance of
89 * mozIStorageAsyncConnection cloned from this one.
91 * @throws NS_ERROR_NOT_SAME_THREAD
92 * If is called on a thread other than the one that opened it.
93 * @throws NS_ERROR_UNEXPECTED
94 * If this connection is a memory database.
96 * @note If your connection is already read-only, you will get a read-only
97 * clone.
98 * @note The resulting connection will NOT implement mozIStorageConnection,
99 * it will only implement mozIStorageAsyncConnection.
100 * @note Due to a bug in SQLite, if you use the shared cache
101 * (see mozIStorageService), you end up with the same privileges as the
102 * first connection opened regardless of what is specified in aReadOnly.
103 * @note The following pragmas are copied over to a read-only clone:
104 * - cache_size
105 * - temp_store
106 * The following pragmas are copied over to a writeable clone:
107 * - cache_size
108 * - temp_store
109 * - foreign_keys
110 * - journal_size_limit
111 * - synchronous
112 * - wal_autocheckpoint
113 * All SQL functions are copied over to read-only and writeable clones.
114 * Additionally, all temporary tables, triggers, and views, as well as
115 * any indexes on temporary tables, are copied over to writeable clones.
116 * For temporary tables, only the schemas are copied, not their
117 * contents.
119 void asyncClone(in boolean aReadOnly,
120 in mozIStorageCompletionCallback aCallback);
123 * The current database nsIFile. Null if the database
124 * connection refers to an in-memory database.
126 readonly attribute nsIFile databaseFile;
129 * Causes any pending database operation to abort and return at the first
130 * opportunity.
131 * This can only be used on read-only connections that don't implement
132 * the mozIStorageConnection interface.
133 * @note operations that are nearly complete may still be able to complete.
134 * @throws if used on an unsupported connection type, or a closed connection.
136 void interrupt();
138 //////////////////////////////////////////////////////////////////////////////
139 //// Statement creation
142 * Create an asynchronous statement for the given SQL. An
143 * asynchronous statement can only be used to dispatch asynchronous
144 * requests to the asynchronous execution thread and cannot be used
145 * to take any synchronous actions on the database.
147 * The expression may use ? to indicate sequential numbered arguments,
148 * ?1, ?2 etc. to indicate specific numbered arguments or :name and
149 * $var to indicate named arguments.
151 * @param aSQLStatement
152 * The SQL statement to execute.
153 * @return a new mozIStorageAsyncStatement
154 * @note The statement is created lazily on first execution.
156 mozIStorageAsyncStatement createAsyncStatement(in AUTF8String aSQLStatement);
159 * Execute an array of statements created with this connection using
160 * any currently bound parameters. When the array contains multiple
161 * statements, the execution is wrapped in a single
162 * transaction. These statements can be reused immediately, and
163 * reset does not need to be called.
165 * @param aStatements
166 * The array of statements to execute asynchronously, in the order they
167 * are given in the array.
168 * @param aNumStatements
169 * The number of statements in aStatements.
170 * @param aCallback [optional]
171 * The callback object that will be notified of progress, errors, and
172 * completion.
173 * @return an object that can be used to cancel the statements execution.
175 * @note If you have any custom defined functions, they must be
176 * re-entrant since they can be called on multiple threads.
178 mozIStoragePendingStatement executeAsync(
179 [array, size_is(aNumStatements)] in mozIStorageBaseStatement aStatements,
180 in unsigned long aNumStatements,
181 [optional] in mozIStorageStatementCallback aCallback
185 * Execute asynchronously an SQL expression, expecting no arguments.
187 * @param aSQLStatement
188 * The SQL statement to execute
189 * @param aCallback [optional]
190 * The callback object that will be notified of progress, errors, and
191 * completion.
192 * @return an object that can be used to cancel the statement execution.
194 mozIStoragePendingStatement executeSimpleSQLAsync(
195 in AUTF8String aSQLStatement,
196 [optional] in mozIStorageStatementCallback aCallback);
198 //////////////////////////////////////////////////////////////////////////////
199 //// Functions
202 * Create a new SQL function. If you use your connection on multiple threads,
203 * your function needs to be threadsafe, or it should only be called on one
204 * thread.
206 * @param aFunctionName
207 * The name of function to create, as seen in SQL.
208 * @param aNumArguments
209 * The number of arguments the function takes. Pass -1 for
210 * variable-argument functions.
211 * @param aFunction
212 * The instance of mozIStorageFunction, which implements the function
213 * in question.
215 void createFunction(in AUTF8String aFunctionName,
216 in long aNumArguments,
217 in mozIStorageFunction aFunction);
220 * Create a new SQL aggregate function. If you use your connection on
221 * multiple threads, your function needs to be threadsafe, or it should only
222 * be called on one thread.
224 * @param aFunctionName
225 * The name of aggregate function to create, as seen in SQL.
226 * @param aNumArguments
227 * The number of arguments the function takes. Pass -1 for
228 * variable-argument functions.
229 * @param aFunction
230 * The instance of mozIStorageAggreagteFunction, which implements the
231 * function in question.
233 void createAggregateFunction(in AUTF8String aFunctionName,
234 in long aNumArguments,
235 in mozIStorageAggregateFunction aFunction);
237 * Delete custom SQL function (simple or aggregate one).
239 * @param aFunctionName
240 * The name of function to remove.
242 void removeFunction(in AUTF8String aFunctionName);
245 * Sets a progress handler. Only one handler can be registered at a time.
246 * If you need more than one, you need to chain them yourself. This progress
247 * handler should be threadsafe if you use this connection object on more than
248 * one thread.
250 * @param aGranularity
251 * The number of SQL virtual machine steps between progress handler
252 * callbacks.
253 * @param aHandler
254 * The instance of mozIStorageProgressHandler.
255 * @return previous registered handler.
257 mozIStorageProgressHandler setProgressHandler(in int32_t aGranularity,
258 in mozIStorageProgressHandler aHandler);
261 * Remove a progress handler.
263 * @return previous registered handler.
265 mozIStorageProgressHandler removeProgressHandler();