summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-06-12 16:06:03 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-06-12 16:06:03 -0700
commitfdcac45b6767caaac70c30fd974dce61119f79d7 (patch)
treedaade53b3f586f32411689e357574d9e0fad5ce3
parent4d6a0df37930309f8e138499785483d9dcadf7d9 (diff)
parentca309f212d560673276aec0f4168a6c56131260c (diff)
downloadframeworks_base-fdcac45b6767caaac70c30fd974dce61119f79d7.zip
frameworks_base-fdcac45b6767caaac70c30fd974dce61119f79d7.tar.gz
frameworks_base-fdcac45b6767caaac70c30fd974dce61119f79d7.tar.bz2
Merge "Print extended SQLite error code." into jb-dev
-rw-r--r--core/jni/android_database_SQLiteCommon.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/core/jni/android_database_SQLiteCommon.cpp b/core/jni/android_database_SQLiteCommon.cpp
index 46009bd..eefcb74 100644
--- a/core/jni/android_database_SQLiteCommon.cpp
+++ b/core/jni/android_database_SQLiteCommon.cpp
@@ -16,6 +16,8 @@
#include "android_database_SQLiteCommon.h"
+#include <utils/String8.h>
+
namespace android {
/* throw a SQLiteException with a message appropriate for the error in handle */
@@ -37,7 +39,8 @@ void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message)
// the error message may contain more information than the error code
// because it is based on the extended error code rather than the simplified
// error code that SQLite normally returns.
- throw_sqlite3_exception(env, sqlite3_errcode(handle), sqlite3_errmsg(handle), message);
+ throw_sqlite3_exception(env, sqlite3_extended_errcode(handle),
+ sqlite3_errmsg(handle), message);
} else {
// we use SQLITE_OK so that a generic SQLiteException is thrown;
// any code not specified in the switch statement below would do.
@@ -49,9 +52,7 @@ void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message)
* should only be used when the database connection is not available because the
* error information will not be quite as rich */
void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* message) {
- char temp[21];
- sprintf(temp, "error code %d", errcode);
- throw_sqlite3_exception(env, errcode, temp, message);
+ throw_sqlite3_exception(env, errcode, "unknown error", message);
}
/* throw a SQLiteException for a given error code, sqlite3message, and
@@ -60,7 +61,7 @@ void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* messa
void throw_sqlite3_exception(JNIEnv* env, int errcode,
const char* sqlite3Message, const char* message) {
const char* exceptionClass;
- switch (errcode) {
+ switch (errcode & 0xff) { /* mask off extended error code */
case SQLITE_IOERR:
exceptionClass = "android/database/sqlite/SQLiteDiskIOException";
break;
@@ -119,19 +120,15 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode,
break;
}
- if (sqlite3Message != NULL && message != NULL) {
- char* fullMessage = (char *)malloc(strlen(sqlite3Message) + strlen(message) + 3);
- if (fullMessage != NULL) {
- strcpy(fullMessage, sqlite3Message);
- strcat(fullMessage, ": ");
- strcat(fullMessage, message);
- jniThrowException(env, exceptionClass, fullMessage);
- free(fullMessage);
- } else {
- jniThrowException(env, exceptionClass, sqlite3Message);
+ if (sqlite3Message) {
+ String8 fullMessage;
+ fullMessage.append(sqlite3Message);
+ fullMessage.appendFormat(" (code %d)", errcode); // print extended error code
+ if (message) {
+ fullMessage.append(": ");
+ fullMessage.append(message);
}
- } else if (sqlite3Message != NULL) {
- jniThrowException(env, exceptionClass, sqlite3Message);
+ jniThrowException(env, exceptionClass, fullMessage.string());
} else {
jniThrowException(env, exceptionClass, message);
}