diff --git a/mozilla/storage/public/mozIStorageConnection.idl b/mozilla/storage/public/mozIStorageConnection.idl index 4359b9b7764..30088b111b8 100644 --- a/mozilla/storage/public/mozIStorageConnection.idl +++ b/mozilla/storage/public/mozIStorageConnection.idl @@ -49,7 +49,7 @@ interface nsIFile; * creating prepared statements, executing SQL, and examining database * errors. */ -[scriptable, uuid(e045e635-94af-48af-9a8d-80f1a88a35f3)] +[scriptable, uuid(4c459c8a-f548-42b7-8d7e-42ea1aed3876)] interface mozIStorageConnection : nsISupports { /* * Initialization and status @@ -113,6 +113,15 @@ interface mozIStorageConnection : nsISupports { */ boolean tableExists(in AUTF8String aTableName); + /** + * Check if the given index exists. + * + * @param aIndexName The index to check + * @returns TRUE if the index exists, FALSE otherwise. + */ + boolean indexExists(in AUTF8String aIndexName); + + /* * Transactions */ diff --git a/mozilla/storage/src/mozStorageConnection.cpp b/mozilla/storage/src/mozStorageConnection.cpp index 1fd73bc6490..3de7fbd485b 100644 --- a/mozilla/storage/src/mozStorageConnection.cpp +++ b/mozilla/storage/src/mozStorageConnection.cpp @@ -255,6 +255,42 @@ mozStorageConnection::TableExists(const nsACString& aSQLStatement, PRBool *_retv return NS_OK; } +NS_IMETHODIMP +mozStorageConnection::IndexExists(const nsACString& aIndexName, PRBool* _retval) +{ + NS_ENSURE_ARG_POINTER(mDBConn); + + nsCString query("SELECT name FROM sqlite_master WHERE type = 'index' AND name ='"); + query.Append(aIndexName); + query.AppendLiteral("'"); + + sqlite3_stmt *stmt = nsnull; + int srv = sqlite3_prepare(mDBConn, query.get(), query.Length(), &stmt, nsnull); + if (srv != SQLITE_OK) { + HandleSqliteError(query.get()); + return NS_ERROR_FAILURE; // XXX error code + } + + PRBool exists = PR_FALSE; + + srv = sqlite3_step(stmt); + // we just care about the return value from step + sqlite3_finalize(stmt); + + if (srv == SQLITE_ROW) { + exists = PR_TRUE; + } else if (srv == SQLITE_DONE) { + exists = PR_FALSE; + } else if (srv == SQLITE_ERROR) { + HandleSqliteError("IndexExists finalize"); + return NS_ERROR_FAILURE; + } + + *_retval = exists; + return NS_OK; +} + + /** ** Transactions **/