Blame storage/mozIStorageConnection.idl

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