From bd29b7c2b7f6c4041b270599d4f0a8bbfb4d785b Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Thu, 4 Mar 2010 16:16:03 -0800 Subject: provide databasename to the logging func registration func this will allow sqlite to return this name, along with the message. otherwise, sqlite logging messages are confusing without database name to associate them with. --- core/jni/android_database_SQLiteDatabase.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'core/jni') diff --git a/core/jni/android_database_SQLiteDatabase.cpp b/core/jni/android_database_SQLiteDatabase.cpp index b93311b..bd55e83 100644 --- a/core/jni/android_database_SQLiteDatabase.cpp +++ b/core/jni/android_database_SQLiteDatabase.cpp @@ -63,19 +63,28 @@ enum { static jfieldID offset_db_handle; +static char *createStr(const char *path) { + int len = strlen(path); + char *str = (char *)malloc(len + 1); + strncpy(str, path, len); + str[len] = NULL; + return str; +} + static void sqlLogger(void *databaseName, int iErrCode, const char *zMsg) { - LOGI("sqlite returned: error code = %d, msg = %s\n", iErrCode, zMsg); + LOGI("sqlite returned: database = %s, error code = %d, msg = %s\n", + (char *)databaseName, iErrCode, zMsg); } // register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called. -static void registerLoggingFunc() { +static void registerLoggingFunc(const char *path) { static bool loggingFuncSet = false; if (loggingFuncSet) { return; } LOGV("Registering sqlite logging func \n"); - int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, 0); + int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, (void *)createStr(path)); if (err != SQLITE_OK) { LOGE("sqlite_config failed error_code = %d. THIS SHOULD NEVER occur.\n", err); return; @@ -93,7 +102,7 @@ static void dbopen(JNIEnv* env, jobject object, jstring pathString, jint flags) int sqliteFlags; // register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called. - registerLoggingFunc(); + registerLoggingFunc(path8); // convert our flags into the sqlite flags if (flags & CREATE_IF_NECESSARY) { @@ -172,10 +181,7 @@ static char *getDatabaseName(JNIEnv* env, sqlite3 * handle, jstring databaseName LOGE("Failure in getDatabaseName(). VM ran out of memory?\n"); return NULL; // VM would have thrown OutOfMemoryError } - int len = strlen(path); - char *dbNameStr = (char *)malloc(len + 1); - strncpy(dbNameStr, path, len); - dbNameStr[len-1] = NULL; + char *dbNameStr = createStr(path); env->ReleaseStringUTFChars(databaseName, path); return dbNameStr; } -- cgit v1.1