Bug 451815 - Need a more reliable way to indicate SQLITE_BUSY
This changeset adds a new error result for storage (NS_ERROR_STORAGE_BUSY) that
maps directly to when SQLite would return SQLITE_BUSY.
r=asuth
--- a/storage/public/Makefile.in
+++ b/storage/public/Makefile.in
@@ -62,11 +62,12 @@ XPIDLSRCS = \
mozIStorageRow.idl \
mozIStorageError.idl \
mozIStorageStatementCallback.idl \
mozIStoragePendingStatement.idl \
$(NULL)
EXPORTS = \
mozStorageHelper.h \
+ mozStorage.h \
$(NULL)
include $(topsrcdir)/config/rules.mk
--- a/storage/public/mozStorage.h
+++ b/storage/public/mozStorage.h
@@ -34,11 +34,14 @@
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _MOZSTORAGE_H_
#define _MOZSTORAGE_H_
-#define MOZ_ERROR_STORAGE_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_STORAGE, 1)
+#include "sqlite3.h"
+
+#define NS_ERROR_STORAGE_BUSY \
+ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_STORAGE, SQLITE_BUSY)
#endif /* _MOZSTORAGE_H_ */
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -56,17 +56,17 @@
#include "mozIStorageFunction.h"
#include "mozStorageEvents.h"
#include "mozStorageUnicodeFunctions.h"
#include "mozStorageConnection.h"
#include "mozStorageService.h"
#include "mozStorageStatement.h"
#include "mozStorageValueArray.h"
-#include "mozStorage.h"
+#include "mozStoragePrivateHelpers.h"
#include "prlog.h"
#include "prprf.h"
#ifdef PR_LOGGING
PRLogModuleInfo* gStorageLog = nsnull;
#endif
rename from storage/src/mozStorage.h
rename to storage/src/mozStoragePrivateHelpers.h
--- a/storage/src/mozStorage.h
+++ b/storage/src/mozStoragePrivateHelpers.h
@@ -33,18 +33,20 @@
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
-#ifndef _MOZSTORAGE_H_
-#define _MOZSTORAGE_H_
+#ifndef _MOZSTORAGEPRIVATEHELPERS_H_
+#define _MOZSTORAGEPRIVATEHELPERS_H_
+
+#include "mozStorage.h"
/**
* This file contains convenience methods for mozStorage.
*/
/**
* Converts a SQLite return code to an nsresult return code.
*
@@ -61,16 +63,17 @@ ConvertResultCode(int srv)
return NS_OK;
case SQLITE_CORRUPT:
case SQLITE_NOTADB:
return NS_ERROR_FILE_CORRUPTED;
case SQLITE_PERM:
case SQLITE_CANTOPEN:
return NS_ERROR_FILE_ACCESS_DENIED;
case SQLITE_BUSY:
+ return NS_ERROR_STORAGE_BUSY;
case SQLITE_LOCKED:
return NS_ERROR_FILE_IS_LOCKED;
case SQLITE_READONLY:
return NS_ERROR_FILE_READ_ONLY;
case SQLITE_FULL:
case SQLITE_TOOBIG:
return NS_ERROR_FILE_NO_DEVICE_SPACE;
case SQLITE_NOMEM:
@@ -81,10 +84,10 @@ ConvertResultCode(int srv)
case SQLITE_INTERRUPT:
return NS_ERROR_ABORT;
}
// generic error
return NS_ERROR_FAILURE;
}
-#endif // _MOZSTORAGE_H_
+#endif // _MOZSTORAGEPRIVATEHELPERS_H_
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -41,17 +41,17 @@
#include "mozStorageService.h"
#include "mozStorageConnection.h"
#include "nsCRT.h"
#include "plstr.h"
#include "prinit.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h"
-#include "mozStorage.h"
+#include "mozStoragePrivateHelpers.h"
#include "sqlite3.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(mozStorageService, mozIStorageService)
mozStorageService *mozStorageService::gStorageService = nsnull;
mozStorageService *
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -47,17 +47,17 @@
#include "nsMemory.h"
#include "nsIClassInfoImpl.h"
#include "nsIProgrammingLanguage.h"
#include "mozStorageConnection.h"
#include "mozStorageStatement.h"
#include "mozStorageStatementJSHelper.h"
#include "mozStorageValueArray.h"
-#include "mozStorage.h"
+#include "mozStoragePrivateHelpers.h"
#include "mozStorageEvents.h"
#include "prlog.h"
#ifdef PR_LOGGING
extern PRLogModuleInfo* gStorageLog;
#endif
@@ -557,17 +557,16 @@ mozStorageStatement::ExecuteStep(PRBool
return NS_OK;
} else if (srv == SQLITE_DONE) {
// statement is done (no row returned)
mExecuting = PR_FALSE;
*_retval = PR_FALSE;
return NS_OK;
} else if (srv == SQLITE_BUSY || srv == SQLITE_MISUSE) {
mExecuting = PR_FALSE;
- return NS_ERROR_FAILURE;
} else if (mExecuting == PR_TRUE) {
#ifdef PR_LOGGING
PR_LOG(gStorageLog, PR_LOG_ERROR, ("SQLite error after mExecuting was true!"));
#endif
mExecuting = PR_FALSE;
}
return ConvertResultCode(srv);