mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Bind sqlite3_db_status() to JNI.
FossilOrigin-Name: b79477a0af94127b0638a8822de01156bef855a7e167f678809e1c978e1a0c3e
This commit is contained in:
@ -2354,90 +2354,6 @@ JDECL(jboolean,1compileoption_1used)(JENV_CSELF, jstring name){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* sqlite3_db_config() for (int,const char *) */
|
||||
JDECL(int,1db_1config__Lorg_sqlite_jni_sqlite3_2ILjava_lang_String_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jstring jStr
|
||||
){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
int rc;
|
||||
char *zStr;
|
||||
|
||||
switch( (ps && jStr) ? op : 0 ){
|
||||
case SQLITE_DBCONFIG_MAINDBNAME:
|
||||
zStr = s3jni_jstring_to_utf8(S3JniGlobal_env_cache(env), jStr, 0);
|
||||
if( zStr ){
|
||||
rc = sqlite3_db_config(ps->pDb, (int)op, zStr);
|
||||
if( rc ){
|
||||
sqlite3_free( zStr );
|
||||
}else{
|
||||
sqlite3_free( ps->zMainDbName );
|
||||
ps->zMainDbName = zStr;
|
||||
}
|
||||
}else{
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
FIXME_THREADING(perDb)
|
||||
/* sqlite3_db_config() for (int,int*) */
|
||||
/* ACHTUNG: openjdk v19 creates a different mangled name for this
|
||||
function than openjdk v8 does. */
|
||||
JDECL(jint,1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_Int32_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jint onOff, jobject jOut
|
||||
){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
int rc;
|
||||
switch( ps ? op : 0 ){
|
||||
case SQLITE_DBCONFIG_ENABLE_FKEY:
|
||||
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
||||
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
||||
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
||||
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
||||
case SQLITE_DBCONFIG_ENABLE_QPSG:
|
||||
case SQLITE_DBCONFIG_TRIGGER_EQP:
|
||||
case SQLITE_DBCONFIG_RESET_DATABASE:
|
||||
case SQLITE_DBCONFIG_DEFENSIVE:
|
||||
case SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
||||
case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
||||
case SQLITE_DBCONFIG_DQS_DML:
|
||||
case SQLITE_DBCONFIG_DQS_DDL:
|
||||
case SQLITE_DBCONFIG_ENABLE_VIEW:
|
||||
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
||||
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
||||
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
||||
case SQLITE_DBCONFIG_REVERSE_SCANORDER: {
|
||||
int pOut = 0;
|
||||
rc = sqlite3_db_config( ps->pDb, (int)op, onOff, &pOut );
|
||||
if( 0==rc && jOut ){
|
||||
OutputPointer_set_Int32(env, jOut, pOut);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
/**
|
||||
This is a workaround for openjdk v19 (and possibly others) encoding
|
||||
this function's name differently than JDK v8 does. If we do not
|
||||
install both names for this function then Java will not be able to
|
||||
find the function in both environments.
|
||||
*/
|
||||
JDECL(jint,1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_00024Int32_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jint onOff, jobject jOut
|
||||
){
|
||||
return JFuncName(1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_Int32_2)(
|
||||
env, jKlazz, jDb, op, onOff, jOut
|
||||
);
|
||||
}
|
||||
|
||||
FIXME_THREADING(perDb)
|
||||
JDECL(jobject,1context_1db_1handle)(JENV_CSELF, jobject jpCx){
|
||||
sqlite3 * const pDb = sqlite3_context_db_handle(PtrGet_sqlite3_context(jpCx));
|
||||
@ -2537,6 +2453,90 @@ JDECL(jint,1create_1function)(JENV_CSELF, jobject jDb, jstring jFuncName,
|
||||
return create_function(env, jDb, jFuncName, nArg, eTextRep, jFunctor);
|
||||
}
|
||||
|
||||
/* sqlite3_db_config() for (int,const char *) */
|
||||
JDECL(int,1db_1config__Lorg_sqlite_jni_sqlite3_2ILjava_lang_String_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jstring jStr
|
||||
){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
int rc;
|
||||
char *zStr;
|
||||
|
||||
switch( (ps && jStr) ? op : 0 ){
|
||||
case SQLITE_DBCONFIG_MAINDBNAME:
|
||||
zStr = s3jni_jstring_to_utf8(S3JniGlobal_env_cache(env), jStr, 0);
|
||||
if( zStr ){
|
||||
rc = sqlite3_db_config(ps->pDb, (int)op, zStr);
|
||||
if( rc ){
|
||||
sqlite3_free( zStr );
|
||||
}else{
|
||||
sqlite3_free( ps->zMainDbName );
|
||||
ps->zMainDbName = zStr;
|
||||
}
|
||||
}else{
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
FIXME_THREADING(perDb)
|
||||
/* sqlite3_db_config() for (int,int*) */
|
||||
/* ACHTUNG: openjdk v19 creates a different mangled name for this
|
||||
function than openjdk v8 does. */
|
||||
JDECL(jint,1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_Int32_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jint onOff, jobject jOut
|
||||
){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
int rc;
|
||||
switch( ps ? op : 0 ){
|
||||
case SQLITE_DBCONFIG_ENABLE_FKEY:
|
||||
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
||||
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
||||
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
||||
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
||||
case SQLITE_DBCONFIG_ENABLE_QPSG:
|
||||
case SQLITE_DBCONFIG_TRIGGER_EQP:
|
||||
case SQLITE_DBCONFIG_RESET_DATABASE:
|
||||
case SQLITE_DBCONFIG_DEFENSIVE:
|
||||
case SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
||||
case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
||||
case SQLITE_DBCONFIG_DQS_DML:
|
||||
case SQLITE_DBCONFIG_DQS_DDL:
|
||||
case SQLITE_DBCONFIG_ENABLE_VIEW:
|
||||
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
||||
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
||||
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
||||
case SQLITE_DBCONFIG_REVERSE_SCANORDER: {
|
||||
int pOut = 0;
|
||||
rc = sqlite3_db_config( ps->pDb, (int)op, onOff, &pOut );
|
||||
if( 0==rc && jOut ){
|
||||
OutputPointer_set_Int32(env, jOut, pOut);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
/**
|
||||
This is a workaround for openjdk v19 (and possibly others) encoding
|
||||
this function's name differently than JDK v8 does. If we do not
|
||||
install both names for this function then Java will not be able to
|
||||
find the function in both environments.
|
||||
*/
|
||||
JDECL(jint,1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_00024Int32_2)(
|
||||
JENV_CSELF, jobject jDb, jint op, jint onOff, jobject jOut
|
||||
){
|
||||
return JFuncName(1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_Int32_2)(
|
||||
env, jKlazz, jDb, op, onOff, jOut
|
||||
);
|
||||
}
|
||||
|
||||
JDECL(jstring,1db_1filename)(JENV_CSELF, jobject jDb, jstring jDbName){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
S3JniEnvCache * const jc = S3JniGlobal_env_cache(env);
|
||||
@ -2558,6 +2558,20 @@ JDECL(jstring,1db_1filename)(JENV_CSELF, jobject jDb, jstring jDbName){
|
||||
return jRv;
|
||||
}
|
||||
|
||||
|
||||
JDECL(jint,1db_1status)(JENV_CSELF, jobject jDb, jint op, jobject jOutCurrent,
|
||||
jobject jOutHigh, jboolean reset ){
|
||||
int iCur = 0, iHigh = 0;
|
||||
sqlite3 * const pDb = PtrGet_sqlite3(jDb);
|
||||
int rc = sqlite3_db_status( pDb, op, &iCur, &iHigh, reset );
|
||||
if( 0==rc ){
|
||||
OutputPointer_set_Int32(env, jOutCurrent, iCur);
|
||||
OutputPointer_set_Int32(env, jOutHigh, iHigh);
|
||||
}
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
|
||||
JDECL(jint,1errcode)(JENV_CSELF, jobject jpDb){
|
||||
sqlite3 * const pDb = PtrGet_sqlite3(jpDb);
|
||||
return pDb ? sqlite3_errcode(pDb) : SQLITE_MISUSE;
|
||||
|
@ -1131,6 +1131,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1config__Lorg_
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1config__Lorg_sqlite_jni_sqlite3_2ILjava_lang_String_2
|
||||
(JNIEnv *, jclass, jobject, jint, jstring);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_db_status
|
||||
* Signature: (Lorg/sqlite/jni/sqlite3;ILorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1status
|
||||
(JNIEnv *, jclass, jobject, jint, jobject, jobject, jboolean);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_errcode
|
||||
|
@ -36,7 +36,7 @@ public final class OutputPointer {
|
||||
}
|
||||
|
||||
public static final class Int32 {
|
||||
private int value;
|
||||
public int value;
|
||||
public Int32(){this(0);}
|
||||
public Int32(int v){value = v;}
|
||||
public final int getValue(){return value;}
|
||||
@ -44,7 +44,7 @@ public final class OutputPointer {
|
||||
}
|
||||
|
||||
public static final class Int64 {
|
||||
private long value;
|
||||
public long value;
|
||||
public Int64(){this(0);}
|
||||
public Int64(long v){value = v;}
|
||||
public final long getValue(){return value;}
|
||||
@ -52,7 +52,7 @@ public final class OutputPointer {
|
||||
}
|
||||
|
||||
public static final class String {
|
||||
private java.lang.String value;
|
||||
public java.lang.String value;
|
||||
public String(){this(null);}
|
||||
public String(java.lang.String v){value = v;}
|
||||
public final java.lang.String getValue(){return value;}
|
||||
@ -60,7 +60,7 @@ public final class OutputPointer {
|
||||
}
|
||||
|
||||
public static final class ByteArray {
|
||||
private byte[] value;
|
||||
public byte[] value;
|
||||
public ByteArray(){this(null);}
|
||||
public ByteArray(byte[] v){value = v;}
|
||||
public final byte[] getValue(){return value;}
|
||||
|
@ -526,6 +526,11 @@ public final class SQLite3Jni {
|
||||
@NotNull sqlite3 db, int op, @NotNull String val
|
||||
);
|
||||
|
||||
public static synchronized native int sqlite3_db_status(
|
||||
@NotNull sqlite3 db, int op, @NotNull OutputPointer.Int32 pCurrent,
|
||||
@NotNull OutputPointer.Int32 pHighwater, boolean reset
|
||||
);
|
||||
|
||||
public static synchronized native int sqlite3_errcode(@NotNull sqlite3 db);
|
||||
|
||||
public static synchronized native String sqlite3_expanded_sql(@NotNull sqlite3_stmt stmt);
|
||||
@ -936,7 +941,6 @@ public final class SQLite3Jni {
|
||||
long maxLength, int encoding
|
||||
);
|
||||
|
||||
|
||||
public static synchronized native int sqlite3_status(
|
||||
int op, @NotNull OutputPointer.Int32 pCurrent,
|
||||
@NotNull OutputPointer.Int32 pHighwater, boolean reset
|
||||
|
@ -494,19 +494,27 @@ public class Tester1 {
|
||||
final OutputPointer.Int32 cur32 = new OutputPointer.Int32();
|
||||
final OutputPointer.Int32 high32 = new OutputPointer.Int32();
|
||||
final sqlite3 db = createNewDb();
|
||||
execSql(db, "create table t(a)");
|
||||
sqlite3_close_v2(db);
|
||||
execSql(db, "create table t(a); insert into t values(1),(2),(3)");
|
||||
|
||||
int rc = sqlite3_status(SQLITE_STATUS_MEMORY_USED, cur32, high32, false);
|
||||
affirm( 0 == rc );
|
||||
affirm( cur32.getValue() > 0 );
|
||||
affirm( high32.getValue() >= cur32.getValue() );
|
||||
affirm( cur32.value > 0 );
|
||||
affirm( high32.value >= cur32.value );
|
||||
|
||||
rc = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, cur64, high64, false);
|
||||
affirm( 0 == rc );
|
||||
affirm( cur64.getValue() > 0 );
|
||||
affirm( high64.getValue() >= cur64.getValue() );
|
||||
affirm( cur64.value > 0 );
|
||||
affirm( high64.value >= cur64.value );
|
||||
|
||||
cur32.value = 0;
|
||||
high32.value = 1;
|
||||
rc = sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, cur32, high32, false);
|
||||
affirm( 0 == rc );
|
||||
affirm( cur32.value > 0 );
|
||||
outln(cur32.value," ",high32.value);
|
||||
affirm( high32.value == 0 /* always 0 for SCHEMA_USED */ );
|
||||
|
||||
sqlite3_close_v2(db);
|
||||
}
|
||||
|
||||
private static void testUdf1(){
|
||||
|
Reference in New Issue
Block a user