Follow up to bug 451392, add hgToolsTag to older configs
[mozilla-1.9.git] / storage / public / mozIStorageConnection.idl
blob370e005971125b479a5729fcf6ee16d1861ddf52
1 /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Oracle Corporation code.
17 * The Initial Developer of the Original Code is
18 * Oracle Corporation
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
24 * Brett Wilson <brettw@gmail.com>
25 * Shawn Wilsher <me@shawnwilsher.com>
26 * Lev Serebryakov <lev@serebryakov.spb.ru>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include "nsISupports.idl"
44 interface mozIStorageAggregateFunction;
45 interface mozIStorageFunction;
46 interface mozIStorageProgressHandler;
47 interface mozIStorageStatement;
48 interface nsIFile;
50 /**
51 * mozIStorageConnection represents a database connection attached to
52 * a specific file or to the in-memory data storage. It is the
53 * primary interface for interacting with a database, including
54 * creating prepared statements, executing SQL, and examining database
55 * errors.
57 [scriptable, uuid(623f9ddb-434b-4d39-bc2d-1c617da241d0)]
58 interface mozIStorageConnection : nsISupports {
60 * Initialization and status
63 /**
64 * Closes a database connection. C++ callers should simply set the database
65 * variable to NULL.
67 void close();
69 /**
70 * Indicates if the connection is open and ready to use. This will be false
71 * if the connection failed to open, or it has been closed.
73 readonly attribute boolean connectionReady;
75 /**
76 * The current database nsIFile. Null if the database
77 * connection refers to an in-memory database.
79 readonly attribute nsIFile databaseFile;
81 /**
82 * lastInsertRowID returns the row ID from the last INSERT
83 * operation.
85 readonly attribute long long lastInsertRowID;
87 /**
88 * The last error SQLite error code.
90 readonly attribute long lastError;
92 /**
93 * The last SQLite error as a string (in english, straight from the
94 * sqlite library).
96 readonly attribute AUTF8String lastErrorString;
98 /**
99 * The schema version of the database. This should not be used until the
100 * database is ready. The schema will be reported as zero if it is not set.
102 attribute long schemaVersion;
105 * Statement creation
109 * Create a mozIStorageStatement for the given SQL expression. The
110 * expression may use ? to indicate sequential numbered arguments,
111 * ?1, ?2 etc. to indicate specific numbered arguments or :name and
112 * $var to indicate named arguments.
114 * @param aSQLStatement The SQL statement to execute
116 * @returns a new mozIStorageStatement
118 mozIStorageStatement createStatement(in AUTF8String aSQLStatement);
121 * Execute a SQL expression, expecting no arguments.
123 * @param aSQLStatement The SQL statement to execute
125 void executeSimpleSQL(in AUTF8String aSQLStatement);
128 * Check if the given table exists.
130 * @param aTableName The table to check
131 * @returns TRUE if table exists, FALSE otherwise.
133 boolean tableExists(in AUTF8String aTableName);
136 * Check if the given index exists.
138 * @param aIndexName The index to check
139 * @returns TRUE if the index exists, FALSE otherwise.
141 boolean indexExists(in AUTF8String aIndexName);
145 * Transactions
149 * Returns true if a transaction is active on this connection.
151 readonly attribute boolean transactionInProgress;
154 * Begin a new transaction. sqlite default transactions are deferred.
155 * If a transaction is active, throws an error.
157 void beginTransaction();
160 * Begins a new transaction with the given type.
162 const PRInt32 TRANSACTION_DEFERRED = 0;
163 const PRInt32 TRANSACTION_IMMEDIATE = 1;
164 const PRInt32 TRANSACTION_EXCLUSIVE = 2;
165 void beginTransactionAs(in PRInt32 transactionType);
168 * Commits the current transaction. If no transaction is active,
169 * @throws NS_ERROR_STORAGE_NO_TRANSACTION.
171 void commitTransaction();
174 * Rolls back the current transaction. If no transaction is active,
175 * @throws NS_ERROR_STORAGE_NO_TRANSACTION.
177 void rollbackTransaction();
180 * Tables
184 * Create the table with the given name and schema.
186 * If the table already exists, NS_ERROR_FAILURE is thrown.
187 * (XXX at some point in the future it will check if the schema is
188 * the same as what is specified, but that doesn't happen currently.)
190 * @param aTableName the table name to be created, consisting of
191 * [A-Za-z0-9_], and beginning with a letter.
193 * @param aTableSchema the schema of the table; what would normally
194 * go between the parens in a CREATE TABLE statement: e.g., "foo
195 * INTEGER, bar STRING".
197 * @throws NS_ERROR_FAILURE if the table already exists or could not
198 * be created for any other reason.
201 void createTable(in string aTableName,
202 in string aTableSchema);
205 * Functions
209 * Create a new SQLite function
211 * @param aFunctionName The name of function to create, as seen in SQL.
212 * @param aNumArguments The number of arguments the function takes. Pass
213 * -1 for variable-argument functions.
214 * @param aFunction The instance of mozIStorageFunction, which implements
215 * the function in question.
217 void createFunction(in AUTF8String aFunctionName,
218 in long aNumArguments,
219 in mozIStorageFunction aFunction);
222 * Create a new SQLite aggregate function
224 * @param aFunctionName The name of aggregate function to create, as seen
225 * in SQL.
226 * @param aNumArguments The number of arguments the function takes. Pass
227 * -1 for variable-argument functions.
228 * @param aFunction The instance of mozIStorageAggreagteFunction,
229 * which implements the function in question.
231 void createAggregateFunction(in AUTF8String aFunctionName,
232 in long aNumArguments,
233 in mozIStorageAggregateFunction aFunction);
235 * Delete custom SQLite function (simple or aggregate one)
237 * @param aFunctionName The name of function to remove.
239 void removeFunction(in AUTF8String aFunctionName);
242 * Sets a progress handler. Only one handler can be registered at a time.
243 * If you need more than one, you need to chain them yourself.
245 * @param aGranularity The number of SQL virtual machine steps between
246 * progress handler callbacks.
247 * @param aHandler The instance of mozIStorageProgressHandler.
249 * @return previous registered handler.
251 mozIStorageProgressHandler setProgressHandler(in PRInt32 aGranularity,
252 in mozIStorageProgressHandler aHandler);
255 * Remove a progress handler.
257 * @return previous registered handler.
259 mozIStorageProgressHandler removeProgressHandler();