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: michael@0: interface mozIStorageConnection; michael@0: interface nsIFile; michael@0: interface nsIFileURL; michael@0: interface nsIPropertyBag2; michael@0: interface nsIVariant; michael@0: interface mozIStorageCompletionCallback; michael@0: michael@0: /** michael@0: * The mozIStorageService interface is intended to be implemented by michael@0: * a service that can create storage connections (mozIStorageConnection) michael@0: * to either a well-known profile database or to a specific database file. michael@0: * michael@0: * This is the only way to open a database connection. michael@0: * michael@0: * @note The first reference to mozIStorageService must be made on the main michael@0: * thread. michael@0: */ michael@0: [scriptable, uuid(07b6b2f5-6d97-47b4-9584-e65bc467fe9e)] michael@0: interface mozIStorageService : nsISupports { michael@0: /** michael@0: * Open an asynchronous connection to a database. michael@0: * michael@0: * This method MUST be called from the main thread. The connection object michael@0: * returned by this function is not threadsafe. You MUST use it only from michael@0: * the main thread. michael@0: * michael@0: * If you have more than one connection to a file, you MUST use the EXACT michael@0: * SAME NAME for the file each time, including case. The sqlite code uses michael@0: * a simple string compare to see if there is already a connection. Opening michael@0: * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. michael@0: * michael@0: * @param aDatabaseStore Either a nsIFile representing the file that contains michael@0: * the database or a special string to open a special database. The special michael@0: * string may be: michael@0: * - "memory" to open an in-memory database. michael@0: * michael@0: * @param aOptions A set of options (may be null). Options may contain: michael@0: * - bool shared (defaults to |false|). michael@0: * -- If |true|, opens the database with a shared-cache. The michael@0: * shared-cache mode is more memory-efficient when many michael@0: * connections to the same database are expected, though, the michael@0: * connections will contend the cache resource. In any cases michael@0: * where performance matter, working without a shared-cache will michael@0: * improve concurrency. @see openUnsharedDatabase michael@0: * michael@0: * - int growthIncrement (defaults to none). michael@0: * -- Set the growth increment for the main database. This hints SQLite to michael@0: * grow the database file by a given chunk size and may reduce michael@0: * filesystem fragmentation on large databases. michael@0: * @see mozIStorageConnection::setGrowthIncrement michael@0: * michael@0: * @param aCallback A callback that will receive the result of the operation. michael@0: * In case of error, it may receive as status: michael@0: * - NS_ERROR_OUT_OF_MEMORY if allocating a new storage object fails. michael@0: * - NS_ERROR_FILE_CORRUPTED if the database file is corrupted. michael@0: * In case of success, it receives as argument the new database michael@0: * connection, as an instance of |mozIStorageAsyncConnection|. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if |aDatabaseStore| is neither a file nor michael@0: * one of the special strings understood by this method, or if one of michael@0: * the options passed through |aOptions| does not have the right type. michael@0: * @throws NS_ERROR_NOT_SAME_THREAD if called from a thread other than the michael@0: * main thread. michael@0: */ michael@0: void openAsyncDatabase(in nsIVariant aDatabaseStore, michael@0: [optional] in nsIPropertyBag2 aOptions, michael@0: in mozIStorageCompletionCallback aCallback); michael@0: /** michael@0: * Get a connection to a named special database storage. michael@0: * michael@0: * @param aStorageKey a string key identifying the type of storage michael@0: * requested. Valid values include: "memory". michael@0: * michael@0: * @see openDatabase for restrictions on how database connections may be michael@0: * used. For the profile database, you should only access it from the main michael@0: * thread since other callers may also have connections. michael@0: * michael@0: * @returns a new mozIStorageConnection for the requested michael@0: * storage database. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid. michael@0: */ michael@0: mozIStorageConnection openSpecialDatabase(in string aStorageKey); michael@0: michael@0: /** michael@0: * Open a connection to the specified file. michael@0: * michael@0: * Consumers should check mozIStorageConnection::connectionReady to ensure michael@0: * that they can use the database. If this value is false, it is strongly michael@0: * recommended that the database be backed up with michael@0: * mozIStorageConnection::backupDB so user data is not lost. michael@0: * michael@0: * ========== michael@0: * DANGER michael@0: * ========== michael@0: * michael@0: * If you have more than one connection to a file, you MUST use the EXACT michael@0: * SAME NAME for the file each time, including case. The sqlite code uses michael@0: * a simple string compare to see if there is already a connection. Opening michael@0: * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. michael@0: * michael@0: * The connection object returned by this function is not threadsafe. You must michael@0: * use it only from the thread you created it from. michael@0: * michael@0: * @param aDatabaseFile michael@0: * A nsIFile that represents the database that is to be opened.. michael@0: * michael@0: * @returns a mozIStorageConnection for the requested database file. michael@0: * michael@0: * @throws NS_ERROR_OUT_OF_MEMORY michael@0: * If allocating a new storage object fails. michael@0: * @throws NS_ERROR_FILE_CORRUPTED michael@0: * If the database file is corrupted. michael@0: */ michael@0: mozIStorageConnection openDatabase(in nsIFile aDatabaseFile); michael@0: michael@0: /** michael@0: * Open a connection to the specified file that doesn't share a sqlite cache. michael@0: * michael@0: * Without a shared-cache, each connection uses its own pages cache, which michael@0: * may be memory inefficient with a large number of connections, in such a michael@0: * case so you should use openDatabase instead. On the other side, if cache michael@0: * contention may be an issue, for instance when concurrency is important to michael@0: * ensure responsiveness, using unshared connections may be a performance win. michael@0: * michael@0: * ========== michael@0: * DANGER michael@0: * ========== michael@0: * michael@0: * If you have more than one connection to a file, you MUST use the EXACT michael@0: * SAME NAME for the file each time, including case. The sqlite code uses michael@0: * a simple string compare to see if there is already a connection. Opening michael@0: * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. michael@0: * michael@0: * The connection object returned by this function is not threadsafe. You must michael@0: * use it only from the thread you created it from. michael@0: * michael@0: * @param aDatabaseFile michael@0: * A nsIFile that represents the database that is to be opened. michael@0: * michael@0: * @returns a mozIStorageConnection for the requested database file. michael@0: * michael@0: * @throws NS_ERROR_OUT_OF_MEMORY michael@0: * If allocating a new storage object fails. michael@0: * @throws NS_ERROR_FILE_CORRUPTED michael@0: * If the database file is corrupted. michael@0: */ michael@0: mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile); michael@0: michael@0: /** michael@0: * See openDatabase(). Exactly the same only initialized with a file URL. michael@0: * Custom parameters can be passed to SQLite and VFS implementations through michael@0: * the query part of the URL. michael@0: * michael@0: * @param aURL michael@0: * A nsIFileURL that represents the database that is to be opened. michael@0: */ michael@0: mozIStorageConnection openDatabaseWithFileURL(in nsIFileURL aFileURL); michael@0: michael@0: /* michael@0: * Utilities michael@0: */ michael@0: michael@0: /** michael@0: * Copies the specified database file to the specified parent directory with michael@0: * the specified file name. If the parent directory is not specified, it michael@0: * places the backup in the same directory as the current file. This function michael@0: * ensures that the file being created is unique. michael@0: * michael@0: * @param aDBFile michael@0: * The database file that will be backed up. michael@0: * @param aBackupFileName michael@0: * The name of the new backup file to create. michael@0: * @param [optional] aBackupParentDirectory michael@0: * The directory you'd like the backup file to be placed. michael@0: * @return The nsIFile representing the backup file. michael@0: */ michael@0: nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName, michael@0: [optional] in nsIFile aBackupParentDirectory); michael@0: }; michael@0: michael@0: %{C++ michael@0: michael@0: #define MOZ_STORAGE_MEMORY_STORAGE_KEY "memory" michael@0: michael@0: %}