1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

JNI wrapper1 normalizeSql() now throws UnsupportedOperationException, instead of returning null, if built without SQLITE_ENABLE_NORMALIZE. Remove SQLITE_PREPARE_NORMALIZE from the JNI interface because it's a legacy no-op.

FossilOrigin-Name: d081a126697e214082f3b203f23ea63510080e5c2aac1d8badc9e6e4bfea7c95
This commit is contained in:
stephan
2023-11-05 03:37:33 +00:00
parent 88c90a793e
commit 546db3f14a
7 changed files with 34 additions and 19 deletions

View File

@ -427,8 +427,6 @@ extern "C" {
#define org_sqlite_jni_capi_CApi_SQLITE_OPEN_EXRESCODE 33554432L
#undef org_sqlite_jni_capi_CApi_SQLITE_PREPARE_PERSISTENT
#define org_sqlite_jni_capi_CApi_SQLITE_PREPARE_PERSISTENT 1L
#undef org_sqlite_jni_capi_CApi_SQLITE_PREPARE_NORMALIZE
#define org_sqlite_jni_capi_CApi_SQLITE_PREPARE_NORMALIZE 2L
#undef org_sqlite_jni_capi_CApi_SQLITE_PREPARE_NO_VTAB
#define org_sqlite_jni_capi_CApi_SQLITE_PREPARE_NO_VTAB 4L
#undef org_sqlite_jni_capi_CApi_SQLITE_OK

View File

@ -2279,7 +2279,6 @@ public final class CApi {
// prepare flags
public static final int SQLITE_PREPARE_PERSISTENT = 1;
public static final int SQLITE_PREPARE_NORMALIZE = 2;
public static final int SQLITE_PREPARE_NO_VTAB = 4;
// result codes

View File

@ -19,7 +19,8 @@ package org.sqlite.jni.capi;
public interface PreupdateHookCallback extends CallbackProxy {
/**
Must function as described for the C-level sqlite3_preupdate_hook()
callback.
callback. If it throws, the exception is translated to a
db-level error and the exception is suppressed.
*/
void call(sqlite3 db, int op, String dbName, String dbTable,
long iKey1, long iKey2 );

View File

@ -327,7 +327,7 @@ public class Tester1 implements Runnable {
rc = sqlite3_prepare_v3(db, "INSERT INTO t2(a) VALUES(1),(2),(3)",
SQLITE_PREPARE_NORMALIZE, outStmt);
0, outStmt);
affirm(0 == rc);
stmt = outStmt.get();
affirm(0 != stmt.getNativePointer());

View File

@ -178,7 +178,6 @@ public final class Sqlite implements AutoCloseable {
public static final int LIMIT_WORKER_THREADS = CApi.SQLITE_LIMIT_WORKER_THREADS;
public static final int PREPARE_PERSISTENT = CApi.SQLITE_PREPARE_PERSISTENT;
public static final int PREPARE_NORMALIZE = CApi.SQLITE_PREPARE_NORMALIZE;
public static final int PREPARE_NO_VTAB = CApi.SQLITE_PREPARE_NO_VTAB;
public static final int TRACE_STMT = CApi.SQLITE_TRACE_STMT;
@ -336,6 +335,22 @@ public final class Sqlite implements AutoCloseable {
return CApi.sqlite3_compileoption_used(optName);
}
private static boolean hasNormalizeSql =
compileOptionUsed("ENABLE_NORMALIZE");
/**
Throws UnsupportedOperationException if check is false.
flag is expected to be the name of an SQLITE_ENABLE_...
build flag.
*/
private static void checkSupported(boolean check, String flag){
if( !check ){
throw new UnsupportedOperationException(
"Library was built without "+flag
);
}
}
/**
Analog to sqlite3_complete().
*/
@ -972,10 +987,12 @@ public final class Sqlite implements AutoCloseable {
}
/**
Analog to sqlite3_normalized_sql(), returning null if the
library is built without the SQLITE_ENABLE_NORMALIZE flag.
Analog to sqlite3_normalized_sql(), but throws
UnsupportedOperationException if the library was built without
the SQLITE_ENABLE_NORMALIZE flag.
*/
public String normalizedSql(){
Sqlite.checkSupported(hasNormalizeSql, "SQLITE_ENABLE_NORMALIZE");
return CApi.sqlite3_normalized_sql(thisStmt());
}