michael@0: /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: #include "mozIStorageAsyncConnection.idl" michael@0: michael@0: interface mozIStorageAggregateFunction; michael@0: interface mozIStorageCompletionCallback; michael@0: interface mozIStorageFunction; michael@0: interface mozIStorageProgressHandler; michael@0: interface mozIStorageBaseStatement; michael@0: interface mozIStorageStatement; michael@0: interface mozIStorageAsyncStatement; michael@0: interface mozIStorageStatementCallback; michael@0: interface mozIStoragePendingStatement; michael@0: interface nsIFile; michael@0: michael@0: /** michael@0: * mozIStorageConnection represents a database connection attached to michael@0: * a specific file or to the in-memory data storage. It is the michael@0: * primary interface for interacting with a database, including michael@0: * creating prepared statements, executing SQL, and examining database michael@0: * errors. michael@0: * michael@0: * @note From the main thread, you should rather use mozIStorageAsyncConnection. michael@0: * michael@0: * @threadsafe michael@0: */ michael@0: [scriptable, uuid(4aa2ac47-8d24-4004-9b31-ec0bd85f0cc3)] michael@0: interface mozIStorageConnection : mozIStorageAsyncConnection { michael@0: /** michael@0: * Closes a database connection. Callers must finalize all statements created michael@0: * for this connection prior to calling this method. It is illegal to use michael@0: * call this method if any asynchronous statements have been executed on this michael@0: * connection. michael@0: * michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * If any statement has been executed asynchronously on this object. michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * If is called on a thread other than the one that opened it. michael@0: */ michael@0: void close(); michael@0: michael@0: /** michael@0: * Clones a database connection and makes the clone read only if needed. michael@0: * michael@0: * @param aReadOnly michael@0: * If true, the returned database should be put into read-only mode. michael@0: * Defaults to false. michael@0: * @return the cloned database connection. michael@0: * michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * If this connection is a memory database. michael@0: * @note If your connection is already read-only, you will get a read-only michael@0: * clone. michael@0: * @note Due to a bug in SQLite, if you use the shared cache (openDatabase), michael@0: * you end up with the same privileges as the first connection opened michael@0: * regardless of what is specified in aReadOnly. michael@0: * @note The following pragmas are copied over to a read-only clone: michael@0: * - cache_size michael@0: * - temp_store michael@0: * The following pragmas are copied over to a writeable clone: michael@0: * - cache_size michael@0: * - temp_store michael@0: * - foreign_keys michael@0: * - journal_size_limit michael@0: * - synchronous michael@0: * - wal_autocheckpoint michael@0: * michael@0: */ michael@0: mozIStorageConnection clone([optional] in boolean aReadOnly); michael@0: michael@0: /** michael@0: * The default size for SQLite database pages used by mozStorage for new michael@0: * databases. michael@0: */ michael@0: readonly attribute long defaultPageSize; michael@0: michael@0: /** michael@0: * Indicates if the connection is open and ready to use. This will be false michael@0: * if the connection failed to open, or it has been closed. michael@0: */ michael@0: readonly attribute boolean connectionReady; michael@0: michael@0: /** michael@0: * lastInsertRowID returns the row ID from the last INSERT michael@0: * operation. michael@0: */ michael@0: readonly attribute long long lastInsertRowID; michael@0: michael@0: /** michael@0: * affectedRows returns the number of database rows that were changed or michael@0: * inserted or deleted by last operation. michael@0: */ michael@0: readonly attribute long affectedRows; michael@0: michael@0: /** michael@0: * The last error SQLite error code. michael@0: */ michael@0: readonly attribute long lastError; michael@0: michael@0: /** michael@0: * The last SQLite error as a string (in english, straight from the michael@0: * sqlite library). michael@0: */ michael@0: readonly attribute AUTF8String lastErrorString; michael@0: michael@0: /** michael@0: * The schema version of the database. This should not be used until the michael@0: * database is ready. The schema will be reported as zero if it is not set. michael@0: */ michael@0: attribute long schemaVersion; michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Statement creation michael@0: michael@0: /** michael@0: * Create a mozIStorageStatement for the given SQL expression. The michael@0: * expression may use ? to indicate sequential numbered arguments, michael@0: * ?1, ?2 etc. to indicate specific numbered arguments or :name and michael@0: * $var to indicate named arguments. michael@0: * michael@0: * @param aSQLStatement michael@0: * The SQL statement to execute. michael@0: * @return a new mozIStorageStatement michael@0: */ michael@0: mozIStorageStatement createStatement(in AUTF8String aSQLStatement); michael@0: michael@0: /** michael@0: * Execute a SQL expression, expecting no arguments. michael@0: * michael@0: * @param aSQLStatement The SQL statement to execute michael@0: */ michael@0: void executeSimpleSQL(in AUTF8String aSQLStatement); michael@0: michael@0: /** michael@0: * Check if the given table exists. michael@0: * michael@0: * @param aTableName michael@0: * The table to check michael@0: * @return TRUE if table exists, FALSE otherwise. michael@0: */ michael@0: boolean tableExists(in AUTF8String aTableName); michael@0: michael@0: /** michael@0: * Check if the given index exists. michael@0: * michael@0: * @param aIndexName The index to check michael@0: * @return TRUE if the index exists, FALSE otherwise. michael@0: */ michael@0: boolean indexExists(in AUTF8String aIndexName); michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Transactions michael@0: michael@0: /** michael@0: * Returns true if a transaction is active on this connection. michael@0: */ michael@0: readonly attribute boolean transactionInProgress; michael@0: michael@0: /** michael@0: * Begin a new transaction. sqlite default transactions are deferred. michael@0: * If a transaction is active, throws an error. michael@0: */ michael@0: void beginTransaction(); michael@0: michael@0: /** michael@0: * Begins a new transaction with the given type. michael@0: */ michael@0: const int32_t TRANSACTION_DEFERRED = 0; michael@0: const int32_t TRANSACTION_IMMEDIATE = 1; michael@0: const int32_t TRANSACTION_EXCLUSIVE = 2; michael@0: void beginTransactionAs(in int32_t transactionType); michael@0: michael@0: /** michael@0: * Commits the current transaction. If no transaction is active, michael@0: * @throws NS_ERROR_UNEXPECTED. michael@0: * @throws NS_ERROR_NOT_INITIALIZED. michael@0: */ michael@0: void commitTransaction(); michael@0: michael@0: /** michael@0: * Rolls back the current transaction. If no transaction is active, michael@0: * @throws NS_ERROR_UNEXPECTED. michael@0: * @throws NS_ERROR_NOT_INITIALIZED. michael@0: */ michael@0: void rollbackTransaction(); michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Tables michael@0: michael@0: /** michael@0: * Create the table with the given name and schema. michael@0: * michael@0: * If the table already exists, NS_ERROR_FAILURE is thrown. michael@0: * (XXX at some point in the future it will check if the schema is michael@0: * the same as what is specified, but that doesn't happen currently.) michael@0: * michael@0: * @param aTableName michael@0: * The table name to be created, consisting of [A-Za-z0-9_], and michael@0: * beginning with a letter. michael@0: * @param aTableSchema michael@0: * The schema of the table; what would normally go between the parens michael@0: * in a CREATE TABLE statement: e.g., "foo INTEGER, bar STRING". michael@0: * michael@0: * @throws NS_ERROR_FAILURE michael@0: * If the table already exists or could not be created for any other michael@0: * reason. michael@0: */ michael@0: void createTable(in string aTableName, michael@0: in string aTableSchema); michael@0: michael@0: /** michael@0: * Controls SQLITE_FCNTL_CHUNK_SIZE setting in sqlite. This helps avoid fragmentation michael@0: * by growing/shrinking the database file in SQLITE_FCNTL_CHUNK_SIZE increments. To michael@0: * conserve memory on systems short on storage space, this function will have no effect michael@0: * on mobile devices or if less than 500MiB of space is left available. michael@0: * michael@0: * @param aIncrement michael@0: * The database file will grow in multiples of chunkSize. michael@0: * @param aDatabaseName michael@0: * Sqlite database name. "" means pass NULL for zDbName to sqlite3_file_control. michael@0: * See http://sqlite.org/c3ref/file_control.html for more details. michael@0: * @throws NS_ERROR_FILE_TOO_BIG michael@0: * If the system is short on storage space. michael@0: */ michael@0: void setGrowthIncrement(in int32_t aIncrement, in AUTF8String aDatabaseName); michael@0: michael@0: /** michael@0: * Enable a predefined virtual table implementation. michael@0: * michael@0: * @param aModuleName michael@0: * The module to enable. Only "filesystem" is currently supported. michael@0: * michael@0: * @throws NS_ERROR_FAILURE michael@0: * For unknown module names. michael@0: */ michael@0: [noscript] void enableModule(in ACString aModuleName); michael@0: };