return rv;
}
+S3JniApi(sqlite3_complete(),int,1complete)(
+ JniArgsEnvClass, jbyteArray jSql
+){
+ jbyte * const pBuf = s3jni_jbytearray_bytes(jSql);
+ const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jSql) : 0;
+ int rc;
+
+ assert( (nBa>0 ? 0==pBuf[nBa-1] : (pBuf ? 0==*pBuf : 1))
+ && "Byte array is not NUL-terminated." );
+ rc = (pBuf && 0==pBuf[(nBa ? nBa-1 : 0)])
+ ? sqlite3_complete( (const char *)pBuf )
+ : (jSql ? SQLITE_NOMEM : SQLITE_ERROR);
+ s3jni_jbytearray_release(jSql, pBuf);
+ return rc;
+}
+
S3JniApi(sqlite3_compileoption_used(),jboolean,1compileoption_1used)(
JniArgsEnvClass, jstring name
){
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1collation_1needed
(JNIEnv *, jclass, jobject, jobject);
-/*
- * Class: org_sqlite_jni_SQLite3Jni
- * Method: sqlite3_context_db_handle
- * Signature: (Lorg/sqlite/jni/sqlite3_context;)Lorg/sqlite/jni/sqlite3;
- */
-JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1context_1db_1handle
- (JNIEnv *, jclass, jobject);
-
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_commit_hook
JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1compileoption_1used
(JNIEnv *, jclass, jstring);
+/*
+ * Class: org_sqlite_jni_SQLite3Jni
+ * Method: sqlite3_complete
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1complete
+ (JNIEnv *, jclass, jbyteArray);
+
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_config
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__Lorg_sqlite_jni_ConfigSqllogCallback_2
(JNIEnv *, jclass, jobject);
+/*
+ * Class: org_sqlite_jni_SQLite3Jni
+ * Method: sqlite3_context_db_handle
+ * Signature: (Lorg/sqlite/jni/sqlite3_context;)Lorg/sqlite/jni/sqlite3;
+ */
+JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1context_1db_1handle
+ (JNIEnv *, jclass, jobject);
+
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_create_collation
@NotNull sqlite3_stmt stmt, @NotNull byte[] paramName
);
+ @Canonical
public static int sqlite3_bind_parameter_index(
@NotNull sqlite3_stmt stmt, @NotNull String paramName
){
@NotNull sqlite3 db, @Nullable CollationNeededCallback callback
);
- @Canonical
- public static native sqlite3 sqlite3_context_db_handle(
- @NotNull sqlite3_context cx
- );
-
@Canonical
public static native CommitHookCallback sqlite3_commit_hook(
@NotNull sqlite3 db, @Nullable CommitHookCallback hook
@NotNull String optName
);
+ /**
+ This implementation is private because it's too easy to pass it
+ non-NUL-terminated arrays.
+ */
+ @Canonical
+ private static native int sqlite3_complete(
+ @NotNull byte[] nulTerminatedUtf8Sql
+ );
+
+ @Canonical()
+ public static int sqlite3_complete(@NotNull String sql){
+ /* Design note: we don't implement this in native code because we
+ won't get a NUL-terminated string there unless we make our own
+ copy to add a terminator. That's much easier to do here. */
+ return sqlite3_complete( (sql+"\0").getBytes(StandardCharsets.UTF_8) );
+ }
+
+
/**
<p>Works like in the C API with the exception that it only supports
the following subset of configution flags:
@Canonical(comment="Option subset: SQLITE_CONFIG_SQLLOG")
public static native int sqlite3_config( @Nullable ConfigSqllogCallback logger );
+ @Canonical
+ public static native sqlite3 sqlite3_context_db_handle(
+ @NotNull sqlite3_context cx
+ );
+
@Canonical
public static native int sqlite3_create_collation(
@NotNull sqlite3 db, @NotNull String name, int eTextRep,
<p>Several overloads provided simplified call signatures.
*/
+ @Canonical
public static int sqlite3_prepare(
@NotNull sqlite3 db, @NotNull byte[] sqlUtf8,
@NotNull OutputPointer.sqlite3_stmt outStmt,
output paramter is returned as the index offset into the given
byte array at which SQL parsing stopped.
*/
+ @Canonical
public static int sqlite3_prepare_v2(
@NotNull sqlite3 db, @NotNull byte[] sqlUtf8,
@NotNull OutputPointer.sqlite3_stmt outStmt,
output paramter is returned as the index offset into the given
byte array at which SQL parsing stopped.
*/
+ @Canonical
public static int sqlite3_prepare_v3(
@NotNull sqlite3 db, @NotNull byte[] sqlUtf8, int prepFlags,
@NotNull OutputPointer.sqlite3_stmt outStmt,
The main sqlite3_result_error() impl of which all others are
proxies. eTextRep must be one of SQLITE_UTF8 or SQLITE_UTF16 and
msg must be encoded correspondingly. Any other eTextRep value
- results in the C-level sqlite3_result_error() being called with
- a complaint about the invalid argument.
+ results in the C-level sqlite3_result_error() being called with a
+ complaint about the invalid argument.
*/
@Canonical
private static native void sqlite3_result_error(
@NotNull sqlite3_context cx, @NotNull byte[] msg, int eTextRep
);
+ @Canonical
public static void sqlite3_result_error(
@NotNull sqlite3_context cx, @NotNull byte[] utf8
){
sqlite3_result_error(cx, utf8, SQLITE_UTF8);
}
+ @Canonical
public static void sqlite3_result_error(
@NotNull sqlite3_context cx, @NotNull String msg
){
@NotNull sqlite3_context cx, @Nullable byte[] blob, int maxLen
);
+ @Canonical
public static void sqlite3_result_blob(
@NotNull sqlite3_context cx, @Nullable byte[] blob
){
@NotNull sqlite3_context cx, @Nullable byte[] blob, long maxLen
);
+ @Canonical
public static void sqlite3_result_blob64(
@NotNull sqlite3_context cx, @Nullable byte[] blob
){
@NotNull sqlite3_context cx, @Nullable byte[] utf8, int maxLen
);
+ @Canonical
public static void sqlite3_result_text(
@NotNull sqlite3_context cx, @Nullable byte[] utf8
){
sqlite3_result_text(cx, utf8, null==utf8 ? 0 : utf8.length);
}
+ @Canonical
public static void sqlite3_result_text(
@NotNull sqlite3_context cx, @Nullable String text
){
Sets the current UDF result to the given bytes, which are assumed
be encoded in UTF-16 using the platform's byte order.
*/
+ @Canonical
public static void sqlite3_result_text16(
@NotNull sqlite3_context cx, @Nullable byte[] utf16
){
sqlite3_result_text64(cx, utf16, utf16.length, SQLITE_UTF16);
}
+ @Canonical
public static void sqlite3_result_text16(
@NotNull sqlite3_context cx, @Nullable String text
){
*/
@Canonical
private static native int sqlite3_strglob(
- @NotNull byte[] glob, @NotNull byte[] txt
+ @NotNull byte[] glob, @NotNull byte[] nullTerminatedUtf8
);
+ @Canonical
public static int sqlite3_strglob(
@NotNull String glob, @NotNull String txt
){
*/
@Canonical
private static native int sqlite3_strlike(
- @NotNull byte[] glob, @NotNull byte[] txt, int escChar
+ @NotNull byte[] glob, @NotNull byte[] nullTerminatedUtf8,
+ int escChar
);
+ @Canonical
public static int sqlite3_strlike(
@NotNull String glob, @NotNull String txt, char escChar
){
sqlite3_close_v2(db);
}
+ private void testComplete(){
+ affirm( 0==sqlite3_complete("select 1") );
+ affirm( 0!=sqlite3_complete("select 1;") );
+ affirm( 0!=sqlite3_complete("nope 'nope' 'nope' 1;"), "Yup" );
+ }
+
/* Copy/paste/rename this to add new tests. */
private void _testTemplate(){
final sqlite3 db = createNewDb();
final fts5_extension_function func = new fts5_extension_function(){
@Override public void call(Fts5ExtensionApi ext, Fts5Context fCx,
sqlite3_context pCx, sqlite3_value argv[]){
- int nCols = ext.xColumnCount(fCx);
+ final int nCols = ext.xColumnCount(fCx);
affirm( 2 == nCols );
affirm( nCols == argv.length );
affirm( ext.xUserData(fCx) == pUserData );
final OutputPointer.String op = new OutputPointer.String();
+ final OutputPointer.Int32 colsz = new OutputPointer.Int32();
+ final OutputPointer.Int64 colTotalSz = new OutputPointer.Int64();
for(int i = 0; i < nCols; ++i ){
int rc = ext.xColumnText(fCx, i, op);
affirm( 0 == rc );
final String val = op.value;
affirm( val.equals(sqlite3_value_text16(argv[i])) );
+ rc = ext.xColumnSize(fCx, i, colsz);
+ affirm( 0==rc );
+ affirm( 3==sqlite3_value_bytes(argv[i]) );
+ rc = ext.xColumnTotalSize(fCx, i, colTotalSz);
+ affirm( 0==rc );
}
++xFuncCount.value;
}
same semantics as their counterparts in <a
href="https://sqlite.org/c3ref/intro.html">the C API
documentation</a>, despite their signatures perhaps differing
- slightly. The Java API adds a number of overloads to simplify use,
- as well as a few Java-specific functions, and those are never
- flagged as @Canonical.
+ slightly. Canonical forms may be native or implemented in Java.
+ Sometimes multiple overloads are labeled as Canonical because one
+ or more of them are just type- or encoding-related conversion
+ wrappers but provide identical semantics (e.g. from a String to a
+ byte[]). The Java API adds a number of convenience overloads to
+ simplify use, as well as a few Java-specific functions, and those
+ are never flagged as @Canonical.
<p>In some cases, the canonical version of a function is private
and exposed to Java via public overloads.
-C Duplicate\scode\sconsolidation.
-D 2023-09-02T11:26:36.375
+C Expose\ssqlite3_complete()\sto\sJNI.\sSlightly\swiden\sthe\sdefinition\sof\s"canonical"\sfor\sthe\spurposes\sof\sthe\s@Canonical\sannotation.\sAdd\sa\sfew\snew\stests.
+D 2023-09-02T12:53:25.655
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e
F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9
F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
-F ext/jni/src/c/sqlite3-jni.c 2b274355058b64edb76cbbec8f6459ea977f56bf648becd8c4dba96b9c5147ec
-F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1
+F ext/jni/src/c/sqlite3-jni.c 88e7ced81dcb82200b16cebf6d67564c3844f9af1c17717a94afda38793b7a08
+F ext/jni/src/c/sqlite3-jni.h eed8d955de3b55c50242d44104f3f5bf299625f69b97e747541509c04019c9ce
F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436
F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4
F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38
F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86
F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4
F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c
-F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd
+F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 900c43e4789a0faf822febdbe0ae58719832d43ad6b78bee2cfc4a20c38fdab5
F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c
F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab
-F ext/jni/src/org/sqlite/jni/Tester1.java e62b0e855ef19a703dc53c1eb8395ff49f5dc4c9471627f5ba71b9b831a18b37
-F ext/jni/src/org/sqlite/jni/TesterFts5.java 2b2d6f3cc9f508358c103b774aee296c0f3d8c2f387d6abae9b8b9055f62c800
+F ext/jni/src/org/sqlite/jni/Tester1.java f67a63e3b138495b0c51dcb4f0e1ee1fcb91d772107afabf6d90256ea0ce3c4a
+F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59
F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0
F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c
F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee
F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246
F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2
-F ext/jni/src/org/sqlite/jni/annotation/Canonical.java d9ff79f1bf9d063d0c3e3b768ec7df15f51e4ca51a5bb291d33b7a6ea9a24f3a
+F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0f8234d379d266d1b2c21400a057864b538a0ea5
F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457
F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af
F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726
-R cd45a82215972a4be2e15156d78c2ac2
+P a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148
+R 728b2c246df3114419f3af688349a1b0
U stephan
-Z ff41a71811c7dc2406bc2ebbdfa8abb1
+Z abdadbf4f03136eea88913bb00194ef2
# Remove this line to create a well-formed Fossil manifest.
-a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148
\ No newline at end of file
+a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce
\ No newline at end of file