From df10e47ecbf8a03bc86567d49571323cf38543d0 Mon Sep 17 00:00:00 2001 From: "vladimir%pobox.com" Date: Tue, 15 Nov 2005 00:35:50 +0000 Subject: [PATCH] b=273050, storage module interface review, r=darin git-svn-id: svn://10.0.0.236/trunk@184622 18797224-902f-48f8-a5cc-f745e15eee43 --- .../providers/storage/calStorageCalendar.js | 4 +- .../storage/public/mozIStorageConnection.idl | 89 +++-- .../storage/public/mozIStorageFunction.idl | 7 +- mozilla/storage/public/mozIStorageService.idl | 37 +- .../storage/public/mozIStorageStatement.idl | 83 +++-- .../public/mozIStorageStatementWrapper.idl | 26 +- .../storage/public/mozIStorageValueArray.idl | 116 +++++-- mozilla/storage/src/mozStorageConnection.cpp | 75 +--- mozilla/storage/src/mozStorageConnection.h | 2 +- mozilla/storage/src/mozStorageService.cpp | 4 +- mozilla/storage/src/mozStorageStatement.cpp | 149 ++------ .../src/mozStorageStatementWrapper.cpp | 6 +- mozilla/storage/src/mozStorageValueArray.cpp | 319 +++++------------- mozilla/storage/src/mozStorageValueArray.h | 2 +- mozilla/storage/test/storage1.cpp | 23 -- 15 files changed, 351 insertions(+), 591 deletions(-) diff --git a/mozilla/calendar/providers/storage/calStorageCalendar.js b/mozilla/calendar/providers/storage/calStorageCalendar.js index 181bf9ca578..65f294c74b0 100644 --- a/mozilla/calendar/providers/storage/calStorageCalendar.js +++ b/mozilla/calendar/providers/storage/calStorageCalendar.js @@ -299,8 +299,8 @@ calStorageCalendar.prototype = { this.mDBTwo = dbService.openDatabase (fileURL.file); } else if (aURI.scheme == "moz-profile-calendar") { dbService = Components.classes[kStorageServiceContractID].getService(kStorageServiceIID); - this.mDB = dbService.getProfileStorage("profile"); - this.mDBTwo = dbService.getProfileStorage("profile"); + this.mDB = dbService.openSpecialDatabase("profile"); + this.mDBTwo = dbService.openSpecialDatabase("profile"); } this.initDB(); diff --git a/mozilla/storage/public/mozIStorageConnection.idl b/mozilla/storage/public/mozIStorageConnection.idl index 15c55fa83f6..eeb85b89092 100644 --- a/mozilla/storage/public/mozIStorageConnection.idl +++ b/mozilla/storage/public/mozIStorageConnection.idl @@ -42,6 +42,13 @@ interface mozIStorageFunction; interface mozIStorageStatement; interface nsIFile; +/** + * 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. + */ [scriptable, uuid(623b8b2e-c9f9-4cc3-b15a-f3c96df2cc1c)] interface mozIStorageConnection : nsISupports { /* @@ -54,9 +61,10 @@ interface mozIStorageConnection : nsISupports { readonly attribute boolean connectionReady; /** - * the current database filename. Empty if the database is in-memory + * The current database nsIFile. Null if the database + * connection refers to an in-memory database. */ - readonly attribute AUTF8String databaseName; + readonly attribute nsIFile databaseFile; /** * lastInsertRowID returns the row ID from the last INSERT @@ -65,12 +73,13 @@ interface mozIStorageConnection : nsISupports { readonly attribute long long lastInsertRowID; /** - * lastError returns the last error code + * The last error SQLite error code. */ readonly attribute long lastError; /** - * lastErrorString returns the last error as a string + * The last SQLite error as a string (in english, straight from the + * sqlite library). */ readonly attribute AUTF8String lastErrorString; @@ -79,21 +88,22 @@ interface mozIStorageConnection : nsISupports { */ /** - * Create a mozIStorageStatement for the given SQL expression. - * The expression may use ?0 ?1 etc. to indicate numbered arguments. + * Create a mozIStorageStatement for the given SQL expression. The + * expression may use ? to indicate sequential numbered arguments, + * or :name and $var to indicate named arguments. * * @param aSQLStatement The SQL statement to execute * * @returns a new mozIStorageStatement */ - mozIStorageStatement createStatement (in AUTF8String aSQLStatement); + mozIStorageStatement createStatement(in AUTF8String aSQLStatement); /** * Execute a SQL expression, expecting no arguments. * * @param aSQLStatement The SQL statement to execute */ - void executeSimpleSQL (in AUTF8String aSQLStatement); + void executeSimpleSQL(in AUTF8String aSQLStatement); /** * Check if the given table exists. @@ -101,7 +111,7 @@ interface mozIStorageConnection : nsISupports { * @param aTableName The table to check * @returns TRUE if table exists, FALSE otherwise. */ - boolean tableExists (in AUTF8String aTableName); + boolean tableExists(in AUTF8String aTableName); /* * Transactions @@ -116,7 +126,7 @@ interface mozIStorageConnection : nsISupports { * Begin a new transaction. sqlite default transactions are deferred. * If a transaction is active, throws an error. */ - void beginTransaction (); + void beginTransaction(); /** * Begins a new transaction with the given type. @@ -124,72 +134,53 @@ interface mozIStorageConnection : nsISupports { const PRInt32 TRANSACTION_DEFERRED = 0; const PRInt32 TRANSACTION_IMMEDIATE = 1; const PRInt32 TRANSACTION_EXCLUSIVE = 2; - void beginTransactionAs (in PRInt32 transactionType); + void beginTransactionAs(in PRInt32 transactionType); /** * Commits the current transaction. If no transaction is active, * @throws NS_ERROR_STORAGE_NO_TRANSACTION. */ - void commitTransaction (); + void commitTransaction(); /** * Rolls back the current transaction. If no transaction is active, * @throws NS_ERROR_STORAGE_NO_TRANSACTION. */ - void rollbackTransaction (); + void rollbackTransaction(); /* * Tables */ /** - * Create the table with the given name and schema. If the table - * already exists with the given schema, the non-error - * NS_STORAGE_TABLE_EXISTS is returned. If the table exists but with - * a different schema, NS_ERROR_STORAGE_TABLE_CONFLICT (?) is thrown. + * Create the table with the given name and schema. * - * @param aID the owner of this table -- XXXtodo + * 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.) * - * @param aTableName the table name to be created, consisting of [A-Za-z0-9_], and beginning with a letter. + * @param aTableName the table name to be created, consisting of + * [A-Za-z0-9_], and beginning with a letter. + * + * @param aTableSchema the schema of the table; what would normally + * go between the parens in a CREATE TABLE statement: e.g., "foo + * INTEGER, bar STRING". + * + * @throws NS_ERROR_FAILURE if the table already exists or could not + * be created for any other reason. * - * @param aTableSchema the schema of the table; what would normally go between the parens in a CREATE TABLE - * statement: "foo INTEGER, bar STRING". */ void createTable(in string aTableName, in string aTableSchema); /* - * Functions and Triggers + * Functions */ /** * Create a new SQLite function */ - void createFunction (in string aFunctionName, - in long aNumArguments, - in mozIStorageFunction aFunction); - - /** - * Create a new trigger. Note that we only support AFTER triggers here, - * not BEFORE (so that we can support IPC notification of triggers). - * All triggers created this way are TEMPORARY triggers, i.e. they are only - * valid for the duration of this connection. Without this, triggers would - * persist between connections, even if the functions they refer to may no - * longer be defined; this would be bad. - * - * aParameters is a comma-separated list of parameters, referencing - * either "new.*" or "old.*", as appropriate for the trigger event - * type. - */ - const long TRIGGER_EVENT_DELETE = 1; - const long TRIGGER_EVENT_INSERT = 2; - const long TRIGGER_EVENT_UPDATE = 3; - - void createTrigger (in string aTriggerName, - in long aTriggerType, - in string aTableName, - in string aTriggerFunction, - in string aParameters); - - void removeTrigger (in string aTriggerName); + void createFunction(in string aFunctionName, + in long aNumArguments, + in mozIStorageFunction aFunction); }; diff --git a/mozilla/storage/public/mozIStorageFunction.idl b/mozilla/storage/public/mozIStorageFunction.idl index 631740a5e16..90ed9ecbcb8 100644 --- a/mozilla/storage/public/mozIStorageFunction.idl +++ b/mozilla/storage/public/mozIStorageFunction.idl @@ -42,6 +42,11 @@ interface mozIStorageConnection; interface mozIStorageValueArray; interface nsIArray; +/** + * mozIStorageFunction is to be implemented by storage consumers that + * wish to define custom storage functions, through + * mozIStorageConnection's createFunction method. + */ [scriptable, uuid(898d4189-7012-4ae9-a2af-435491cfa114)] interface mozIStorageFunction : nsISupports { /** @@ -52,5 +57,5 @@ interface mozIStorageFunction : nsISupports { * @param aFunctionArguments The arguments passed in to the function */ - void onFunctionCall (in mozIStorageValueArray aFunctionArguments); + void onFunctionCall(in mozIStorageValueArray aFunctionArguments); }; diff --git a/mozilla/storage/public/mozIStorageService.idl b/mozilla/storage/public/mozIStorageService.idl index e6df04baa46..2db40ce2a62 100644 --- a/mozilla/storage/public/mozIStorageService.idl +++ b/mozilla/storage/public/mozIStorageService.idl @@ -41,29 +41,46 @@ interface mozIStorageConnection; interface nsIFile; +/** + * The mozIStorageService interface is intended to be implemented by + * a service that can create storage connections (mozIStorageConnection) + * to either a well-known profile database or to a specific database file. + * + * This is the only way to open a database connection. + */ [scriptable, uuid(22cff01c-1a5a-4b11-9e27-f8f832226489)] interface mozIStorageService : nsISupports { /** - * Get a connection to the local profile storage. + * Get a connection to a named special database storage. * * @param aStorageKey a string key identifying the type of storage - * requested. Valid values include: "profile", "cert". + * requested. Valid values include: "profile", "memory" * - * @returns a mozIStorageConnection corresponding to - * the appropriate storage for the current thread. - * (XXX - always returns same one for now, need to add threading) + * @returns a new mozIStorageConnection for the requested + * storage database. + * + * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid. */ - mozIStorageConnection getProfileStorage(in string aStorageKey); + mozIStorageConnection openSpecialDatabase(in string aStorageKey); /** * Open a connection to the specified file. * * @param aDatabaseFile a nsIFile of the database to open. * - * @returns a mozIStorageConnection corresponding to - * the appropriate storage for the current thread. - * (XXX - always returns same one for now, need to add threading) + * @returns a mozIStorageConnection for the requested + * database file. + * + * @throws NS_ERROR_FAILURE if any operation fails while opening + * the database. */ mozIStorageConnection openDatabase(in nsIFile aDatabaseFile); -}; \ No newline at end of file +}; + +%{C++ + +#define MOZ_STORAGE_MEMORY_STORAGE_KEY "memory" +#define MOZ_STORAGE_PROFILE_STORAGE_KEY "profile" + +%} diff --git a/mozilla/storage/public/mozIStorageStatement.idl b/mozilla/storage/public/mozIStorageStatement.idl index 15509383135..724cdef0d04 100644 --- a/mozilla/storage/public/mozIStorageStatement.idl +++ b/mozilla/storage/public/mozIStorageStatement.idl @@ -51,76 +51,73 @@ interface mozIStorageStatement : mozIStorageValueArray { * Initialize this query with the given SQL statement. * */ - void initialize (in mozIStorageConnection aDBConnection, in AUTF8String aSQLStatement); + void initialize(in mozIStorageConnection aDBConnection, + in AUTF8String aSQLStatement); - mozIStorageStatement clone (); + /** + * Create a clone of this statement, by initializing a new statement + * with the same connection and same SQL statement as this one. It + * does not preserve statement state; that is, if a statement is + * being executed when it is cloned, the new statement will not be + * executing. + */ + mozIStorageStatement clone(); /* * Number of parameters */ readonly attribute unsigned long parameterCount; - /* + /** * Name of nth parameter, if given */ AUTF8String getParameterName(in unsigned long aParamIndex); - /* - * Indexes of named parameter + /** + * All indexes of a named parameter, if it's specified more than once */ - void getParameterIndexes(in AUTF8String aParameterName, - out unsigned long aCount, - [array,size_is(aCount),retval] out unsigned long aIndexes); - /* + void getParameterIndexes + (in AUTF8String aParameterName, + out unsigned long aCount, + [array,size_is(aCount),retval] out unsigned long aIndexes); + + /** * Number of columns returned */ readonly attribute unsigned long columnCount; - /* + /** * Name of nth column */ AUTF8String getColumnName(in unsigned long aColumnIndex); - /* + /** * Reset parameters/statement execution */ - void reset (); - - /* - * Parameter binding - */ - void bindCStringParameter (in unsigned long aParamIndex, in string aValue); - void bindUTF8StringParameter (in unsigned long aParamIndex, in AUTF8String aValue); - - void bindWStringParameter (in unsigned long aParamIndex, in wstring aValue); - void bindStringParameter (in unsigned long aParamIndex, in AString aValue); - - void bindDoubleParameter (in unsigned long aParamIndex, in double aValue); - void bindInt32Parameter (in unsigned long aParamIndex, in long aValue); - void bindInt64Parameter (in unsigned long aParamIndex, in long long aValue); - - void bindNullParameter (in unsigned long aParamIndex); - - void bindDataParameter (in unsigned long aParamIndex, [array,const,size_is(aValueSize)] in octet aValue, in unsigned long aValueSize); - - // void bindParameters (in string aFormatString, ...); + void reset(); /** - * Execute the query, ignoring any results. This is accomplished - * by calling step() once, and then calling reset(). + * Bind the given value to the parameter at aParamIndex. + */ + void bindUTF8StringParameter(in unsigned long aParamIndex, + in AUTF8String aValue); + void bindStringParameter(in unsigned long aParamIndex, in AString aValue); + void bindDoubleParameter(in unsigned long aParamIndex, in double aValue); + void bindInt32Parameter(in unsigned long aParamIndex, in long aValue); + void bindInt64Parameter(in unsigned long aParamIndex, in long long aValue); + void bindNullParameter(in unsigned long aParamIndex); + void bindBlobParameter(in unsigned long aParamIndex, + [array,const,size_is(aValueSize)] in octet aValue, + in unsigned long aValueSize); + + /** + * Execute the query, ignoring any results. This is accomplished by + * calling step() once, and then calling reset(). * * Error and last insert info, etc. are available from * the mozStorageConnection. */ - void execute (); - - /** - * Execute the query, using any currently-bound parameters. - * - * @returns a mozIStorageDataSet containing all the rows of the query - * result. - */ - mozIStorageDataSet executeDataSet (); + void execute(); /** * Execute a query, using any currently-bound parameters. Reset @@ -132,7 +129,7 @@ interface mozIStorageStatement : mozIStorageValueArray { * the statement. * */ - boolean executeStep (); + boolean executeStep(); /** * The current state. Row getters are only valid while diff --git a/mozilla/storage/public/mozIStorageStatementWrapper.idl b/mozilla/storage/public/mozIStorageStatementWrapper.idl index b2ebd641246..b268aafb2de 100644 --- a/mozilla/storage/public/mozIStorageStatementWrapper.idl +++ b/mozilla/storage/public/mozIStorageStatementWrapper.idl @@ -51,26 +51,34 @@ interface mozIStorageStatementParams : nsISupports { [scriptable, uuid(eee6f7c9-5586-4eaf-b35c-dca987c4ffd1)] interface mozIStorageStatementWrapper : nsISupports { - void initialize (in mozIStorageStatement aStatement); + /** + * Initialize this wrapper with aStatement. + */ + void initialize(in mozIStorageStatement aStatement); + /** + * The statement that is wrapped. + */ readonly attribute mozIStorageStatement statement; /** - * step, reset, and execute are passed down to the statement itself. + * Step, reset, and execute the wrapped statement. */ - void reset (); - boolean step (); - void execute (); + void reset(); + boolean step(); + void execute(); /** - * The current row. Throws an exception if no row is currently available. - * Useful only from script. The value of this is only valid while the - * statement is still executing, and is on the appropriate row + * The current row. Throws an exception if no row is currently + * available. Useful only from script. The value of this is only + * valid while the statement is still executing, and is still on the + * appropriate row. */ readonly attribute mozIStorageStatementRow row; /** - * The parameters. Can be set in lieu of using the call notation on this. + * The parameters; these can be set in lieu of using the call + * notation on this. */ readonly attribute mozIStorageStatementParams params; }; diff --git a/mozilla/storage/public/mozIStorageValueArray.idl b/mozilla/storage/public/mozIStorageValueArray.idl index dd1a843f81c..771c14fc1da 100644 --- a/mozilla/storage/public/mozIStorageValueArray.idl +++ b/mozilla/storage/public/mozIStorageValueArray.idl @@ -38,9 +38,19 @@ #include "nsISupports.idl" +[ptr] native octetPtr(PRUint8); + +/** + * mozIStorageValueArray wraps an array of SQL values, + * such as a single database row. + */ [scriptable, uuid(44fc1d3b-dc91-4d17-8bc5-2069d8fd3cca)] interface mozIStorageValueArray : nsISupports { - + /** + * These type values are returned by getTypeOfIndex + * to indicate what type of value is present at + * a given column. + */ const long VALUE_TYPE_NULL = 0; const long VALUE_TYPE_INTEGER = 1; const long VALUE_TYPE_FLOAT = 2; @@ -48,35 +58,93 @@ interface mozIStorageValueArray : nsISupports { const long VALUE_TYPE_BLOB = 4; /** - * numColumns + * numEntries * - * number of columns in the array + * number of entries in the array (each corresponding to a column + * in the database row) */ - readonly attribute unsigned long numColumns; + readonly attribute unsigned long numEntries; - long getTypeOfIndex (in unsigned long aIndex); + /** + * Returns the type of the value at the given column index; + * one of VALUE_TYPE_NULL, VALUE_TYPE_INTEGER, VALUE_TYPE_FLOAT, + * VALUE_TYPE_TEXT, VALUE_TYPE_BLOB. + */ + long getTypeOfIndex(in unsigned long aIndex); - /* Due to SQLite's type conversion rules, any of these is valid */ - - long getAsInt32(in unsigned long aIndex); - long long getAsInt64(in unsigned long aIndex); - double getAsDouble(in unsigned long aIndex); - string getAsCString(in unsigned long aIndex); - AUTF8String getAsUTF8String(in unsigned long aIndex); - AString getAsString(in unsigned long aIndex); - void getAsBlob(in unsigned long aIndex, [array,size_is(aDataSize)] out octet aData, out unsigned long aDataSize); - boolean getIsNull (in unsigned long aIndex); + /** + * Obtain a value for the given entry (column) index. + * Due to SQLite's type conversion rules, any of these are valid + * for any column regardless of the column's data type. However, + * if the specific type matters, getTypeOfIndex should be used + * first to identify the column type, and then the appropriate + * get method should be called. + */ + long getInt32(in unsigned long aIndex); + long long getInt64(in unsigned long aIndex); + double getDouble(in unsigned long aIndex); + AUTF8String getUTF8String(in unsigned long aIndex); + AString getString(in unsigned long aIndex); + void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData); + boolean getIsNull(in unsigned long aIndex); - /* XXX handle blobs! */ + /** + * Returns a shared string pointer + */ + [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult); + [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult); + [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult); - /* Native stuff */ - [notxpcom] long asInt32(in unsigned long aIndex); - [notxpcom] long long asInt64(in unsigned long aIndex); - [notxpcom] double asDouble(in unsigned long aIndex); - [notxpcom] string asSharedCString(in unsigned long aIndex, out unsigned long aLength); - [notxpcom] wstring asSharedWString(in unsigned long aIndex, out unsigned long aLength); +%{C++ + /** + * Getters for native code that return their values as + * the return type, for convenience and sanity. + * + * Not virtual; no vtable bloat. + */ - [noscript] void asSharedBlob(in unsigned long aIndex, [shared] out voidPtr aData, out unsigned long aDataSize); + inline PRInt32 AsInt32(PRUint32 idx) { + PRInt32 v; + GetInt32(idx, &v); + return v; + } + + inline PRInt64 AsInt64(PRUint32 idx) { + PRInt64 v; + GetInt64(idx, &v); + return v; + } + + inline double AsDouble(PRUint32 idx) { + double v; + GetDouble(idx, &v); + return v; + } + + inline const char* AsSharedUTF8String(PRUint32 idx, PRUint32 *len) { + const char *str = nsnull; + GetSharedUTF8String(idx, len, &str); + return str; + } + + inline const PRUnichar* AsSharedWString(PRUint32 idx, PRUint32 *len) { + const PRUnichar *str = nsnull; + GetSharedString(idx, len, &str); + return str; + } + + inline const PRUint8* AsSharedBlob(PRUint32 idx, PRUint32 *len) { + const PRUint8 *blob = nsnull; + GetSharedBlob(idx, len, &blob); + return blob; + } + + inline PRBool IsNull(PRUint32 idx) { + PRBool b = PR_FALSE; + GetIsNull(idx, &b); + return b; + } + +%} - [notxpcom] boolean isNull(in unsigned long aIndex); }; diff --git a/mozilla/storage/src/mozStorageConnection.cpp b/mozilla/storage/src/mozStorageConnection.cpp index 2a1518f0d2d..e8e53964dbe 100644 --- a/mozilla/storage/src/mozStorageConnection.cpp +++ b/mozilla/storage/src/mozStorageConnection.cpp @@ -92,10 +92,9 @@ mozStorageConnection::Initialize(nsIFile *aDatabaseFile) int srv; nsresult rv; - if (aDatabaseFile) { - rv = aDatabaseFile->GetNativeLeafName(mDatabaseName); - NS_ENSURE_SUCCESS(rv, rv); + mDatabaseFile = aDatabaseFile; + if (aDatabaseFile) { nsCAutoString nativePath; rv = aDatabaseFile->GetNativePath(nativePath); NS_ENSURE_SUCCESS(rv, rv); @@ -139,11 +138,11 @@ mozStorageConnection::GetConnectionReady(PRBool *aConnectionReady) } NS_IMETHODIMP -mozStorageConnection::GetDatabaseName(nsACString& aDatabaseName) +mozStorageConnection::GetDatabaseFile(nsIFile **aFile) { NS_ASSERTION(mDBConn, "connection not initialized"); - aDatabaseName = mDatabaseName; + NS_IF_ADDREF(*aFile = mDatabaseFile); return NS_OK; } @@ -350,7 +349,7 @@ mozStorageConnection::CreateTable(/*const nsID& aID,*/ } /** - ** Functions and Triggers + ** Functions **/ static void @@ -358,8 +357,6 @@ mozStorageSqlFuncHelper (sqlite3_context *ctx, int argc, sqlite3_value **argv) { - fprintf (stderr, "mozStorageSqlFuncHelper: %p %d %p\n", ctx, argc, argv); - void *userData = sqlite3_user_data (ctx); // We don't want to QI here, because this will be called a -lot- mozIStorageFunction *userFunction = NS_STATIC_CAST(mozIStorageFunction *, userData); @@ -406,68 +403,6 @@ mozStorageConnection::CreateFunction(const char *aFunctionName, return NS_OK; } -NS_IMETHODIMP -mozStorageConnection::CreateTrigger(const char *aTriggerName, - PRInt32 aTriggerType, - const char *aTableName, - const char *aTriggerFunction, - const char *aParameters) -{ -#if 0 - nsresult rv; - - /* We don't need to split this until we need to generate - * our own IPC trigger - */ - nsCStringArray *cstr = new nsCStringArray(); - if (!cstr) - return NS_ERROR_OUT_OF_MEMORY; - - rv = cstr->ParseString (aParameters, ","); - if (NS_FAILED(rv)) return rv; -#endif - - char *event = nsnull; - if (aTriggerType == TRIGGER_EVENT_DELETE) - event = "DELETE"; - else if (aTriggerType == TRIGGER_EVENT_INSERT) - event = "INSERT"; - else if (aTriggerType == TRIGGER_EVENT_UPDATE) - event = "UPDATE"; - else - return NS_ERROR_FAILURE; - - char *sql = PR_sprintf_append - (nsnull, - "CREATE TEMPORARY TRIGGER %s AFTER %s ON %s FOR EACH ROW BEGIN SELECT %s(%s); END;", - aTriggerName, - event, - aTableName, - aTriggerFunction, - aParameters); - if (!sql) - return NS_ERROR_OUT_OF_MEMORY; - - /* Now create the trigger */ - int srv = sqlite3_exec (mDBConn, - sql, - nsnull, - nsnull, - nsnull); - if (srv != SQLITE_OK) { - HandleSqliteError(nsnull); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -NS_IMETHODIMP -mozStorageConnection::RemoveTrigger(const char *aTriggerName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - /** ** Other bits **/ diff --git a/mozilla/storage/src/mozStorageConnection.h b/mozilla/storage/src/mozStorageConnection.h index 7c724cc89eb..4765e552011 100644 --- a/mozilla/storage/src/mozStorageConnection.h +++ b/mozilla/storage/src/mozStorageConnection.h @@ -72,7 +72,7 @@ protected: void HandleSqliteError(const char *aSqlStatement); sqlite3 *mDBConn; - nsCString mDatabaseName; + nsCOMPtr mDatabaseFile; PRBool mTransactionInProgress; nsCOMPtr mFunctions; diff --git a/mozilla/storage/src/mozStorageService.cpp b/mozilla/storage/src/mozStorageService.cpp index 77cb5912ed5..acbdb592365 100644 --- a/mozilla/storage/src/mozStorageService.cpp +++ b/mozilla/storage/src/mozStorageService.cpp @@ -61,9 +61,9 @@ mozStorageService::~mozStorageService() #define NS_APP_STORAGE_50_FILE "UStor" #endif -/* mozIStorageConnection getProfileStorage (in string aStorageKey); */ +/* mozIStorageConnection openSpecialDatabase(in string aStorageKey); */ NS_IMETHODIMP -mozStorageService::GetProfileStorage(const char *aStorageKey, mozIStorageConnection **_retval) +mozStorageService::OpenSpecialDatabase(const char *aStorageKey, mozIStorageConnection **_retval) { nsresult rv; diff --git a/mozilla/storage/src/mozStorageStatement.cpp b/mozilla/storage/src/mozStorageStatement.cpp index 5edc3df7231..3bc06e26e3f 100644 --- a/mozilla/storage/src/mozStorageStatement.cpp +++ b/mozilla/storage/src/mozStorageStatement.cpp @@ -270,20 +270,6 @@ mozStorageStatement::Reset() return NS_OK; } -/* void bindCStringParameter (in unsigned long aParamIndex, in string aValue); */ -NS_IMETHODIMP -mozStorageStatement::BindCStringParameter(PRUint32 aParamIndex, const char *aValue) -{ - NS_ASSERTION (mDBConnection && mDBStatement, "statement not initialized"); - if (aParamIndex < 0 || aParamIndex >= mParamCount) - return NS_ERROR_FAILURE; // XXXerror - - sqlite3_bind_text (mDBStatement, aParamIndex + 1, aValue, -1, SQLITE_TRANSIENT); - // XXX check return value for errors? - - return NS_OK; -} - /* void bindUTF8StringParameter (in unsigned long aParamIndex, in AUTF8String aValue); */ NS_IMETHODIMP mozStorageStatement::BindUTF8StringParameter(PRUint32 aParamIndex, const nsACString & aValue) @@ -300,20 +286,6 @@ mozStorageStatement::BindUTF8StringParameter(PRUint32 aParamIndex, const nsACStr return NS_OK; } -/* void bindWStringParameter (in unsigned long aParamIndex, in wstring aValue); */ -NS_IMETHODIMP -mozStorageStatement::BindWStringParameter(PRUint32 aParamIndex, const PRUnichar *aValue) -{ - NS_ASSERTION (mDBConnection && mDBStatement, "statement not initialized"); - if (aParamIndex < 0 || aParamIndex >= mParamCount) - return NS_ERROR_FAILURE; // XXXerror - - sqlite3_bind_text16 (mDBStatement, aParamIndex + 1, aValue, -1, SQLITE_TRANSIENT); - // XXX check return value for errors? - - return NS_OK; -} - /* void bindStringParameter (in unsigned long aParamIndex, in AString aValue); */ NS_IMETHODIMP mozStorageStatement::BindStringParameter(PRUint32 aParamIndex, const nsAString & aValue) @@ -386,9 +358,9 @@ mozStorageStatement::BindNullParameter(PRUint32 aParamIndex) return NS_OK; } -/* void bindDataParameter (in unsigned long aParamIndex, [array, const, size_is (aValueSize)] in octet aValue, in unsigned long aValueSize); */ +/* void bindBlobParameter (in unsigned long aParamIndex, [array, const, size_is (aValueSize)] in octet aValue, in unsigned long aValueSize); */ NS_IMETHODIMP -mozStorageStatement::BindDataParameter(PRUint32 aParamIndex, const PRUint8 *aValue, PRUint32 aValueSize) +mozStorageStatement::BindBlobParameter(PRUint32 aParamIndex, const PRUint8 *aValue, PRUint32 aValueSize) { NS_ASSERTION (mDBConnection && mDBStatement, "statement not initialized"); if (aParamIndex < 0 || aParamIndex >= mParamCount) @@ -413,15 +385,6 @@ mozStorageStatement::Execute() return Reset(); } -/* mozIStorageDataSet executeDataSet (); */ -NS_IMETHODIMP -mozStorageStatement::ExecuteDataSet(mozIStorageDataSet **_retval) -{ - NS_ASSERTION (mDBConnection && mDBStatement, "statement not initialized"); - - return NS_ERROR_NOT_IMPLEMENTED; -} - /* boolean executeStep (); */ NS_IMETHODIMP mozStorageStatement::ExecuteStep(PRBool *_retval) @@ -553,9 +516,9 @@ mozStorageStatement::Recreate() *** mozIStorageValueArray ***/ -/* readonly attribute unsigned long length; */ +/* readonly attribute unsigned long numEntries; */ NS_IMETHODIMP -mozStorageStatement::GetNumColumns(PRUint32 *aLength) +mozStorageStatement::GetNumEntries(PRUint32 *aLength) { *aLength = mResultColumnCount; return NS_OK; @@ -592,9 +555,9 @@ mozStorageStatement::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retval) return NS_OK; } -/* long getAsInt32 (in unsigned long aIndex); */ +/* long getInt32 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatement::GetAsInt32(PRUint32 aIndex, PRInt32 *_retval) +mozStorageStatement::GetInt32(PRUint32 aIndex, PRInt32 *_retval) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -605,9 +568,9 @@ mozStorageStatement::GetAsInt32(PRUint32 aIndex, PRInt32 *_retval) return NS_OK; } -/* long long getAsInt64 (in unsigned long aIndex); */ +/* long long getInt64 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatement::GetAsInt64(PRUint32 aIndex, PRInt64 *_retval) +mozStorageStatement::GetInt64(PRUint32 aIndex, PRInt64 *_retval) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -618,9 +581,9 @@ mozStorageStatement::GetAsInt64(PRUint32 aIndex, PRInt64 *_retval) return NS_OK; } -/* double getAsDouble (in unsigned long aIndex); */ +/* double getDouble (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatement::GetAsDouble(PRUint32 aIndex, double *_retval) +mozStorageStatement::GetDouble(PRUint32 aIndex, double *_retval) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -631,27 +594,9 @@ mozStorageStatement::GetAsDouble(PRUint32 aIndex, double *_retval) return NS_OK; } -/* string getAsCString (in unsigned long aIndex); */ +/* AUTF8String getUTF8String (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatement::GetAsCString(PRUint32 aIndex, char **_retval) -{ - NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); - if (!mExecuting) - return NS_ERROR_FAILURE; - - int slen = sqlite3_column_bytes (mDBStatement, aIndex); - const unsigned char *cstr = sqlite3_column_text (mDBStatement, aIndex); - char *str = (char *) nsMemory::Clone (cstr, slen); - if (str == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - *_retval = str; - return NS_OK; -} - -/* AUTF8String getAsUTF8String (in unsigned long aIndex); */ -NS_IMETHODIMP -mozStorageStatement::GetAsUTF8String(PRUint32 aIndex, nsACString & _retval) +mozStorageStatement::GetUTF8String(PRUint32 aIndex, nsACString & _retval) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -664,9 +609,9 @@ mozStorageStatement::GetAsUTF8String(PRUint32 aIndex, nsACString & _retval) return NS_OK; } -/* AString getAsString (in unsigned long aIndex); */ +/* AString getString (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatement::GetAsString(PRUint32 aIndex, nsAString & _retval) +mozStorageStatement::GetString(PRUint32 aIndex, nsAString & _retval) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -680,9 +625,9 @@ mozStorageStatement::GetAsString(PRUint32 aIndex, nsAString & _retval) return NS_OK; } -/* void getAsBlob (in unsigned long aIndex, [array, size_is (aDataSize)] out octet aData, out unsigned long aDataSize); */ +/* void getBlob (in unsigned long aIndex, out unsigned long aDataSize, [array, size_is (aDataSize)] out octet aData); */ NS_IMETHODIMP -mozStorageStatement::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PRUint32 *aDataSize) +mozStorageStatement::GetBlob(PRUint32 aIndex, PRUint32 *aDataSize, PRUint8 **aData) { NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); if (!mExecuting) @@ -701,64 +646,38 @@ mozStorageStatement::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PRUint32 *aData return NS_OK; } -/* [notxpcom] long asInt32 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt32) -mozStorageStatement::AsInt32(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); - - return sqlite3_column_int (mDBStatement, aIndex); -} - -/* [notxpcom] long long asInt64 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt64) -mozStorageStatement::AsInt64(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); - - return sqlite3_column_int64 (mDBStatement, aIndex); -} - -/* [notxpcom] double asDouble (in unsigned long aIndex); */ -NS_IMETHODIMP_(double) -mozStorageStatement::AsDouble(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); - - return sqlite3_column_double (mDBStatement, aIndex); -} - -/* [notxpcom] string asSharedCString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(char *) -mozStorageStatement::AsSharedCString(PRUint32 aIndex, PRUint32 *aLength) +/* [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult); */ +NS_IMETHODIMP +mozStorageStatement::GetSharedUTF8String(PRUint32 aIndex, PRUint32 *aLength, const char **_retval) { if (aLength) { int slen = sqlite3_column_bytes (mDBStatement, aIndex); *aLength = slen; } - return (char *) sqlite3_column_text (mDBStatement, aIndex); + *_retval = (const char *) sqlite3_column_text (mDBStatement, aIndex); + return NS_OK; } -/* [notxpcom] wstring asSharedWString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(PRUnichar *) -mozStorageStatement::AsSharedWString(PRUint32 aIndex, PRUint32 *aLength) +/* [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult); */ +NS_IMETHODIMP +mozStorageStatement::GetSharedString(PRUint32 aIndex, PRUint32 *aLength, const PRUnichar **_retval) { if (aLength) { int slen = sqlite3_column_bytes16 (mDBStatement, aIndex); *aLength = slen; } - const void *text = sqlite3_column_text16 (mDBStatement, aIndex); - return NS_STATIC_CAST(PRUnichar *, NS_CONST_CAST(void *, text)); + *_retval = (const PRUnichar *) sqlite3_column_text16 (mDBStatement, aIndex); + return NS_OK; } -/* [noscript] void asSharedBlob (in unsigned long aIndex, [shared] out voidPtr aData, out unsigned long aDataSize); */ +/* [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult); */ NS_IMETHODIMP -mozStorageStatement::AsSharedBlob(PRUint32 aIndex, const void * *aData, PRUint32 *aDataSize) +mozStorageStatement::GetSharedBlob(PRUint32 aIndex, PRUint32 *aDataSize, const PRUint8 **aData) { *aDataSize = sqlite3_column_bytes (mDBStatement, aIndex); - *aData = sqlite3_column_blob (mDBStatement, aIndex); + *aData = (const PRUint8*) sqlite3_column_blob (mDBStatement, aIndex); return NS_OK; } @@ -778,13 +697,3 @@ mozStorageStatement::GetIsNull(PRUint32 aIndex, PRBool *_retval) return NS_OK; } - - -/* [notxpcom] boolean isNull (in unsigned long aIndex); */ -PRBool -mozStorageStatement::IsNull(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mResultColumnCount, "aIndex out of range"); - - return (sqlite3_column_type (mDBStatement, aIndex) == SQLITE_NULL); -} diff --git a/mozilla/storage/src/mozStorageStatementWrapper.cpp b/mozilla/storage/src/mozStorageStatementWrapper.cpp index b0786fdfb56..fb5a47b998c 100644 --- a/mozilla/storage/src/mozStorageStatementWrapper.cpp +++ b/mozilla/storage/src/mozStorageStatementWrapper.cpp @@ -113,7 +113,7 @@ JSValStorageStatementBinder (JSContext *cx, } else if (JSVAL_IS_STRING(val)) { JSString *str = JSVAL_TO_STRING(val); for (i = 0; i < aNumIndexes; i++) - aStatement->BindWStringParameter(aParamIndexes[i], NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str))); + aStatement->BindStringParameter(aParamIndexes[i], nsDependentString(NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)), JS_GetStringLength(str))); } else if (JSVAL_IS_BOOLEAN(val)) { if (val == JSVAL_TRUE) { for (i = 0; i < aNumIndexes; i++) @@ -175,7 +175,7 @@ mozStorageStatementWrapper::Initialize(mozIStorageStatement *aStatement) // fetch various things we care about mStatement->GetParameterCount(&mParamCount); - mStatement->GetNumColumns(&mResultColumnCount); + mStatement->GetColumnCount(&mResultColumnCount); for (unsigned int i = 0; i < mResultColumnCount; i++) { const void *name = sqlite3_column_name16 (NativeStatement(), i); @@ -312,7 +312,7 @@ mozStorageStatementWrapper::Call(nsIXPConnectWrappedNative *wrapper, JSContext * mStatement->Reset(); // bind parameters - for (int i = 0; i < argc; i++) { + for (int i = 0; i < (int) argc; i++) { if (!JSValStorageStatementBinder(cx, mStatement, &i, 1, argv[i])) { *_retval = PR_FALSE; return NS_ERROR_INVALID_ARG; diff --git a/mozilla/storage/src/mozStorageValueArray.cpp b/mozilla/storage/src/mozStorageValueArray.cpp index 2ba050b4d36..a42aca32db1 100644 --- a/mozilla/storage/src/mozStorageValueArray.cpp +++ b/mozilla/storage/src/mozStorageValueArray.cpp @@ -52,7 +52,7 @@ NS_IMPL_ISUPPORTS1(mozStorageStatementRowValueArray, mozIStorageValueArray) mozStorageStatementRowValueArray::mozStorageStatementRowValueArray(sqlite3_stmt *aSqliteStmt) { mSqliteStatement = aSqliteStmt; - mNumColumns = sqlite3_data_count (aSqliteStmt); + mNumEntries = sqlite3_data_count (aSqliteStmt); } mozStorageStatementRowValueArray::~mozStorageStatementRowValueArray() @@ -60,11 +60,11 @@ mozStorageStatementRowValueArray::~mozStorageStatementRowValueArray() /* do nothing, we don't own the stmt */ } -/* readonly attribute unsigned long length; */ +/* readonly attribute unsigned long numEntries; */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetNumColumns(PRUint32 *aLength) +mozStorageStatementRowValueArray::GetNumEntries(PRUint32 *aLength) { - *aLength = mNumColumns; + *aLength = mNumEntries; return NS_OK; } @@ -72,7 +72,7 @@ mozStorageStatementRowValueArray::GetNumColumns(PRUint32 *aLength) NS_IMETHODIMP mozStorageStatementRowValueArray::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); int t = sqlite3_column_type (mSqliteStatement, aIndex); switch (t) { @@ -99,73 +99,52 @@ mozStorageStatementRowValueArray::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retv return NS_OK; } -/* long getAsInt32 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsInt32(PRUint32 aIndex, PRInt32 *_retval) +mozStorageStatementRowValueArray::GetInt32(PRUint32 aIndex, PRInt32 *_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); *_retval = sqlite3_column_int (mSqliteStatement, aIndex); return NS_OK; } -/* long long getAsInt64 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsInt64(PRUint32 aIndex, PRInt64 *_retval) +mozStorageStatementRowValueArray::GetInt64(PRUint32 aIndex, PRInt64 *_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); *_retval = sqlite3_column_int64 (mSqliteStatement, aIndex); return NS_OK; } -/* double getAsDouble (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsDouble(PRUint32 aIndex, double *_retval) +mozStorageStatementRowValueArray::GetDouble(PRUint32 aIndex, double *_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); *_retval = sqlite3_column_double (mSqliteStatement, aIndex); return NS_OK; } -/* string getAsCString (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsCString(PRUint32 aIndex, char **_retval) +mozStorageStatementRowValueArray::GetUTF8String(PRUint32 aIndex, nsACString &_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); - int slen = sqlite3_column_bytes (mSqliteStatement, aIndex); - const unsigned char *cstr = sqlite3_column_text (mSqliteStatement, aIndex); - char *str = (char *) nsMemory::Clone (cstr, slen); - if (str == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - *_retval = str; - return NS_OK; -} - -/* AUTF8String getAsUTF8String (in unsigned long aIndex); */ -NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsUTF8String(PRUint32 aIndex, nsACString & _retval) -{ - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); - - int slen = sqlite3_column_bytes (mSqliteStatement, aIndex); - const unsigned char *cstr = sqlite3_column_text (mSqliteStatement, aIndex); - _retval.Assign ((char *) cstr, slen); + PRUint32 slen = (PRUint32) sqlite3_column_bytes (mSqliteStatement, aIndex); + const char *cstr = (const char *) sqlite3_column_text (mSqliteStatement, aIndex); + _retval.Assign(cstr, slen); return NS_OK; } -/* AString getAsString (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsString(PRUint32 aIndex, nsAString & _retval) +mozStorageStatementRowValueArray::GetString(PRUint32 aIndex, nsAString & _retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); int slen = sqlite3_column_bytes16 (mSqliteStatement, aIndex); const PRUnichar *wstr = (const PRUnichar *) sqlite3_column_text16 (mSqliteStatement, aIndex); @@ -174,11 +153,10 @@ mozStorageStatementRowValueArray::GetAsString(PRUint32 aIndex, nsAString & _retv return NS_OK; } -/* void getAsBlob (in unsigned long aIndex, [array, size_is (aDataSize)] out octet aData, out unsigned long aDataSize); */ NS_IMETHODIMP -mozStorageStatementRowValueArray::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PRUint32 *aDataSize) +mozStorageStatementRowValueArray::GetBlob(PRUint32 aIndex, PRUint32 *aDataSize, PRUint8 **aData) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + NS_ASSERTION (aIndex < mNumEntries, "aIndex out of range"); int blobsize = sqlite3_column_bytes (mSqliteStatement, aIndex); const void *blob = sqlite3_column_blob (mSqliteStatement, aIndex); @@ -193,74 +171,13 @@ mozStorageStatementRowValueArray::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PR return NS_OK; } -/* [notxpcom] long asInt32 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt32) -mozStorageStatementRowValueArray::AsInt32(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); - - return sqlite3_column_int (mSqliteStatement, aIndex); -} - -/* [notxpcom] long long asInt64 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt64) -mozStorageStatementRowValueArray::AsInt64(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); - - return sqlite3_column_int64 (mSqliteStatement, aIndex); -} - -/* [notxpcom] double asDouble (in unsigned long aIndex); */ -NS_IMETHODIMP_(double) -mozStorageStatementRowValueArray::AsDouble(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); - - return sqlite3_column_double (mSqliteStatement, aIndex); -} - -/* [notxpcom] string asSharedCString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(char *) -mozStorageStatementRowValueArray::AsSharedCString(PRUint32 aIndex, PRUint32 *aLength) -{ - if (aLength) { - int slen = sqlite3_column_bytes (mSqliteStatement, aIndex); - *aLength = slen; - } - - return (char *) sqlite3_column_text (mSqliteStatement, aIndex); -} - -/* [notxpcom] wstring asSharedWString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(PRUnichar *) -mozStorageStatementRowValueArray::AsSharedWString(PRUint32 aIndex, PRUint32 *aLength) -{ - if (aLength) { - int slen = sqlite3_column_bytes16 (mSqliteStatement, aIndex); - *aLength = slen; - } - - return (PRUnichar *) sqlite3_column_text16 (mSqliteStatement, aIndex); -} - -/* [noscript] void asSharedBlob (in unsigned long aIndex, [shared] out voidPtr aData, out unsigned long aDataSize); */ -NS_IMETHODIMP -mozStorageStatementRowValueArray::AsSharedBlob(PRUint32 aIndex, const void * *aData, PRUint32 *aDataSize) -{ - *aDataSize = sqlite3_column_bytes (mSqliteStatement, aIndex); - *aData = sqlite3_column_blob (mSqliteStatement, aIndex); - - return NS_OK; -} - -/* boolean getIsNull (in unsigned long aIndex); */ NS_IMETHODIMP mozStorageStatementRowValueArray::GetIsNull(PRUint32 aIndex, PRBool *_retval) { PRInt32 t; nsresult rv = GetTypeOfIndex (aIndex, &t); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (t == VALUE_TYPE_NULL) *_retval = PR_TRUE; @@ -270,16 +187,40 @@ mozStorageStatementRowValueArray::GetIsNull(PRUint32 aIndex, PRBool *_retval) return NS_OK; } - -/* [notxpcom] boolean isNull (in unsigned long aIndex); */ -PRBool -mozStorageStatementRowValueArray::IsNull(PRUint32 aIndex) +NS_IMETHODIMP +mozStorageStatementRowValueArray::GetSharedUTF8String(PRUint32 aIndex, PRUint32 *aLength, const char **_retval) { - NS_ASSERTION (aIndex < mNumColumns, "aIndex out of range"); + if (aLength) { + int slen = sqlite3_column_bytes (mSqliteStatement, aIndex); + *aLength = slen; + } - return (sqlite3_column_type (mSqliteStatement, aIndex) == SQLITE_NULL); + *_retval = (const char*) sqlite3_column_text (mSqliteStatement, aIndex); + return NS_OK; } +NS_IMETHODIMP +mozStorageStatementRowValueArray::GetSharedString(PRUint32 aIndex, PRUint32 *aLength, const PRUnichar **_retval) +{ + if (aLength) { + int slen = sqlite3_column_bytes16 (mSqliteStatement, aIndex); + *aLength = slen; + } + + *_retval = (const PRUnichar *) sqlite3_column_text16 (mSqliteStatement, aIndex); + return NS_OK; +} + +NS_IMETHODIMP +mozStorageStatementRowValueArray::GetSharedBlob(PRUint32 aIndex, PRUint32 *aDataSize, const PRUint8 **aData) +{ + *aDataSize = sqlite3_column_bytes (mSqliteStatement, aIndex); + *aData = (const PRUint8*) sqlite3_column_blob (mSqliteStatement, aIndex); + + return NS_OK; +} + + /*** *** mozStorageArgvValueArray ***/ @@ -299,7 +240,7 @@ mozStorageArgvValueArray::~mozStorageArgvValueArray() /* readonly attribute unsigned long length; */ NS_IMETHODIMP -mozStorageArgvValueArray::GetNumColumns(PRUint32 *aLength) +mozStorageArgvValueArray::GetNumEntries(PRUint32 *aLength) { *aLength = mArgc; return NS_OK; @@ -336,9 +277,8 @@ mozStorageArgvValueArray::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retval) return NS_OK; } -/* long getAsInt32 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsInt32(PRUint32 aIndex, PRInt32 *_retval) +mozStorageArgvValueArray::GetInt32(PRUint32 aIndex, PRInt32 *_retval) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -347,9 +287,8 @@ mozStorageArgvValueArray::GetAsInt32(PRUint32 aIndex, PRInt32 *_retval) return NS_OK; } -/* long long getAsInt64 (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsInt64(PRUint32 aIndex, PRInt64 *_retval) +mozStorageArgvValueArray::GetInt64(PRUint32 aIndex, PRInt64 *_retval) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -358,9 +297,8 @@ mozStorageArgvValueArray::GetAsInt64(PRUint32 aIndex, PRInt64 *_retval) return NS_OK; } -/* double getAsDouble (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsDouble(PRUint32 aIndex, double *_retval) +mozStorageArgvValueArray::GetDouble(PRUint32 aIndex, double *_retval) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -369,25 +307,8 @@ mozStorageArgvValueArray::GetAsDouble(PRUint32 aIndex, double *_retval) return NS_OK; } -/* string getAsCString (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsCString(PRUint32 aIndex, char **_retval) -{ - NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); - - int slen = sqlite3_value_bytes (mArgv[aIndex]); - const unsigned char *cstr = sqlite3_value_text (mArgv[aIndex]); - char *str = (char *) nsMemory::Clone (cstr, slen); - if (str == NULL) - return NS_ERROR_OUT_OF_MEMORY; - - *_retval = str; - return NS_OK; -} - -/* AUTF8String getAsUTF8String (in unsigned long aIndex); */ -NS_IMETHODIMP -mozStorageArgvValueArray::GetAsUTF8String(PRUint32 aIndex, nsACString & _retval) +mozStorageArgvValueArray::GetUTF8String(PRUint32 aIndex, nsACString & _retval) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -398,9 +319,8 @@ mozStorageArgvValueArray::GetAsUTF8String(PRUint32 aIndex, nsACString & _retval) return NS_OK; } -/* AString getAsString (in unsigned long aIndex); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsString(PRUint32 aIndex, nsAString & _retval) +mozStorageArgvValueArray::GetString(PRUint32 aIndex, nsAString & _retval) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -411,9 +331,8 @@ mozStorageArgvValueArray::GetAsString(PRUint32 aIndex, nsAString & _retval) return NS_OK; } -/* void getAsBlob (in unsigned long aIndex, [array, size_is (aDataSize)] out octet aData, out unsigned long aDataSize); */ NS_IMETHODIMP -mozStorageArgvValueArray::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PRUint32 *aDataSize) +mozStorageArgvValueArray::GetBlob(PRUint32 aIndex, PRUint32 *aDataSize, PRUint8 **aData) { NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); @@ -430,74 +349,14 @@ mozStorageArgvValueArray::GetAsBlob(PRUint32 aIndex, PRUint8 **aData, PRUint32 * return NS_OK; } -/* [notxpcom] long asInt32 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt32) -mozStorageArgvValueArray::AsInt32(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); - - return sqlite3_value_int (mArgv[aIndex]); -} - -/* [notxpcom] long long asInt64 (in unsigned long aIndex); */ -NS_IMETHODIMP_(PRInt64) -mozStorageArgvValueArray::AsInt64(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); - - return sqlite3_value_int64 (mArgv[aIndex]); -} - -/* [notxpcom] double asDouble (in unsigned long aIndex); */ -NS_IMETHODIMP_(double) -mozStorageArgvValueArray::AsDouble(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); - - return sqlite3_value_double (mArgv[aIndex]); -} - -/* [notxpcom] string asSharedCString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(char *) -mozStorageArgvValueArray::AsSharedCString(PRUint32 aIndex, PRUint32 *aLength) -{ - if (aLength) { - int slen = sqlite3_value_bytes (mArgv[aIndex]); - *aLength = slen; - } - - return (char *) sqlite3_value_text (mArgv[aIndex]); -} - -/* [notxpcom] wstring asSharedWString (in unsigned long aIndex, out unsigned long aLength); */ -NS_IMETHODIMP_(PRUnichar *) -mozStorageArgvValueArray::AsSharedWString(PRUint32 aIndex, PRUint32 *aLength) -{ - if (aLength) { - int slen = sqlite3_value_bytes16 (mArgv[aIndex]); - *aLength = slen; - } - - return (PRUnichar *) sqlite3_value_text16 (mArgv[aIndex]); -} - -/* [noscript] void asSharedBlob (in unsigned long aIndex, [shared] out voidPtr aData, out unsigned long aDataSize); */ -NS_IMETHODIMP -mozStorageArgvValueArray::AsSharedBlob(PRUint32 aIndex, const void * *aData, PRUint32 *aDataSize) -{ - *aDataSize = sqlite3_value_bytes (mArgv[aIndex]); - *aData = sqlite3_value_blob (mArgv[aIndex]); - - return NS_OK; -} - /* boolean getIsNull (in unsigned long aIndex); */ NS_IMETHODIMP mozStorageArgvValueArray::GetIsNull(PRUint32 aIndex, PRBool *_retval) { PRInt32 t; nsresult rv = GetTypeOfIndex (aIndex, &t); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (t == VALUE_TYPE_NULL) *_retval = PR_TRUE; @@ -507,41 +366,35 @@ mozStorageArgvValueArray::GetIsNull(PRUint32 aIndex, PRBool *_retval) return NS_OK; } - -/* [notxpcom] boolean isNull (in unsigned long aIndex); */ -PRBool -mozStorageArgvValueArray::IsNull(PRUint32 aIndex) -{ - NS_ASSERTION (aIndex < mArgc, "aIndex out of range"); - - return (sqlite3_value_type (mArgv[aIndex]) == SQLITE_NULL); -} - -/*** - *** mozStorageDataSet - ***/ - -NS_IMPL_ISUPPORTS1(mozStorageDataSet, mozIStorageDataSet) - -mozStorageDataSet::mozStorageDataSet(nsIArray *aRows) - : mRows(aRows) -{ -} - -mozStorageDataSet::~mozStorageDataSet() -{ -} - -/* readonly attribute nsIArray dataRows; */ NS_IMETHODIMP -mozStorageDataSet::GetDataRows(nsIArray **aDataRows) +mozStorageArgvValueArray::GetSharedUTF8String(PRUint32 aIndex, PRUint32 *aLength, const char **_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + if (aLength) { + int slen = sqlite3_value_bytes (mArgv[aIndex]); + *aLength = slen; + } + + *_retval = (const char*) sqlite3_value_text (mArgv[aIndex]); + return NS_OK; } -/* nsISimpleEnumerator getRowEnumerator (); */ NS_IMETHODIMP -mozStorageDataSet::GetRowEnumerator(nsISimpleEnumerator **_retval) +mozStorageArgvValueArray::GetSharedString(PRUint32 aIndex, PRUint32 *aLength, const PRUnichar **_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + if (aLength) { + int slen = sqlite3_value_bytes16 (mArgv[aIndex]); + *aLength = slen; + } + + *_retval = (const PRUnichar*) sqlite3_value_text16 (mArgv[aIndex]); + return NS_OK; +} + +NS_IMETHODIMP +mozStorageArgvValueArray::GetSharedBlob(PRUint32 aIndex, PRUint32 *aDataSize, const PRUint8 **aData) +{ + *aDataSize = sqlite3_value_bytes (mArgv[aIndex]); + *aData = (const PRUint8*) sqlite3_value_blob (mArgv[aIndex]); + + return NS_OK; } diff --git a/mozilla/storage/src/mozStorageValueArray.h b/mozilla/storage/src/mozStorageValueArray.h index f2a0eb20355..b4a5a4ed223 100644 --- a/mozilla/storage/src/mozStorageValueArray.h +++ b/mozilla/storage/src/mozStorageValueArray.h @@ -62,7 +62,7 @@ public: private: sqlite3_stmt *mSqliteStatement; - PRUint32 mNumColumns; + PRUint32 mNumEntries; }; class mozStorageArgvValueArray : public mozIStorageValueArray diff --git a/mozilla/storage/test/storage1.cpp b/mozilla/storage/test/storage1.cpp index a7148dc7b35..787a52d7e1f 100644 --- a/mozilla/storage/test/storage1.cpp +++ b/mozilla/storage/test/storage1.cpp @@ -92,10 +92,6 @@ main (int argc, char **argv) rv = dbConn->CreateStatement (NS_LITERAL_CSTRING("SELECT i FROM foo"), getter_AddRefs(dbFooSelectStatement)); TEST_CHECK_ERROR(rv); - rv = dbConn->CreateTrigger("foo_trig", mozIStorageConnection::TRIGGER_EVENT_INSERT, - "foo", "x_test", "1"); - TEST_CHECK_ERROR(rv); - for (int i = 0; i < 10; i++) { rv = dbFooInsertStatement->BindInt32Parameter (0, i); TEST_CHECK_ERROR(rv); @@ -119,23 +115,4 @@ main (int argc, char **argv) TEST_CHECK_ERROR(rv); fprintf (stderr, "Done. %d 0x%08x %p\n", rv, rv, dbRow.get()); - -#if 0 - // try an enumerator - fprintf (stderr, "Trying via an enumerator\n"); - - nsCOMPtr dbEnum; - - (void) dbFooSelectStatement->Reset (); - rv = dbFooSelectStatement->ExecuteEnumerator (getter_AddRefs(dbEnum)); - TEST_CHECK_ERROR(rv); - - PRBool b; - while ((dbEnum->HasMoreElements(&b) == NS_OK) && b) { - dbEnum->GetNext (getter_AddRefs (dbRow)); - PRUint32 len; - dbRow->GetLength (&len); - fprintf (stderr, "Row[length %d]: %d '%s'\n", len, dbRow->AsInt32(0), dbRow->AsSharedCString(0, 0)); - } -#endif }