diff options
author | Vasu Nori <vnori@google.com> | 2010-03-04 16:16:03 -0800 |
---|---|---|
committer | Vasu Nori <vnori@google.com> | 2010-03-04 16:16:03 -0800 |
commit | bd29b7c2b7f6c4041b270599d4f0a8bbfb4d785b (patch) | |
tree | 8e182ce1eea4c71dedb6f389c182f0e23470fcb6 /core/jni | |
parent | fb3803a360531020ed605247cb26a476f1c379bd (diff) | |
download | frameworks_base-bd29b7c2b7f6c4041b270599d4f0a8bbfb4d785b.zip frameworks_base-bd29b7c2b7f6c4041b270599d4f0a8bbfb4d785b.tar.gz frameworks_base-bd29b7c2b7f6c4041b270599d4f0a8bbfb4d785b.tar.bz2 |
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.
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_database_SQLiteDatabase.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
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; } |