Esta página está traduciéndose a partir del artículo mozIStorageConnection, razón por la cual puede haber algunos errores sintácticos o partes sin traducir. Puedes colaborar continuando con la traducción
Este artículo cubre características introducidas en Firefox 2
mozIStorageConnection interface represents a database connection attached to a specific file or to in-memory data storage. It is the primary interface for interacting with a database, including creating prepared statements, executing SQL, and examining database errors.
See Storage for an introduction.
mozIStorageConnection is defined in storage/public/mozIStorageConnection.idl
. It is scriptable
and
unfrozen (hasn't changed since Mozilla 1.9)
.
Inherits from: nsISupports
void close();
|
mozIStorageStatement createStatement(in AUTF8String aSQLStatement);
|
void executeSimpleSQL(in AUTF8String aSQLStatement);
|
boolean tableExists(in AUTF8String aTableName);
|
boolean indexExists(in AUTF8String aIndexName);
|
void beginTransaction();
|
void beginTransactionAs(in PRInt32 transactionType);
|
void commitTransaction();
|
void rollbackTransaction();
|
void createTable(in string aTableName, in string aTableSchema);
|
void createFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageFunction aFunction);
|
void createAggregateFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageAggregateFunction aFunction);
|
void removeFunction(in AUTF8String aFunctionName);
|
mozIStorageProgressHandler setProgressHandler(in PRInt32 aGranularity, in mozIStorageProgressHandler aHandler);
|
mozIStorageProgressHandler removeProgressHandler();
|
void preload(); Obsolete
|
| Attribute | Type | Description |
connectionReady
| boolean
| Indicates whether or not the connection is open or ready to use. This is false if the connection failed to open or if it has been closed.
|
databaseFile
| nsIFile
| The current database file. NULL if the database connection refers to an in-memory database.
|
lastInsertRowID
| long long
| The row ID from the last SQL INSERT operation.
|
lastError
| long
| The last sqlite error code that occurred. |
lastErrorString
| AUTF8String
| The English error string reported by the sqlite library for the last sqlite operation. |
schemaVersion
| long
| The schema version of the database. This should not be used until the database is ready. The version will be reported as 0 if not set. since Gecko 1.9 M8 |
transactionInProgress
| boolean
| Returns true if there is a transaction in progress on the database; otherwise returns false.
|
| Constant | Value | Description |
TRANSACTION_DEFERRED
| 0 | Default. The database lock is acquired when needed. |
TRANSACTION_IMMEDIATE
| 1 | Get a read lock on the database immediately. |
TRANSACTION_EXCLUSIVE
| 2 | Get a write lock on the database immediately. |
Closes a database connection. C++ callers should simply set the database variable to NULL. since Gecko 1.9 M8
You need to call finalize() on the statement if you have created one before attempting to close or you will get an NS_ERROR_FILE_IS_LOCKED exception.
void close();
Creates a mozIStorageStatement
for the given SQL expression. The expression may use "?" to indicate sequentially numbered arguments (?1, ?2, etc) or ":name" and "$var" to indicate named arguments.
mozIStorageStatement createStatement( in AUTF8String aSQLStatement );
Executes an SQL expression. By default, it doesn't expect any arguments at all.
void executeSimpleSQL( in AUTF8String aSQLStatement );
This method reports whether the given table exists or not.
boolean tableExists( in AUTF8String aTableName );
This method determines whether or not the given index exists.
boolean indexExists( in AUTF8String aIndexName );
Starts a new transaction. By default, SQLite defers transactions. If a transaction is already active, this method throws an exception.
^
beginTransaction() and related methods is strongly recommended because it stores the transaction state in the connection. Otherwise, the attribute transactionInProgress will have the wrong value.
void beginTransaction();
This method starts a new transaction of the given transaction type.
void beginTransactionAs( in PRInt32 transactionType );
This method rolls back the current transaction. This is essentially an "undo," and returns the database to the state it was in before the transaction began.
void rollbackTransaction();
This method creates a table with the given table name and schema.
^
void createTable( in string aTableName, in string aTableSchema );
CREATE TABLE statement uses. For example: "foo INTEGER, bar STRING".
Creates a new SQLite function. since Gecko 1.9 M8
void createFunction( in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageFunction aFunction );
-1 for variable-argument functions.
mozIStorageFunction
that implements the function.
This method creates a new SQLite aggregate function. since Gecko 1.9 M8
void createAggregateFunction( in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageAggregateFunction aFunction );
-1 for variable-argument functions.
mozIStorageAggregateFunction
that implements the function.
Deletes a custom SQLite function; it works with both standard and aggregate functions. since Gecko 1.9 M8
void removeFunction( in AUTF8String aFunctionName );
This method 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. since Gecko 1.9 M8
mozIStorageProgressHandler setProgressHandler( in PRInt32 aGranularity, in mozIStorageProgressHandler aHandler );
mozIStorageProgressHandler
.
Removes a progress handler. since Gecko 1.9 M8
mozIStorageProgressHandler removeProgressHandler();
Preloads the database cache by loading pages from the start of the database file until the memory cache (the size of which is specified by PRAGMA cache_size=size) is full or the entire file is read.
The cache must be active on the database for this to work. This means that you must have a transaction open on the connection, or have a transaction open on another connection that shares the same pager cache. This cached data will go away when the transaction is closed.
This preload operation can dramatically speed up read operations because the data is loaded as one large block. Normally, pages are read in on demand, which can cause many disk seeks.
void preload();
Page last modified 15:25, 25 May 2008 by HenryGR