mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Expose context_db_handle() to the JNI wrapper1 API and clean up some related tests.
FossilOrigin-Name: c23123af7d40dea24a0848dff987fd58a6703ce04165060533544db85983d566
This commit is contained in:
@ -12,10 +12,6 @@
|
||||
** This file is part of the wrapper1 interface for sqlite3.
|
||||
*/
|
||||
package org.sqlite.jni.wrapper1;
|
||||
import org.sqlite.jni.capi.CApi;
|
||||
import org.sqlite.jni.annotation.*;
|
||||
import org.sqlite.jni.capi.sqlite3_context;
|
||||
import org.sqlite.jni.capi.sqlite3_value;
|
||||
|
||||
/**
|
||||
EXPERIMENTAL/INCOMPLETE/UNTESTED
|
||||
|
@ -56,7 +56,7 @@ public interface SqlFunction {
|
||||
*/
|
||||
Arguments(sqlite3_context cx, sqlite3_value args[]){
|
||||
this.cx = cx;
|
||||
this.args = args==null ? new sqlite3_value[0] : args;;
|
||||
this.args = args==null ? new sqlite3_value[0] : args;
|
||||
this.length = this.args.length;
|
||||
}
|
||||
|
||||
@ -76,6 +76,16 @@ public interface SqlFunction {
|
||||
//! Returns the underlying sqlite3_context for these arguments.
|
||||
sqlite3_context getContext(){return cx;}
|
||||
|
||||
/**
|
||||
Returns the Sqlite (db) object associated with this UDF call,
|
||||
or null if the UDF is somehow called without such an object or
|
||||
the db has been closed in an untimely manner (e.g. closed by a
|
||||
UDF call).
|
||||
*/
|
||||
public Sqlite getDb(){
|
||||
return Sqlite.fromNative( CApi.sqlite3_context_db_handle(cx) );
|
||||
}
|
||||
|
||||
public int getArgCount(){ return args.length; }
|
||||
|
||||
public int getInt(int argNdx){return CApi.sqlite3_value_int(valueAt(argNdx));}
|
||||
|
@ -781,7 +781,7 @@ public final class Sqlite implements AutoCloseable {
|
||||
Returns the Sqlite which prepared this statement, or null if
|
||||
this statement has been finalized.
|
||||
*/
|
||||
public Sqlite db(){ return this._db; }
|
||||
public Sqlite getDb(){ return this._db; }
|
||||
|
||||
/**
|
||||
Works like sqlite3_reset() but throws on error.
|
||||
|
@ -74,7 +74,7 @@ public final class SqliteException extends java.lang.RuntimeException {
|
||||
}
|
||||
|
||||
public SqliteException(Sqlite.Stmt stmt){
|
||||
this(stmt.db());
|
||||
this(stmt.getDb());
|
||||
}
|
||||
|
||||
public int errcode(){ return errCode; }
|
||||
|
@ -241,6 +241,7 @@ public class Tester2 implements Runnable {
|
||||
Sqlite.Stmt stmt = db.prepare("SELECT ?1");
|
||||
Exception e = null;
|
||||
affirm( null!=stmt.nativeHandle() );
|
||||
affirm( db == stmt.getDb() );
|
||||
affirm( 1==stmt.bindParameterCount() );
|
||||
affirm( "?1".equals(stmt.bindParameterName(1)) );
|
||||
affirm( null==stmt.bindParameterName(2) );
|
||||
@ -294,21 +295,30 @@ public class Tester2 implements Runnable {
|
||||
final ValueHolder<Integer> vh = new ValueHolder<>(0);
|
||||
final ScalarFunction f = new ScalarFunction(){
|
||||
public void xFunc(SqlFunction.Arguments args){
|
||||
affirm( db == args.getDb() );
|
||||
for( SqlFunction.Arguments.Arg arg : args ){
|
||||
vh.value += arg.getInt();
|
||||
}
|
||||
args.resultInt(vh.value);
|
||||
}
|
||||
public void xDestroy(){
|
||||
++xDestroyCalled.value;
|
||||
}
|
||||
};
|
||||
db.createFunction("myfunc", -1, f);
|
||||
execSql(db, "select myfunc(1,2,3)");
|
||||
Sqlite.Stmt q = db.prepare("select myfunc(1,2,3)");
|
||||
affirm( q.step() );
|
||||
affirm( 6 == vh.value );
|
||||
vh.value = 0;
|
||||
execSql(db, "select myfunc(-1,-2,-3)");
|
||||
affirm( -6 == vh.value );
|
||||
affirm( 6 == q.columnInt(0) );
|
||||
q.finalizeStmt();
|
||||
affirm( 0 == xDestroyCalled.value );
|
||||
vh.value = 0;
|
||||
q = db.prepare("select myfunc(-1,-2,-3)");
|
||||
affirm( q.step() );
|
||||
affirm( -6 == vh.value );
|
||||
affirm( -6 == q.columnInt(0) );
|
||||
affirm( 0 == xDestroyCalled.value );
|
||||
q.finalizeStmt();
|
||||
}
|
||||
affirm( 1 == xDestroyCalled.value );
|
||||
}
|
||||
|
@ -12,10 +12,6 @@
|
||||
** This file is part of the wrapper1 interface for sqlite3.
|
||||
*/
|
||||
package org.sqlite.jni.wrapper1;
|
||||
import org.sqlite.jni.capi.CApi;
|
||||
import org.sqlite.jni.annotation.*;
|
||||
import org.sqlite.jni.capi.sqlite3_context;
|
||||
import org.sqlite.jni.capi.sqlite3_value;
|
||||
|
||||
/**
|
||||
A SqlFunction implementation for window functions. The T type
|
||||
|
Reference in New Issue
Block a user