summaryrefslogtreecommitdiffstats
path: root/storage/mozIStorageConnection.idl
blob: 34217b5f429d2e4c42e0eb8edf746a282bdcf7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "mozIStorageAsyncConnection.idl"

%{C++
namespace mozilla::dom::quota {
class QuotaObject;
}

namespace mozilla::storage {
class SQLiteMutex;
class SQLiteMutexAutoLock;
}

%}

[ptr] native QuotaObject(mozilla::dom::quota::QuotaObject);
native SQLiteMutex(mozilla::storage::SQLiteMutex&);
native SQLiteMutexAutoLock(const mozilla::storage::SQLiteMutexAutoLock&);

interface mozIStorageAggregateFunction;
interface mozIStorageCompletionCallback;
interface mozIStorageFunction;
interface mozIStorageProgressHandler;
interface mozIStorageBaseStatement;
interface mozIStorageStatement;
interface mozIStorageAsyncStatement;
interface mozIStorageStatementCallback;
interface mozIStoragePendingStatement;
interface nsIFile;

/**
 * mozIStorageConnection represents a database connection attached to
 * a specific file or to the in-memory data storage.  It is the
 * primary interface for interacting with a database, including
 * creating prepared statements, executing SQL, and examining database
 * errors.
 *
 * @note From the main thread, you should rather use mozIStorageAsyncConnection.
 *
 * @threadsafe
 */
[scriptable, builtinclass, uuid(4aa2ac47-8d24-4004-9b31-ec0bd85f0cc3)]
interface mozIStorageConnection : mozIStorageAsyncConnection {
  /**
   * Closes a database connection.  Callers must finalize all statements created
   * for this connection prior to calling this method.  It is illegal to use
   * call this method if any asynchronous statements have been executed on this
   * connection.
   *
   * @throws NS_ERROR_UNEXPECTED
   *         If any statement has been executed asynchronously on this object.
   * @throws NS_ERROR_UNEXPECTED
   *         If is called on a thread other than the one that opened it.
   */
  void close();

  /**
   * Clones a database connection and makes the clone read only if needed.
   * SQL Functions and attached on-disk databases are applied to the new clone.
   *
   * @param aReadOnly
   *        If true, the returned database should be put into read-only mode.
   *        Defaults to false.
   * @return the cloned database connection.
   *
   * @throws NS_ERROR_UNEXPECTED
   *         If this connection is a memory database.
   * @note If your connection is already read-only, you will get a read-only
   *       clone.
   * @note Due to a bug in SQLite, if you use the shared cache (openDatabase),
   *       you end up with the same privileges as the first connection opened
   *       regardless of what is specified in aReadOnly.
   * @note The following pragmas are copied over to a read-only clone:
   *        - cache_size
   *        - temp_store
   *       The following pragmas are copied over to a writeable clone:
   *        - cache_size
   *        - temp_store
   *        - foreign_keys
   *        - journal_size_limit
   *        - synchronous
   *        - wal_autocheckpoint
   *       All SQL functions are copied over to read-only and writeable clones.
   *       Additionally, all temporary tables, triggers, and views, as well as
   *       any indexes on temporary tables, are copied over to writeable clones.
   *       For temporary tables, only the schemas are copied, not their
   *       contents.
   *
   */
  mozIStorageConnection clone([optional] in boolean aReadOnly);

  /**
   * The default size for SQLite database pages used by mozStorage for new
   * databases.
   */
  readonly attribute long defaultPageSize;

  /**
   * Indicates if the connection is open and ready to use.  This will be false
   * if the connection failed to open, or it has been closed.
   */
  readonly attribute boolean connectionReady;

  /**
   * lastInsertRowID returns the row ID from the last INSERT
   * operation.
   */
  readonly attribute long long lastInsertRowID;

  /**
   * affectedRows returns the number of database rows that were changed or
   * inserted or deleted by last operation.
   */
  readonly attribute long affectedRows;

  /**
   * The last error SQLite error code.
   */
  readonly attribute long lastError;

  /**
   * The last SQLite error as a string (in english, straight from the
   * sqlite library).
   */
  readonly attribute AUTF8String lastErrorString;

  /**
   * The schema version of the database.  This should not be used until the
   * database is ready.  The schema will be reported as zero if it is not set.
   */
  attribute long schemaVersion;

  //////////////////////////////////////////////////////////////////////////////
  //// Statement creation

  /**
   * Create a mozIStorageStatement for the given SQL expression.  The
   * expression may use ? to indicate sequential numbered arguments,
   * ?1, ?2 etc. to indicate specific numbered arguments or :name and
   * $var to indicate named arguments.
   *
   * @param aSQLStatement
   *        The SQL statement to execute.
   * @return a new mozIStorageStatement
   */
  mozIStorageStatement createStatement(in AUTF8String aSQLStatement);

  /**
   * Execute a SQL expression, expecting no arguments.
   *
   * @param aSQLStatement  The SQL statement to execute
   */
  void executeSimpleSQL(in AUTF8String aSQLStatement);

  /**
   * Check if the given table exists.
   *
   * @param aTableName
   *        The table to check
   * @return TRUE if table exists, FALSE otherwise.
   */
  boolean tableExists(in AUTF8String aTableName);

  /**
   * Check if the given index exists.
   *
   * @param aIndexName   The index to check
   * @return TRUE if the index exists, FALSE otherwise.
   */
  boolean indexExists(in AUTF8String aIndexName);

  //////////////////////////////////////////////////////////////////////////////
  //// Transactions

  /**
   * Begin a new transaction. If a transaction is active, throws an error.
   */
  void beginTransaction();

  /**
   * Commits the current transaction.  If no transaction is active,
   * @throws NS_ERROR_UNEXPECTED.
   * @throws NS_ERROR_NOT_INITIALIZED.
   */
  void commitTransaction();

  /**
   * Rolls back the current transaction.  If no transaction is active,
   * @throws NS_ERROR_UNEXPECTED.
   * @throws NS_ERROR_NOT_INITIALIZED.
   */
  void rollbackTransaction();

  //////////////////////////////////////////////////////////////////////////////
  //// Tables

  /**
   * Create the table with the given name and schema.
   *
   * If the table already exists, NS_ERROR_FAILURE is thrown.
   * (XXX at some point in the future it will check if the schema is
   * the same as what is specified, but that doesn't happen currently.)
   *
   * @param aTableName
   *        The table name to be created, consisting of [A-Za-z0-9_], and
   *        beginning with a letter.
   * @param aTableSchema
   *        The schema of the table; what would normally go between the parens
   *        in a CREATE TABLE statement: e.g., "foo  INTEGER, bar STRING".
   *
   * @throws NS_ERROR_FAILURE
   *         If the table already exists or could not be created for any other
   *         reason.
   */
  void createTable(in string aTableName,
                   in string aTableSchema);

  /**
   * Controls SQLITE_FCNTL_CHUNK_SIZE setting in sqlite. This helps avoid fragmentation
   * by growing/shrinking the database file in SQLITE_FCNTL_CHUNK_SIZE increments. To
   * conserve memory on systems short on storage space, this function will have no effect
   * on mobile devices or if less than 500MiB of space is left available.
   *
   * @param aIncrement
   *        The database file will grow in multiples of chunkSize.
   * @param aDatabaseName
   *        Sqlite database name. "" means pass NULL for zDbName to sqlite3_file_control.
   *        See http://sqlite.org/c3ref/file_control.html for more details.
   * @throws NS_ERROR_FILE_TOO_BIG
   *         If the system is short on storage space.
   */
  void setGrowthIncrement(in int32_t aIncrement, in AUTF8String aDatabaseName);

  /**
   * Enable a predefined virtual table implementation.
   *
   * @param aModuleName
   *        The module to enable. Only "filesystem" is currently supported.
   *
   * @throws NS_ERROR_FAILURE
   *         For unknown module names.
   */
  [noscript] void enableModule(in ACString aModuleName);

  /**
   * Get quota objects.
   *
   * @param[out] aDatabaseQuotaObject
   *             The QuotaObject associated with the database file.
   * @param[out] aJournalQuotaObject
   *             The QuotaObject associated with the journal file.
   *
   * @throws NS_ERROR_NOT_INITIALIZED.
   */
  [noscript] void getQuotaObjects(out QuotaObject aDatabaseQuotaObject,
                                  out QuotaObject aJournalQuotaObject);

  /**
   * The mutex used for protection of operations (BEGIN/COMMIT/ROLLBACK) in
   * mozStorageTransaction. The lock must be held in a way that spans whole
   * operation, not just when accessing the nesting level.
   */
  [notxpcom, nostdcall] readonly attribute SQLiteMutex sharedDBMutex;

  /**
   * Helper methods for managing the transaction nesting level. The methods
   * must be called with a proof of lock. Currently only used by
   * mozStorageTransaction.
   */
  [notxpcom, nostdcall] unsigned long getTransactionNestingLevel(
      in SQLiteMutexAutoLock aProofOfLock);

  [notxpcom, nostdcall] unsigned long increaseTransactionNestingLevel(
      in SQLiteMutexAutoLock aProofOfLock);

  [notxpcom, nostdcall] unsigned long decreaseTransactionNestingLevel(
      in SQLiteMutexAutoLock aProofOfLock);
};