public abstract class Function extends Object
A subclass of org.sqlite.Function can be registered with Function.create() and called by the name it was given. All functions must implement xFunc(), which is called when SQLite runs the custom function.
Eg.Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:"); Function.create(conn, "myFunc", new Function() { protected void xFunc() { System.out.println("myFunc called!"); } }); conn.createStatement().execute("select myFunc();");
Arguments passed to a custom function can be accessed using the protected functions provided. args() returns the number of arguments passed, while value_<type>(int) returns the value of the specific argument. Similarly a function can return a value using the result(<type>) function.
Aggregate functions are not yet supported, but coming soon.
Modifier and Type | Class and Description |
---|---|
static class |
Function.Aggregate
Provides an interface for creating SQLite user-defined aggregate functions.
|
static class |
Function.Window
Provides an interface for creating SQLite user-defined window functions.
|
Modifier and Type | Field and Description |
---|---|
static int |
FLAG_DETERMINISTIC
Flag to provide to
create(Connection, String, Function, int)
that marks this Function as deterministic, making is usable in
Indexes on Expressions. |
Constructor and Description |
---|
Function() |
Modifier and Type | Method and Description |
---|---|
protected int |
args()
Returns the number of arguments passed to the function.
|
static void |
create(Connection conn,
String name,
Function f)
Registers a given function with the connection.
|
static void |
create(Connection conn,
String name,
Function f,
int flags)
Registers a given function with the connection.
|
static void |
create(Connection conn,
String name,
Function f,
int nArgs,
int flags)
Registers a given function with the connection.
|
static void |
destroy(Connection conn,
String name)
Removes a named function from the given connection.
|
static void |
destroy(Connection conn,
String name,
int nArgs)
Removes a named function from the given connection.
|
protected void |
error(String err)
Called by xFunc to throw an error.
|
protected void |
result()
Called by xFunc to return a value.
|
protected void |
result(byte[] value)
Called by xFunc to return a value.
|
protected void |
result(double value)
Called by xFunc to return a value.
|
protected void |
result(int value)
Called by xFunc to return a value.
|
protected void |
result(long value)
Called by xFunc to return a value.
|
protected void |
result(String value)
Called by xFunc to return a value.
|
protected byte[] |
value_blob(int arg)
Called by xFunc to access the value of an argument.
|
protected double |
value_double(int arg)
Called by xFunc to access the value of an argument.
|
protected int |
value_int(int arg)
Called by xFunc to access the value of an argument.
|
protected long |
value_long(int arg)
Called by xFunc to access the value of an argument.
|
protected String |
value_text(int arg)
Called by xFunc to access the value of an argument.
|
protected int |
value_type(int arg)
Called by xFunc to access the value of an argument.
|
protected abstract void |
xFunc()
Called by SQLite as a custom function.
|
public static final int FLAG_DETERMINISTIC
create(Connection, String, Function, int)
that marks this Function as deterministic, making is usable in
Indexes on Expressions.public static final void create(Connection conn, String name, Function f) throws SQLException
conn
- The connection.name
- The name of the function.f
- The function to register.SQLException
public static final void create(Connection conn, String name, Function f, int flags) throws SQLException
conn
- The connection.name
- The name of the function.f
- The function to register.flags
- Extra flags to pass, such as FLAG_DETERMINISTIC
SQLException
public static final void create(Connection conn, String name, Function f, int nArgs, int flags) throws SQLException
conn
- The connection.name
- The name of the function.f
- The function to register.nArgs
- The number of arguments that the function takes.flags
- Extra flags to pass, such as FLAG_DETERMINISTIC
SQLException
public static final void destroy(Connection conn, String name, int nArgs) throws SQLException
conn
- The connection to remove the function from.name
- The name of the function.nArgs
- The number of args for the function.SQLException
public static final void destroy(Connection conn, String name) throws SQLException
conn
- The connection to remove the function from.name
- The name of the function.SQLException
protected abstract void xFunc() throws SQLException
SQLException
protected final int args() throws SQLException
SQLException
protected final void result(byte[] value) throws SQLException
value
- SQLException
protected final void result(double value) throws SQLException
value
- SQLException
protected final void result(int value) throws SQLException
value
- SQLException
protected final void result(long value) throws SQLException
value
- SQLException
protected final void result() throws SQLException
SQLException
protected final void result(String value) throws SQLException
value
- SQLException
protected final void error(String err) throws SQLException
err
- SQLException
protected final String value_text(int arg) throws SQLException
arg
- SQLException
protected final byte[] value_blob(int arg) throws SQLException
arg
- SQLException
protected final double value_double(int arg) throws SQLException
arg
- SQLException
protected final int value_int(int arg) throws SQLException
arg
- SQLException
protected final long value_long(int arg) throws SQLException
arg
- SQLException
protected final int value_type(int arg) throws SQLException
arg
- SQLException
Copyright © 2021. All rights reserved.