diff options
author | Vasu Nori <vnori@google.com> | 2010-07-25 16:38:48 -0700 |
---|---|---|
committer | Vasu Nori <vnori@google.com> | 2010-07-26 13:00:07 -0700 |
commit | fb16cbd9b2e86d6878d4bff820422bc09c8938de (patch) | |
tree | 4bbcf44b1a14a7bdff5ce13cce5cb3eff2ac056c /core/jni/android_database_SQLiteStatement.cpp | |
parent | 037644fbe424315c5a3e9706453ce97413d636ff (diff) | |
download | frameworks_base-fb16cbd9b2e86d6878d4bff820422bc09c8938de.zip frameworks_base-fb16cbd9b2e86d6878d4bff820422bc09c8938de.tar.gz frameworks_base-fb16cbd9b2e86d6878d4bff820422bc09c8938de.tar.bz2 |
add new API in SQLiteStatement to deprecate another.
1. SQLIteStatement.executeUpdateDelete() replaces execute() - and returns the
number of rows changed.
2. let SQLiteDatabase.execSQL() call the above new API - which
means all CRUD statements by execSQL() are stored in prepared statement cache.
3. remove the following from SQLiteDatabase
lastrowId
lastchangecount()
native_execSQL()
Change-Id: I4e93a09dc381f425c3ae6ccc331a7bf227491e22
Diffstat (limited to 'core/jni/android_database_SQLiteStatement.cpp')
-rw-r--r-- | core/jni/android_database_SQLiteStatement.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/core/jni/android_database_SQLiteStatement.cpp b/core/jni/android_database_SQLiteStatement.cpp index 0341e0b..2212d9a 100644 --- a/core/jni/android_database_SQLiteStatement.cpp +++ b/core/jni/android_database_SQLiteStatement.cpp @@ -16,7 +16,7 @@ */ #undef LOG_TAG -#define LOG_TAG "Cursor" +#define LOG_TAG "SQLiteStatementCpp" #include <jni.h> #include <JNIHelp.h> @@ -48,24 +48,40 @@ static jfieldID gStatementField; (sqlite3 *)env->GetIntField(object, gHandleField) -static void native_execute(JNIEnv* env, jobject object) +static jint native_execute(JNIEnv* env, jobject object) { int err; sqlite3 * handle = GET_HANDLE(env, object); sqlite3_stmt * statement = GET_STATEMENT(env, object); + int numChanges = -1; // Execute the statement err = sqlite3_step(statement); - // Throw an exception if an error occured + // Throw an exception if an error occurred if (err == SQLITE_ROW) { - LOGV("Queries cannot be performed using execute(). use SQLiteDatabase.query() instead."); + 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(handle)); + } else { + numChanges = sqlite3_changes(handle); } - // Reset the statment so it's ready to use again + // Reset the statement so it's ready to use again sqlite3_reset(statement); + return numChanges; +} + +static jlong native_executeInsert(JNIEnv* env, jobject object) +{ + sqlite3 * handle = GET_HANDLE(env, object); + jint numChanges = native_execute(env, object); + if (numChanges > 0) { + return sqlite3_last_insert_rowid(handle); + } else { + return -1; + } } static jlong native_1x1_long(JNIEnv* env, jobject object) @@ -117,11 +133,11 @@ static jstring native_1x1_string(JNIEnv* env, jobject object) return value; } - static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ - {"native_execute", "()V", (void *)native_execute}, + {"native_execute", "()I", (void *)native_execute}, + {"native_executeInsert", "()J", (void *)native_executeInsert}, {"native_1x1_long", "()J", (void *)native_1x1_long}, {"native_1x1_string", "()Ljava/lang/String;", (void *)native_1x1_string}, }; |