am fdcac45b: Merge "Print extended SQLite error code." into jb-dev
* commit 'fdcac45b6767caaac70c30fd974dce61119f79d7': Print extended SQLite error code.
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "android_database_SQLiteCommon.h"
|
#include "android_database_SQLiteCommon.h"
|
||||||
|
|
||||||
|
#include <utils/String8.h>
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
/* throw a SQLiteException with a message appropriate for the error in handle */
|
/* 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
|
// the error message may contain more information than the error code
|
||||||
// because it is based on the extended error code rather than the simplified
|
// because it is based on the extended error code rather than the simplified
|
||||||
// error code that SQLite normally returns.
|
// 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 {
|
} else {
|
||||||
// we use SQLITE_OK so that a generic SQLiteException is thrown;
|
// we use SQLITE_OK so that a generic SQLiteException is thrown;
|
||||||
// any code not specified in the switch statement below would do.
|
// 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
|
* should only be used when the database connection is not available because the
|
||||||
* error information will not be quite as rich */
|
* error information will not be quite as rich */
|
||||||
void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* message) {
|
void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* message) {
|
||||||
char temp[21];
|
throw_sqlite3_exception(env, errcode, "unknown error", message);
|
||||||
sprintf(temp, "error code %d", errcode);
|
|
||||||
throw_sqlite3_exception(env, errcode, temp, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* throw a SQLiteException for a given error code, sqlite3message, and
|
/* 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,
|
void throw_sqlite3_exception(JNIEnv* env, int errcode,
|
||||||
const char* sqlite3Message, const char* message) {
|
const char* sqlite3Message, const char* message) {
|
||||||
const char* exceptionClass;
|
const char* exceptionClass;
|
||||||
switch (errcode) {
|
switch (errcode & 0xff) { /* mask off extended error code */
|
||||||
case SQLITE_IOERR:
|
case SQLITE_IOERR:
|
||||||
exceptionClass = "android/database/sqlite/SQLiteDiskIOException";
|
exceptionClass = "android/database/sqlite/SQLiteDiskIOException";
|
||||||
break;
|
break;
|
||||||
@@ -119,19 +120,15 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlite3Message != NULL && message != NULL) {
|
if (sqlite3Message) {
|
||||||
char* fullMessage = (char *)malloc(strlen(sqlite3Message) + strlen(message) + 3);
|
String8 fullMessage;
|
||||||
if (fullMessage != NULL) {
|
fullMessage.append(sqlite3Message);
|
||||||
strcpy(fullMessage, sqlite3Message);
|
fullMessage.appendFormat(" (code %d)", errcode); // print extended error code
|
||||||
strcat(fullMessage, ": ");
|
if (message) {
|
||||||
strcat(fullMessage, message);
|
fullMessage.append(": ");
|
||||||
jniThrowException(env, exceptionClass, fullMessage);
|
fullMessage.append(message);
|
||||||
free(fullMessage);
|
|
||||||
} else {
|
|
||||||
jniThrowException(env, exceptionClass, sqlite3Message);
|
|
||||||
}
|
}
|
||||||
} else if (sqlite3Message != NULL) {
|
jniThrowException(env, exceptionClass, fullMessage.string());
|
||||||
jniThrowException(env, exceptionClass, sqlite3Message);
|
|
||||||
} else {
|
} else {
|
||||||
jniThrowException(env, exceptionClass, message);
|
jniThrowException(env, exceptionClass, message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user