summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/jni/android_database_SQLiteCommon.cpp22
-rw-r--r--core/jni/android_database_SQLiteConnection.cpp4
2 files changed, 14 insertions, 12 deletions
diff --git a/core/jni/android_database_SQLiteCommon.cpp b/core/jni/android_database_SQLiteCommon.cpp
index 06bff19ce42a..46009bde75a8 100644
--- a/core/jni/android_database_SQLiteCommon.cpp
+++ b/core/jni/android_database_SQLiteCommon.cpp
@@ -33,8 +33,11 @@ void throw_sqlite3_exception(JNIEnv* env, const char* message) {
*/
void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message) {
if (handle) {
- throw_sqlite3_exception(env, sqlite3_errcode(handle),
- sqlite3_errmsg(handle), message);
+ // get the error code and message from the SQLite connection
+ // 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);
} else {
// we use SQLITE_OK so that a generic SQLiteException is thrown;
// any code not specified in the switch statement below would do.
@@ -42,15 +45,13 @@ void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message)
}
}
-/* throw a SQLiteException for a given error code */
+/* throw a SQLiteException for a given error code
+ * 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) {
- if (errcode == SQLITE_DONE) {
- throw_sqlite3_exception(env, errcode, NULL, message);
- } else {
- char temp[21];
- sprintf(temp, "error code %d", errcode);
- throw_sqlite3_exception(env, errcode, temp, message);
- }
+ char temp[21];
+ sprintf(temp, "error code %d", errcode);
+ throw_sqlite3_exception(env, errcode, temp, message);
}
/* throw a SQLiteException for a given error code, sqlite3message, and
@@ -75,6 +76,7 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode,
break;
case SQLITE_DONE:
exceptionClass = "android/database/sqlite/SQLiteDoneException";
+ sqlite3Message = NULL; // SQLite error message is irrelevant in this case
break;
case SQLITE_FULL:
exceptionClass = "android/database/sqlite/SQLiteFullException";
diff --git a/core/jni/android_database_SQLiteConnection.cpp b/core/jni/android_database_SQLiteConnection.cpp
index 3bbb8bf819b5..c9cf2fa9c282 100644
--- a/core/jni/android_database_SQLiteConnection.cpp
+++ b/core/jni/android_database_SQLiteConnection.cpp
@@ -444,7 +444,7 @@ static int executeNonQuery(JNIEnv* env, SQLiteConnection* connection, sqlite3_st
throw_sqlite3_exception(env,
"Queries can be performed using SQLiteDatabase query or rawQuery methods only.");
} else if (err != SQLITE_DONE) {
- throw_sqlite3_exception_errcode(env, err, sqlite3_errmsg(connection->db));
+ throw_sqlite3_exception(env, connection->db);
}
return err;
}
@@ -479,7 +479,7 @@ static jlong nativeExecuteForLastInsertedRowId(JNIEnv* env, jclass clazz,
static int executeOneRowQuery(JNIEnv* env, SQLiteConnection* connection, sqlite3_stmt* statement) {
int err = sqlite3_step(statement);
if (err != SQLITE_ROW) {
- throw_sqlite3_exception_errcode(env, err, sqlite3_errmsg(connection->db));
+ throw_sqlite3_exception(env, connection->db);
}
return err;
}