mozIStorageService
From MDC
This article covers features introduced in Firefox 2
The mozIStorageService interface lets you open a mozIStorageConnection to a SQLite database file.
The connection object must be instantiated from the main thread, even if you intend to use it from other threads. This is the only way to open a database connection.
If you wish to use full-text indexing on a database, you must open it as an unshared database, using the openUnsharedDatabase() method.
Contents |
mozIStorageService is defined in storage/public/mozIStorageService.idl. It is scriptable and
unfrozen (hasn't changed since Mozilla 1.8).
Inherits from: nsISupports
[edit] Method overview
nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName, [optional] in nsIFile aBackupParentDirectory);
|
mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
|
mozIStorageConnection openSpecialDatabase(in string aStorageKey);
|
mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile);
|
[edit] Methods
[edit] backupDatabaseFile()
Makes a backup copy of a database file.
nsIFile backupDatabaseFile( in nsIFile aDBFile, in AString aBackupFileName, [optional] in nsIFile aBackupParentDirectory );
[edit] Parameters
- aDBFile
- The database file to back up.
- aBackupFileName
- The filename to give to the new backup file.
- aBackupParentDirectory
- The directory to put the backup into. If this isn't specified, the backup is placed in the same directory as the original file.
[edit] Return value
An nsIFile object representing the newly-created backup file.
[edit] Remarks
This method ensures that the backup file being created has a unique name.
[edit] openSpecialDatabase()
Opens a connection to a named special database storage that identifies the type of storage requested.
mozIStorageConnection openSpecialDatabase( in string aStorageKey );
[edit] Parameters
- aStorageKey
- A string key identifying the type of storage requested. Valid values are "profile" and "memory".
[edit] Return value
A new mozIStorageConnection providing access to the requested database.
[edit] Exceptions thrown
- NS_ERROR_INVALID_ARG
aStorageKeyis invalid.
[edit] openDatabase()
Opens a database connection to the specified file. After calling this method, you should check the value of mozIStorageConnection::connectionReady to ensure that the database is usable; if that value is false, the database failed to open properly. In that situation, it's recommended that you call mozIStorageService::backupDatabaseFile() to back up the database so that user data isn't lost.
If your database contains virtual tables (for example, for full-text indexes), you must use openUnsharedDatabase() to open it, since those tables aren't compatible with a shared cache. If you use this method to open a database containing virtual tables, it will think the database is corrupted and throw NS_ERROR_FILE_CORRUPTED.
Versions of Firefox prior to 2.0.12 do not support multiple opens of the same database; doing so will corrupt the database file.
mozIStorageConnection openDatabase( in nsIFile aDatabaseFile );
[edit] Parameters
- aDatabaseFile
- An
nsIFileindicating the database file to open.
[edit] Return value
A mozIStorageConnection representing the connection to the opened database file.
[edit] Exceptions thrown
- NS_ERROR_FAILURE
- An error occurred attempting to open the database.
- NS_ERROR_FILE_CORRUPTED
- The database file is corrupted, or contains virtual tables and is not compatible with this method.
- NS_ERROR_OUT_OF_MEMORY
- Allocating a new storage object failed.
[edit] openUnsharedDatabase()
This method was added in Firefox 3.
Opens a database connection to the specified file without using the sqlite shared cache. After calling this method, you should check the value of mozIStorageConnection::connectionReady to ensure that the database is usable; if that value is false, the database failed to open properly. In that situation, it's recommended that you call mozIStorageService::backupDatabaseFile() to back up the database so that user data isn't lost.
Each connection uses its own sqlite cache, which isn't as efficient as using a shared cache, so you should use openDatabase() instead of this method unless you need a feature of sqlite that is incompatible with a shared cache, such a virtual table or full text indexing support.
mozIStorageConnection openUnsharedDatabase( in nsIFile aDatabaseFile );
[edit] Parameters
- aDatabaseFile
- An
nsIFileindicating the database file to open.
[edit] Return value
A mozIStorageConnection representing the connection to the opened database file.
[edit] Exceptions thrown
- NS_ERROR_FAILURE
- An error occurred attempting to open the database.
- NS_ERROR_FILE_CORRUPTED
- The database file is corrupted, or contains virtual tables and is not compatible with this method.
- NS_ERROR_OUT_OF_MEMORY
- Allocating a new storage object failed.
