mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Bind sqlite3_strlike/strglob() to JNI.
FossilOrigin-Name: eb5440f71be32812f6310756b8e30958002e8e8e41a7eb16f081058ff733b47c
This commit is contained in:
@ -543,6 +543,11 @@ static struct {
|
||||
#endif
|
||||
} S3JniGlobal;
|
||||
|
||||
#define OOM_CHECK(VAR) if(!(VAR)) s3jni_oom(env)
|
||||
static void s3jni_oom(JNIEnv * const env){
|
||||
(*env)->FatalError(env, "Out of memory.") /* does not return */;
|
||||
}
|
||||
|
||||
/**
|
||||
sqlite3_malloc() proxy which fails fatally on OOM. This should
|
||||
only be used for routines which manage global state and have no
|
||||
@ -551,9 +556,7 @@ static struct {
|
||||
*/
|
||||
static void * s3jni_malloc(JNIEnv * const env, size_t n){
|
||||
void * const rv = sqlite3_malloc(n);
|
||||
if(n && !rv){
|
||||
(*env)->FatalError(env, "Out of memory.") /* does not return */;
|
||||
}
|
||||
if(n && !rv) s3jni_oom(env);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -3056,6 +3059,27 @@ JDECL(void,1set_1last_1insert_1rowid)(JENV_CSELF, jobject jpDb, jlong rowId){
|
||||
(sqlite3_int64)rowId);
|
||||
}
|
||||
|
||||
static int s3jni_strlike_glob(int isLike, JNIEnv *const env,
|
||||
jbyteArray baG, jbyteArray baT){
|
||||
int rc = 0;
|
||||
jbyte * const pG = JBA_TOC(baG);
|
||||
jbyte * const pT = pG ? JBA_TOC(baT) : 0;
|
||||
|
||||
OOM_CHECK(pT);
|
||||
rc = sqlite3_strglob((const char *)pG, (const char *)pT);
|
||||
JBA_RELEASE(baG, pG);
|
||||
JBA_RELEASE(baT, pT);
|
||||
return rc;
|
||||
}
|
||||
|
||||
JDECL(int,1strglob)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
|
||||
return s3jni_strlike_glob(0, env, baG, baT);
|
||||
}
|
||||
|
||||
JDECL(int,1strlike)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
|
||||
return s3jni_strlike_glob(1, env, baG, baT);
|
||||
}
|
||||
|
||||
JDECL(jint,1shutdown)(JENV_CSELF){
|
||||
S3JniGlobal_S3JniEnvCache_clear();
|
||||
/* Do not clear S3JniGlobal.jvm: it's legal to call
|
||||
|
@ -1459,6 +1459,22 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1sourceid
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1step
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_strglob
|
||||
* Signature: ([B[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strglob
|
||||
(JNIEnv *, jclass, jbyteArray, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_strlike
|
||||
* Signature: ([B[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strlike
|
||||
(JNIEnv *, jclass, jbyteArray, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_threadsafe
|
||||
|
@ -850,6 +850,24 @@ public final class SQLite3Jni {
|
||||
|
||||
public static native int sqlite3_step(@NotNull sqlite3_stmt stmt);
|
||||
|
||||
private static native int sqlite3_strglob(@NotNull byte[] glob, @NotNull byte[] txt);
|
||||
|
||||
public static int sqlite3_strglob(@NotNull String glob, @NotNull String txt){
|
||||
return sqlite3_strglob(
|
||||
glob.getBytes(StandardCharsets.UTF_8),
|
||||
txt.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
private static native int sqlite3_strlike(@NotNull byte[] glob, @NotNull byte[] txt);
|
||||
|
||||
public static int sqlite3_strlike(@NotNull String glob, @NotNull String txt){
|
||||
return sqlite3_strlike(
|
||||
glob.getBytes(StandardCharsets.UTF_8),
|
||||
txt.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
}
|
||||
|
||||
public static native int sqlite3_threadsafe();
|
||||
|
||||
public static native int sqlite3_total_changes(@NotNull sqlite3 db);
|
||||
|
Reference in New Issue
Block a user