@@ -85,7 +85,7 @@ namespace sqlcipher {
8585 {
8686 int value;
8787 int highWater;
88- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
88+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
8989 int status = sqlite3_status (operation, &value, &highWater, reset);
9090 if (status != SQLITE_OK){
9191 throw_sqlite3_exception (env, handle);
@@ -99,7 +99,10 @@ namespace sqlcipher {
9999 jsize size = 0 ;
100100 jbyte *key = 0 ;
101101 sqlite3 *handle = NULL ;
102- handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
102+ handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
103+ if (handle == NULL ){
104+ LOGE (" env->GetLongField returned NULL when retrieving sqlite3 *\n " );
105+ }
103106 key = env->GetByteArrayElements (jKey, NULL );
104107 size = env->GetArrayLength (jKey);
105108 if (key == NULL || size == 0 ) goto done;
@@ -116,7 +119,7 @@ namespace sqlcipher {
116119 jsize size = 0 ;
117120 jbyte *key = 0 ;
118121 sqlite3 *handle = NULL ;
119- handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
122+ handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
120123 key = env->GetByteArrayElements (jKey, NULL );
121124 size = env->GetArrayLength (jKey);
122125 if (key == NULL || size == 0 ) goto done;
@@ -133,7 +136,7 @@ namespace sqlcipher {
133136 int idx;
134137 jint releaseElements = 0 ;
135138 jboolean arrayIsCopy;
136- sqlite3 *handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
139+ sqlite3 *handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
137140 jsize sz = env->GetArrayLength (jKey);
138141 jchar* jKeyChar = env->GetCharArrayElements (jKey, &arrayIsCopy);
139142 jstring key = env->NewString (jKeyChar, sz);
@@ -151,7 +154,7 @@ namespace sqlcipher {
151154
152155 void native_rawExecSQL (JNIEnv* env, jobject object, jstring sql)
153156 {
154- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
157+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
155158 char const * sqlCommand = env->GetStringUTFChars (sql, NULL );
156159 int status = sqlite3_exec (handle, sqlCommand, NULL , NULL , NULL );
157160 env->ReleaseStringUTFChars (sql, sqlCommand);
@@ -244,7 +247,7 @@ namespace sqlcipher {
244247 sqlite3_enable_load_extension (handle, 1 );
245248
246249 LOGV (" Opened '%s' - %p\n " , path8, handle);
247- env->SetIntField (object, offset_db_handle, (int ) handle);
250+ env->SetLongField (object, offset_db_handle, (intptr_t ) handle);
248251 handle = NULL ; // The caller owns the handle now.
249252
250253 done:
@@ -272,7 +275,7 @@ namespace sqlcipher {
272275 /* public native void enableSqlTracing(); */
273276 static void enableSqlTracing (JNIEnv* env, jobject object, jstring databaseName)
274277 {
275- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
278+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
276279 sqlite3_trace (handle, &sqlTrace, (void *)getDatabaseName (env, handle, databaseName));
277280 }
278281
@@ -284,15 +287,15 @@ namespace sqlcipher {
284287 /* public native void enableSqlProfiling(); */
285288 static void enableSqlProfiling (JNIEnv* env, jobject object, jstring databaseName)
286289 {
287- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
290+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
288291 sqlite3_profile (handle, &sqlProfile, (void *)getDatabaseName (env, handle, databaseName));
289292 }
290293
291294
292295 /* public native void close(); */
293296 static void dbclose (JNIEnv* env, jobject object)
294297 {
295- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
298+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
296299
297300 if (handle != NULL ) {
298301 // release the memory associated with the traceFuncArg in enableSqlTracing function
@@ -309,7 +312,7 @@ namespace sqlcipher {
309312 int result = sqlite3_close (handle);
310313 if (result == SQLITE_OK) {
311314 LOGV (" Closed %p\n " , handle);
312- env->SetIntField (object, offset_db_handle, 0 );
315+ env->SetLongField (object, offset_db_handle, 0 );
313316 } else {
314317 // This can happen if sub-objects aren't closed first. Make sure the caller knows.
315318 LOGE (" sqlite3_close(%p) failed: %d\n " , handle, result);
@@ -324,7 +327,7 @@ namespace sqlcipher {
324327 int err;
325328 int stepErr;
326329 sqlite3_stmt * statement = NULL ;
327- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
330+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
328331 jchar const * sql = env->GetStringChars (sqlString, NULL );
329332 jsize sqlLen = env->GetStringLength (sqlString);
330333
@@ -372,23 +375,23 @@ namespace sqlcipher {
372375 /* native long lastInsertRow(); */
373376 static jlong lastInsertRow (JNIEnv* env, jobject object)
374377 {
375- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
378+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
376379
377380 return sqlite3_last_insert_rowid (handle);
378381 }
379382
380383 /* native int lastChangeCount(); */
381384 static jint lastChangeCount (JNIEnv* env, jobject object)
382385 {
383- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
386+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
384387
385388 return sqlite3_changes (handle);
386389 }
387390
388391 /* native int native_getDbLookaside(); */
389392 static jint native_getDbLookaside (JNIEnv* env, jobject object)
390393 {
391- sqlite3 * handle = (sqlite3 *)env->GetIntField (object, offset_db_handle);
394+ sqlite3 * handle = (sqlite3 *)env->GetLongField (object, offset_db_handle);
392395 int pCur = -1 ;
393396 int unused;
394397 sqlite3_db_status (handle, SQLITE_DBSTATUS_LOOKASIDE_USED, &pCur, &unused, 0 );
@@ -550,7 +553,7 @@ namespace sqlcipher {
550553 return -1 ;
551554 }
552555
553- offset_db_handle = env->GetFieldID (clazz, " mNativeHandle" , " I " );
556+ offset_db_handle = env->GetFieldID (clazz, " mNativeHandle" , " J " );
554557 if (offset_db_handle == NULL ) {
555558 LOGE (" Can't find SQLiteDatabase.mNativeHandle\n " );
556559 return -1 ;
0 commit comments