mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Bind the bool-flag sqlite3_db_config() variants to the JNI wrapper1 API.
FossilOrigin-Name: b5cdcb9279d9276f24b67083839f463beecd731f46f2e8bf68fff716df0a3921
This commit is contained in:
@ -3429,7 +3429,6 @@ S3JniApi(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
|
@ -828,7 +828,7 @@ public final class CApi {
|
||||
SQLITE_DBCONFIG_... options which uses this call form.
|
||||
|
||||
<p>Unlike the C API, this returns SQLITE_MISUSE if its db argument
|
||||
are null (as opposed to invoking UB).
|
||||
is null (as opposed to invoking UB).
|
||||
*/
|
||||
public static native int sqlite3_db_config(
|
||||
@NotNull sqlite3 db, int op, int onOff, @Nullable OutputPointer.Int32 out
|
||||
@ -851,7 +851,6 @@ public final class CApi {
|
||||
return null==db ? null : sqlite3_db_name(db.getNativePointer(), ndx);
|
||||
}
|
||||
|
||||
|
||||
public static native String sqlite3_db_filename(
|
||||
@NotNull sqlite3 db, @NotNull String dbName
|
||||
);
|
||||
|
@ -1049,6 +1049,7 @@ public class Tester1 implements Runnable {
|
||||
rc = sqlite3_db_config(db1, SQLITE_DBCONFIG_MAINDBNAME, "foo");
|
||||
affirm( sqlite3_db_filename(db1, "foo").endsWith(dbName) );
|
||||
affirm( "foo".equals( sqlite3_db_name(db1, 0) ) );
|
||||
affirm( SQLITE_MISUSE == sqlite3_db_config(db1, 0, 0, null) );
|
||||
|
||||
final ValueHolder<Integer> xBusyCalled = new ValueHolder<>(0);
|
||||
BusyHandlerCallback handler = new BusyHandlerCallback(){
|
||||
|
@ -67,6 +67,25 @@ public final class Sqlite implements AutoCloseable {
|
||||
public static final int TRACE_CLOSE = CApi.SQLITE_TRACE_CLOSE;
|
||||
public static final int TRACE_ALL = TRACE_STMT | TRACE_PROFILE | TRACE_ROW | TRACE_CLOSE;
|
||||
|
||||
public static final int DBCONFIG_ENABLE_FKEY = CApi.SQLITE_DBCONFIG_ENABLE_FKEY;
|
||||
public static final int DBCONFIG_ENABLE_TRIGGER = CApi.SQLITE_DBCONFIG_ENABLE_TRIGGER;
|
||||
public static final int DBCONFIG_ENABLE_FTS3_TOKENIZER = CApi.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER;
|
||||
public static final int DBCONFIG_ENABLE_LOAD_EXTENSION = CApi.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION;
|
||||
public static final int DBCONFIG_NO_CKPT_ON_CLOSE = CApi.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE;
|
||||
public static final int DBCONFIG_ENABLE_QPSG = CApi.SQLITE_DBCONFIG_ENABLE_QPSG;
|
||||
public static final int DBCONFIG_TRIGGER_EQP = CApi.SQLITE_DBCONFIG_TRIGGER_EQP;
|
||||
public static final int DBCONFIG_RESET_DATABASE = CApi.SQLITE_DBCONFIG_RESET_DATABASE;
|
||||
public static final int DBCONFIG_DEFENSIVE = CApi.SQLITE_DBCONFIG_DEFENSIVE;
|
||||
public static final int DBCONFIG_WRITABLE_SCHEMA = CApi.SQLITE_DBCONFIG_WRITABLE_SCHEMA;
|
||||
public static final int DBCONFIG_LEGACY_ALTER_TABLE = CApi.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE;
|
||||
public static final int DBCONFIG_DQS_DML = CApi.SQLITE_DBCONFIG_DQS_DML;
|
||||
public static final int DBCONFIG_DQS_DDL = CApi.SQLITE_DBCONFIG_DQS_DDL;
|
||||
public static final int DBCONFIG_ENABLE_VIEW = CApi.SQLITE_DBCONFIG_ENABLE_VIEW;
|
||||
public static final int DBCONFIG_LEGACY_FILE_FORMAT = CApi.SQLITE_DBCONFIG_LEGACY_FILE_FORMAT;
|
||||
public static final int DBCONFIG_TRUSTED_SCHEMA = CApi.SQLITE_DBCONFIG_TRUSTED_SCHEMA;
|
||||
public static final int DBCONFIG_STMT_SCANSTATUS = CApi.SQLITE_DBCONFIG_STMT_SCANSTATUS;
|
||||
public static final int DBCONFIG_REVERSE_SCANORDER = CApi.SQLITE_DBCONFIG_REVERSE_SCANORDER;
|
||||
|
||||
//! Used only by the open() factory functions.
|
||||
private Sqlite(sqlite3 db){
|
||||
this.db = db;
|
||||
@ -375,6 +394,19 @@ public final class Sqlite implements AutoCloseable {
|
||||
return CApi.sqlite3_db_filename(thisDb(), dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
Analog to sqlite3_db_config() for the call forms which take one
|
||||
of the boolean-type db configuration flags (namely the
|
||||
DBCONFIG_... constants defined in this class). On success it
|
||||
returns the result of that underlying call. Throws on error.
|
||||
*/
|
||||
public boolean dbConfig(int op, boolean on){
|
||||
org.sqlite.jni.capi.OutputPointer.Int32 pOut =
|
||||
new org.sqlite.jni.capi.OutputPointer.Int32();
|
||||
checkRc( CApi.sqlite3_db_config(thisDb(), op, on ? 1 : 0, pOut) );
|
||||
return pOut.get()!=0;
|
||||
}
|
||||
|
||||
/**
|
||||
Analog to the variant of sqlite3_db_config() for configuring the
|
||||
SQLITE_DBCONFIG_MAINDBNAME option. Throws on error.
|
||||
|
@ -211,15 +211,24 @@ public class Tester2 implements Runnable {
|
||||
void testOpenDb1(){
|
||||
Sqlite db = openDb();
|
||||
affirm( 0!=db.nativeHandle().getNativePointer() );
|
||||
affirm( "main".equals( db.dbName(0) ) );
|
||||
db.setMainDbName("foo");
|
||||
affirm( "foo".equals( db.dbName(0) ) );
|
||||
affirm( db.dbConfig(Sqlite.DBCONFIG_DEFENSIVE, true)
|
||||
/* The underlying function has different mangled names in jdk8
|
||||
vs jdk19, and this call is here to ensure that the build
|
||||
fails if it cannot find both names. */ );
|
||||
affirm( !db.dbConfig(Sqlite.DBCONFIG_DEFENSIVE, false) );
|
||||
SqliteException ex = null;
|
||||
try{ db.dbConfig(0, false); }
|
||||
catch(SqliteException e){ ex = e; }
|
||||
affirm( null!=ex );
|
||||
ex = null;
|
||||
db.close();
|
||||
affirm( null==db.nativeHandle() );
|
||||
|
||||
SqliteException ex = null;
|
||||
try {
|
||||
db = openDb("/no/such/dir/.../probably");
|
||||
}catch(SqliteException e){
|
||||
ex = e;
|
||||
}
|
||||
try{ db = openDb("/no/such/dir/.../probably"); }
|
||||
catch(SqliteException e){ ex = e; }
|
||||
affirm( ex!=null );
|
||||
affirm( ex.errcode() != 0 );
|
||||
affirm( ex.extendedErrcode() != 0 );
|
||||
|
Reference in New Issue
Block a user