1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Export the sqlite3_keyword_...() family of functions to JNI.

FossilOrigin-Name: bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7
This commit is contained in:
stephan
2023-09-03 09:28:45 +00:00
parent de4d1c357f
commit 2966b85df3
6 changed files with 84 additions and 12 deletions

View File

@ -2061,6 +2061,7 @@ WRAP_INT_DB(1error_1offset, sqlite3_error_offset)
WRAP_INT_DB(1extended_1errcode, sqlite3_extended_errcode)
WRAP_MUTF8_VOID(1libversion, sqlite3_libversion)
WRAP_INT_VOID(1libversion_1number, sqlite3_libversion_number)
WRAP_INT_VOID(1keyword_1count, sqlite3_keyword_count)
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
WRAP_INT_DB(1preupdate_1blobwrite, sqlite3_preupdate_blobwrite)
WRAP_INT_DB(1preupdate_1count, sqlite3_preupdate_count)
@ -2398,7 +2399,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)(
rc = sqlite3_busy_handler(ps->pDb, s3jni_busy_handler, ps);
if( 0==rc ){
S3JniHook_unref(pHook);
*pHook = hook;
*pHook = hook /* transfer Java ref ownership */;
hook = S3JniHook_empty;
}
}/* else no-op */
@ -3307,6 +3308,34 @@ JniDecl(jboolean,1java_1uncache_1thread)(JniArgsEnvClass){
return rc ? JNI_TRUE : JNI_FALSE;
}
S3JniApi(sqlite3_keyword_check(),jboolean,1keyword_1check)(
JniArgsEnvClass, jstring jWord
){
int nWord = 0;
char * zWord = s3jni_jstring_to_utf8(jWord, &nWord);
int rc = 0;
s3jni_oom_check(jWord ? !!zWord : 1);
if( zWord && nWord ){
rc = sqlite3_keyword_check(zWord, nWord);
}
sqlite3_free(zWord);
return rc ? JNI_TRUE : JNI_FALSE;
}
S3JniApi(sqlite3_keyword_name(),jstring,1keyword_1name)(
JniArgsEnvClass, jint ndx
){
const char * zWord = 0;
int n = 0;
jstring rv = 0;
if( 0==sqlite3_keyword_name(ndx, &zWord, &n) ){
rv = s3jni_utf8_to_jstring(zWord, n);
}
return rv;
}
S3JniApi(sqlite3_last_insert_rowid(),jlong,1last_1insert_1rowid)(
JniArgsEnvClass, jobject jpDb

View File

@ -1323,6 +1323,30 @@ JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1interrupt
JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1is_1interrupted
(JNIEnv *, jclass, jobject);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_keyword_check
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1check
(JNIEnv *, jclass, jstring);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_keyword_count
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1count
(JNIEnv *, jclass);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_keyword_name
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1name
(JNIEnv *, jclass, jint);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_last_insert_rowid

View File

@ -543,7 +543,6 @@ public final class SQLite3Jni {
<p>Note that sqlite3_config() is not threadsafe with regards to
the rest of the library. This must not be called when any other
library APIs are being called.
*/
@Canonical(comment="Option subset: "+
"SQLITE_CONFIG_SINGLETHREAD, SQLITE_CONFIG_MULTITHREAD, "+
@ -682,6 +681,16 @@ public final class SQLite3Jni {
@Canonical
public static native boolean sqlite3_is_interrupted(@NotNull sqlite3 db);
@Canonical
public static native boolean sqlite3_keyword_check(@NotNull String word);
@Canonical
public static native int sqlite3_keyword_count();
@Canonical
public static native String sqlite3_keyword_name(int index);
@Canonical
public static native long sqlite3_last_insert_rowid(@NotNull sqlite3 db);

View File

@ -1478,6 +1478,16 @@ public class Tester1 implements Runnable {
affirm( 0!=sqlite3_complete("nope 'nope' 'nope' 1;"), "Yup" );
}
private void testKeyword(){
final int n = sqlite3_keyword_count();
affirm( n>0 );
affirm( !sqlite3_keyword_check("_nope_") );
affirm( sqlite3_keyword_check("seLect") );
affirm( null!=sqlite3_keyword_name(0) );
affirm( null!=sqlite3_keyword_name(n-1) );
affirm( null==sqlite3_keyword_name(n) );
}
/* Copy/paste/rename this to add new tests. */
private void _testTemplate(){
final sqlite3 db = createNewDb();