/* The hand-written JNI shim: one C function per Java native method, with the marshalling done by hand. Header generated by `javac -h`; see scripts/build-jni.sh. */ #include #include #include #include "bench_SqliteJni.h" JNIEXPORT jint JNICALL Java_bench_SqliteJni_versionNumber(JNIEnv *env, jclass c) { return sqlite3_libversion_number(); } JNIEXPORT jint JNICALL Java_bench_SqliteJni_strlike(JNIEnv *env, jclass c, jstring glob, jstring text) { const char *g = (*env)->GetStringUTFChars(env, glob, NULL); const char *t = (*env)->GetStringUTFChars(env, text, NULL); int r = sqlite3_strlike(g, t, 0); (*env)->ReleaseStringUTFChars(env, text, t); (*env)->ReleaseStringUTFChars(env, glob, g); return r; } JNIEXPORT jlong JNICALL Java_bench_SqliteJni_open(JNIEnv *env, jclass c, jstring path) { const char *p = (*env)->GetStringUTFChars(env, path, NULL); sqlite3 *db = NULL; int rc = sqlite3_open(p, &db); (*env)->ReleaseStringUTFChars(env, path, p); return rc == SQLITE_OK ? (jlong)(intptr_t)db : 0; } JNIEXPORT jint JNICALL Java_bench_SqliteJni_exec(JNIEnv *env, jclass c, jlong db, jstring sql) { const char *s = (*env)->GetStringUTFChars(env, sql, NULL); int rc = sqlite3_exec((sqlite3 *)(intptr_t)db, s, NULL, NULL, NULL); (*env)->ReleaseStringUTFChars(env, sql, s); return rc; } JNIEXPORT jlong JNICALL Java_bench_SqliteJni_prepare(JNIEnv *env, jclass c, jlong db, jstring sql) { const char *s = (*env)->GetStringUTFChars(env, sql, NULL); sqlite3_stmt *st = NULL; int rc = sqlite3_prepare_v2((sqlite3 *)(intptr_t)db, s, -1, &st, NULL); (*env)->ReleaseStringUTFChars(env, sql, s); return rc == SQLITE_OK ? (jlong)(intptr_t)st : 0; } JNIEXPORT jint JNICALL Java_bench_SqliteJni_bindInt(JNIEnv *env, jclass c, jlong st, jint i, jint v) { return sqlite3_bind_int((sqlite3_stmt *)(intptr_t)st, i, v); } JNIEXPORT jint JNICALL Java_bench_SqliteJni_bindText(JNIEnv *env, jclass c, jlong st, jint i, jstring v) { const char *s = (*env)->GetStringUTFChars(env, v, NULL); int rc = sqlite3_bind_text((sqlite3_stmt *)(intptr_t)st, i, s, -1, SQLITE_TRANSIENT); (*env)->ReleaseStringUTFChars(env, v, s); return rc; } JNIEXPORT jint JNICALL Java_bench_SqliteJni_step(JNIEnv *env, jclass c, jlong st) { return sqlite3_step((sqlite3_stmt *)(intptr_t)st); } JNIEXPORT jint JNICALL Java_bench_SqliteJni_reset(JNIEnv *env, jclass c, jlong st) { return sqlite3_reset((sqlite3_stmt *)(intptr_t)st); } JNIEXPORT jint JNICALL Java_bench_SqliteJni_finalizeStmt(JNIEnv *env, jclass c, jlong st) { return sqlite3_finalize((sqlite3_stmt *)(intptr_t)st); } JNIEXPORT jint JNICALL Java_bench_SqliteJni_close(JNIEnv *env, jclass c, jlong db) { return sqlite3_close((sqlite3 *)(intptr_t)db); }