mozIStorageConnection
| IID: | ffddc17b-cec3-492c-b13e-d5393c4b1595 |
| Inherits From: | nsISupports |
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.
Constants
| Begins a new transaction with the given type. | ||
| PRInt32 | TRANSACTION_DEFERRED | = 0 |
| PRInt32 | TRANSACTION_IMMEDIATE | = 1 |
| PRInt32 | TRANSACTION_EXCLUSIVE | = 2 |
Properties
readonly PRBool connectionReady
Whether the database is open or not
readonly nsIFile databaseFile
The current database nsIFile. Null if the database connection refers to an in-memory database.
readonly PRInt32 lastError
The last error SQLite error code.
readonly AUTF8String lastErrorString
The last SQLite error as a string (in english, straight from the sqlite library).
readonly PRInt64 lastInsertRowID
LastInsertRowID returns the row ID from the last INSERT operation.
PRInt32 schemaVersion
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.
readonly PRBool transactionInProgress
Returns true if a transaction is active on this connection.
Methods
nsIFile backupDB ( AString fileName , nsIFile parentDirectory )
void beginTransaction ( )
void beginTransactionAs ( PRInt32 transactionType )
void close ( )
void commitTransaction ( )
void createAggregateFunction ( AUTF8String functionName , PRInt32 numArguments , mozIStorageAggregateFunction function )
void createFunction ( AUTF8String functionName , PRInt32 numArguments , mozIStorageFunction function )
mozIStorageStatement createStatement ( AUTF8String SQLStatement )
void createTable ( char* tableName , char* tableSchema )
void executeSimpleSQL ( AUTF8String SQLStatement )
PRBool indexExists ( AUTF8String indexName )
void removeFunction ( AUTF8String functionName )
mozIStorageProgressHandler removeProgressHandler ( )
void rollbackTransaction ( )
mozIStorageProgressHandler setProgressHandler ( PRInt32 granularity , mozIStorageProgressHandler handler )
PRBool tableExists ( AUTF8String tableName )
nsIFile backupDB ( AString fileName , nsIFile parentDirectory )
Copies the current database file to the specified parent directory with the specified file name. If the parent directory is not specified, it places the backup in the same directory as the current file. This function ensures that the file being created is unique.
- Arguments:
- fileName: The name of the new file to create.
- parentDirectory
- Returns:
- nsIFile representing the backup file.
Begin a new transaction. sqlite default transactions are deferred. If a transaction is active, throws an error.
Closes a database connection. C++ callers should simply set the database variable to NULL.
void createAggregateFunction ( AUTF8String functionName , PRInt32 numArguments , mozIStorageAggregateFunction function )
Create a new SQLite aggregate function
- Arguments:
- functionName: The name of aggregate function to create, as seen in SQL.
- numArguments: The number of arguments the function takes. Pass -1 for variable-argument functions.
- function: The instance of mozIStorageAggreagteFunction, which implements the function in question.
void createFunction ( AUTF8String functionName , PRInt32 numArguments , mozIStorageFunction function )
Create a new SQLite function
- Arguments:
- functionName: The name of function to create, as seen in SQL.
- numArguments: The number of arguments the function takes. Pass -1 for variable-argument functions.
- function: The instance of mozIStorageFunction, which implements the function in question.
mozIStorageStatement createStatement ( AUTF8String SQLStatement )
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.
- Arguments:
- SQLStatement: The SQL statement to execute
void createTable ( char* tableName , char* tableSchema )
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.)
- Arguments:
- tableName: the table name to be created, consisting of [A-Za-z0-9_], and beginning with a letter.
- tableSchema: the schema of the table; what would normally go between the parens in a CREATE TABLE statement: e.g., "foo INTEGER, bar STRING".
void executeSimpleSQL ( AUTF8String SQLStatement )
Execute a SQL expression, expecting no arguments.
- Arguments:
- SQLStatement: The SQL statement to execute
PRBool indexExists ( AUTF8String indexName )
Check if the given index exists.
- Arguments:
- indexName: The index to check
void removeFunction ( AUTF8String functionName )
Delete custom SQLite function (simple or aggregate one)
- Arguments:
- functionName: The name of function to remove.
mozIStorageProgressHandler removeProgressHandler ( )
Remove a progress handler.
- Returns:
- previous registered handler.
mozIStorageProgressHandler setProgressHandler ( PRInt32 granularity , mozIStorageProgressHandler handler )
Sets a progress handler. Only one handler can be registered at a time. If you need more than one, you need to chain them yourself.
- Arguments:
- granularity: The number of SQL virtual machine steps between progress handler callbacks.
- handler: The instance of mozIStorageProgressHandler.
- Returns:
- previous registered handler.
PRBool tableExists ( AUTF8String tableName )
Check if the given table exists.
- Arguments:
- tableName: The table to check
References
This interface is the type of the following properties:
nsIDownloadManager.DBConnection
This interface is passed as an argument to the following methods:
mozIStorageProgressHandler.onProgress, mozIStorageStatement.initialize
This interface is returned from the following methods:
mozIStorageService.openDatabase, mozIStorageService.openSpecialDatabase, mozIStorageService.openUnsharedDatabase
Reference documentation is generated from Mozilla's source.
