Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / storage / mozIStorageConnection.idl
blob34217b5f429d2e4c42e0eb8edf746a282bdcf7bc
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"
7 #include "mozIStorageAsyncConnection.idl"
9 %{C++
10 namespace mozilla::dom::quota {
11 class QuotaObject;
14 namespace mozilla::storage {
15 class SQLiteMutex;
16 class SQLiteMutexAutoLock;
21 [ptr] native QuotaObject(mozilla::dom::quota::QuotaObject);
22 native SQLiteMutex(mozilla::storage::SQLiteMutex&);
23 native SQLiteMutexAutoLock(const mozilla::storage::SQLiteMutexAutoLock&);
25 interface mozIStorageAggregateFunction;
26 interface mozIStorageCompletionCallback;
27 interface mozIStorageFunction;
28 interface mozIStorageProgressHandler;
29 interface mozIStorageBaseStatement;
30 interface mozIStorageStatement;
31 interface mozIStorageAsyncStatement;
32 interface mozIStorageStatementCallback;
33 interface mozIStoragePendingStatement;
34 interface nsIFile;
36 /**
37 * mozIStorageConnection represents a database connection attached to
38 * a specific file or to the in-memory data storage. It is the
39 * primary interface for interacting with a database, including
40 * creating prepared statements, executing SQL, and examining database
41 * errors.
43 * @note From the main thread, you should rather use mozIStorageAsyncConnection.
45 * @threadsafe
47 [scriptable, builtinclass, uuid(4aa2ac47-8d24-4004-9b31-ec0bd85f0cc3)]
48 interface mozIStorageConnection : mozIStorageAsyncConnection {
49 /**
50 * Closes a database connection. Callers must finalize all statements created
51 * for this connection prior to calling this method. It is illegal to use
52 * call this method if any asynchronous statements have been executed on this
53 * connection.
55 * @throws NS_ERROR_UNEXPECTED
56 * If any statement has been executed asynchronously on this object.
57 * @throws NS_ERROR_UNEXPECTED
58 * If is called on a thread other than the one that opened it.
60 void close();
62 /**
63 * Clones a database connection and makes the clone read only if needed.
64 * SQL Functions and attached on-disk databases are applied to the new clone.
66 * @param aReadOnly
67 * If true, the returned database should be put into read-only mode.
68 * Defaults to false.
69 * @return the cloned database connection.
71 * @throws NS_ERROR_UNEXPECTED
72 * If this connection is a memory database.
73 * @note If your connection is already read-only, you will get a read-only
74 * clone.
75 * @note Due to a bug in SQLite, if you use the shared cache (openDatabase),
76 * you end up with the same privileges as the first connection opened
77 * regardless of what is specified in aReadOnly.
78 * @note The following pragmas are copied over to a read-only clone:
79 * - cache_size
80 * - temp_store
81 * The following pragmas are copied over to a writeable clone:
82 * - cache_size
83 * - temp_store
84 * - foreign_keys
85 * - journal_size_limit
86 * - synchronous
87 * - wal_autocheckpoint
88 * All SQL functions are copied over to read-only and writeable clones.
89 * Additionally, all temporary tables, triggers, and views, as well as
90 * any indexes on temporary tables, are copied over to writeable clones.
91 * For temporary tables, only the schemas are copied, not their
92 * contents.
95 mozIStorageConnection clone([optional] in boolean aReadOnly);
97 /**
98 * The default size for SQLite database pages used by mozStorage for new
99 * databases.
101 readonly attribute long defaultPageSize;
104 * Indicates if the connection is open and ready to use. This will be false
105 * if the connection failed to open, or it has been closed.
107 readonly attribute boolean connectionReady;
110 * lastInsertRowID returns the row ID from the last INSERT
111 * operation.
113 readonly attribute long long lastInsertRowID;
116 * affectedRows returns the number of database rows that were changed or
117 * inserted or deleted by last operation.
119 readonly attribute long affectedRows;
122 * The last error SQLite error code.
124 readonly attribute long lastError;
127 * The last SQLite error as a string (in english, straight from the
128 * sqlite library).
130 readonly attribute AUTF8String lastErrorString;
133 * The schema version of the database. This should not be used until the
134 * database is ready. The schema will be reported as zero if it is not set.
136 attribute long schemaVersion;
138 //////////////////////////////////////////////////////////////////////////////
139 //// Statement creation
142 * Create a mozIStorageStatement for the given SQL expression. The
143 * expression may use ? to indicate sequential numbered arguments,
144 * ?1, ?2 etc. to indicate specific numbered arguments or :name and
145 * $var to indicate named arguments.
147 * @param aSQLStatement
148 * The SQL statement to execute.
149 * @return a new mozIStorageStatement
151 mozIStorageStatement createStatement(in AUTF8String aSQLStatement);
154 * Execute a SQL expression, expecting no arguments.
156 * @param aSQLStatement The SQL statement to execute
158 void executeSimpleSQL(in AUTF8String aSQLStatement);
161 * Check if the given table exists.
163 * @param aTableName
164 * The table to check
165 * @return TRUE if table exists, FALSE otherwise.
167 boolean tableExists(in AUTF8String aTableName);
170 * Check if the given index exists.
172 * @param aIndexName The index to check
173 * @return TRUE if the index exists, FALSE otherwise.
175 boolean indexExists(in AUTF8String aIndexName);
177 //////////////////////////////////////////////////////////////////////////////
178 //// Transactions
181 * Begin a new transaction. If a transaction is active, throws an error.
183 void beginTransaction();
186 * Commits the current transaction. If no transaction is active,
187 * @throws NS_ERROR_UNEXPECTED.
188 * @throws NS_ERROR_NOT_INITIALIZED.
190 void commitTransaction();
193 * Rolls back the current transaction. If no transaction is active,
194 * @throws NS_ERROR_UNEXPECTED.
195 * @throws NS_ERROR_NOT_INITIALIZED.
197 void rollbackTransaction();
199 //////////////////////////////////////////////////////////////////////////////
200 //// Tables
203 * Create the table with the given name and schema.
205 * If the table already exists, NS_ERROR_FAILURE is thrown.
206 * (XXX at some point in the future it will check if the schema is
207 * the same as what is specified, but that doesn't happen currently.)
209 * @param aTableName
210 * The table name to be created, consisting of [A-Za-z0-9_], and
211 * beginning with a letter.
212 * @param aTableSchema
213 * The schema of the table; what would normally go between the parens
214 * in a CREATE TABLE statement: e.g., "foo INTEGER, bar STRING".
216 * @throws NS_ERROR_FAILURE
217 * If the table already exists or could not be created for any other
218 * reason.
220 void createTable(in string aTableName,
221 in string aTableSchema);
224 * Controls SQLITE_FCNTL_CHUNK_SIZE setting in sqlite. This helps avoid fragmentation
225 * by growing/shrinking the database file in SQLITE_FCNTL_CHUNK_SIZE increments. To
226 * conserve memory on systems short on storage space, this function will have no effect
227 * on mobile devices or if less than 500MiB of space is left available.
229 * @param aIncrement
230 * The database file will grow in multiples of chunkSize.
231 * @param aDatabaseName
232 * Sqlite database name. "" means pass NULL for zDbName to sqlite3_file_control.
233 * See http://sqlite.org/c3ref/file_control.html for more details.
234 * @throws NS_ERROR_FILE_TOO_BIG
235 * If the system is short on storage space.
237 void setGrowthIncrement(in int32_t aIncrement, in AUTF8String aDatabaseName);
240 * Enable a predefined virtual table implementation.
242 * @param aModuleName
243 * The module to enable. Only "filesystem" is currently supported.
245 * @throws NS_ERROR_FAILURE
246 * For unknown module names.
248 [noscript] void enableModule(in ACString aModuleName);
251 * Get quota objects.
253 * @param[out] aDatabaseQuotaObject
254 * The QuotaObject associated with the database file.
255 * @param[out] aJournalQuotaObject
256 * The QuotaObject associated with the journal file.
258 * @throws NS_ERROR_NOT_INITIALIZED.
260 [noscript] void getQuotaObjects(out QuotaObject aDatabaseQuotaObject,
261 out QuotaObject aJournalQuotaObject);
264 * The mutex used for protection of operations (BEGIN/COMMIT/ROLLBACK) in
265 * mozStorageTransaction. The lock must be held in a way that spans whole
266 * operation, not just when accessing the nesting level.
268 [notxpcom, nostdcall] readonly attribute SQLiteMutex sharedDBMutex;
271 * Helper methods for managing the transaction nesting level. The methods
272 * must be called with a proof of lock. Currently only used by
273 * mozStorageTransaction.
275 [notxpcom, nostdcall] unsigned long getTransactionNestingLevel(
276 in SQLiteMutexAutoLock aProofOfLock);
278 [notxpcom, nostdcall] unsigned long increaseTransactionNestingLevel(
279 in SQLiteMutexAutoLock aProofOfLock);
281 [notxpcom, nostdcall] unsigned long decreaseTransactionNestingLevel(
282 in SQLiteMutexAutoLock aProofOfLock);