1

to add a UDF in SQLlite/Android How to load extensions into SQLite? first sqlite3_enable_load_extension must be done to prevent from 'unauthorized access' I did in myfunc.c

#include <sqlite3.h>
#include <jni.h>
#include <stdlib.h>

jstring
Java_com_test_abc_SQLiteOpenHelper_enableExtension(JNIEnv* env, jobject thiz, sqlite3 *db)
{
    sqlite3_enable_load_extension(db, 1); //errorline, without any infos
    return (*env)->NewStringUTF(env, "enableExtension done");
}

java

package com.test.abc;
....
public class MyOpenHelper extends SQLiteOpenHelper {
    ...
    @Override
    public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
        enableExtension(db);
    }
    public native String enableExtension(SQLiteDatabase db);
}

without success. The JNI call from Java to C comes never back, without errorline it works. Has anyone a clue what is going wrong here? Best with code example.

Community
  • 1
  • 1
hannes ach
  • 16,247
  • 7
  • 61
  • 84

1 Answers1

0

From Java you get sqlite db that is created/initialized with Android integrated sqlite lib. Then you pass it to jni code that is working with your custom sqlite lib that is not the same version and this db connection is not initialized with it. Even if it worked, you would set the flag on your custom sqlib, but not on Android integrated lib. You have to work with your custom lib all the way, change the package as instructed here: http://www.sqlite.org/android/doc/trunk/www/index.wiki

pera
  • 882
  • 11
  • 21