b=293707, update storage calendar, partial (mozStorage-only) commit, r=shaver

This commit is contained in:
vladimir%pobox.com 2005-05-12 01:09:04 +00:00
parent 8c0a3f0dc0
commit 02b491c5e1
5 changed files with 58 additions and 4 deletions

View File

@ -95,6 +95,14 @@ interface mozIStorageConnection : nsISupports {
*/
void executeSimpleSQL (in AUTF8String aSQLStatement);
/**
* Check if the given table exists.
*
* @param aTableName The table to check
* @returns TRUE if table exists, FALSE otherwise.
*/
boolean tableExists (in AUTF8String aTableName);
/*
* Transactions
*/

View File

@ -49,15 +49,18 @@ interface mozIStorageStatementParams : nsISupports {
// magic interface for parameter setting that implements nsIXPCScriptable.
};
[scriptable, uuid(c9fc1259-a9ac-43da-912f-d321ebd0ff7a)]
[scriptable, uuid(eee6f7c9-5586-4eaf-b35c-dca987c4ffd1)]
interface mozIStorageStatementWrapper : nsISupports {
void initialize (in mozIStorageStatement aStatement);
readonly attribute mozIStorageStatement statement;
/**
* step, reset, and execute are passed down to the statement itself.
*/
void reset ();
boolean step ();
void execute ();
/**
* The current row. Throws an exception if no row is currently available.

View File

@ -39,7 +39,6 @@
#ifndef _MOZSTORAGE_H_
#define _MOZSTORAGE_H_
#define MOZ_ERROR_STORAGE_OPEN_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_STORAGE,1)
#define MOZ_ERROR_STORAGE_BUSY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_STORAGE,2)
#define MOZ_ERROR_STORAGE_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_STORAGE, 1)
#endif /* _MOZSTORAGE_H_ */

View File

@ -212,6 +212,41 @@ mozStorageConnection::ExecuteSimpleSQL(const nsACString& aSQLStatement)
return NS_OK;
}
NS_IMETHODIMP
mozStorageConnection::TableExists(const nsACString& aSQLStatement, PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(mDBConn);
nsCString query("SELECT name FROM sqlite_master WHERE type = 'table' AND name ='");
query.Append(aSQLStatement);
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("TableExists finalize");
return NS_ERROR_FAILURE;
}
*_retval = exists;
return NS_OK;
}
/**
** Transactions
**/

View File

@ -219,6 +219,15 @@ mozStorageStatementWrapper::Step(PRBool *_retval)
return rv;
}
NS_IMETHODIMP
mozStorageStatementWrapper::Execute()
{
if (!mStatement)
return NS_ERROR_FAILURE;
return mStatement->Execute();
}
NS_IMETHODIMP
mozStorageStatementWrapper::GetRow(mozIStorageStatementRow **aRow)
{