xref: /aosp_15_r20/external/javasqlite/src/main/java/SQLite/Function.java (revision fd76c71b147b98c03334ec0945352cee0b39aab1)
1*fd76c71bSTreehugger Robot package SQLite;
2*fd76c71bSTreehugger Robot 
3*fd76c71bSTreehugger Robot /**
4*fd76c71bSTreehugger Robot  * Callback interface for SQLite's user defined functions.
5*fd76c71bSTreehugger Robot  * Each callback method receives a
6*fd76c71bSTreehugger Robot  * <A HREF="FunctionContext.html">FunctionContext</A> object
7*fd76c71bSTreehugger Robot  * which is used to set the function result or error code.
8*fd76c71bSTreehugger Robot  * <BR><BR>
9*fd76c71bSTreehugger Robot  * Example:<BR>
10*fd76c71bSTreehugger Robot  *
11*fd76c71bSTreehugger Robot  * <PRE>
12*fd76c71bSTreehugger Robot  *   class SinFunc implements SQLite.Function {
13*fd76c71bSTreehugger Robot  *     public void function(SQLite.FunctionContext fc, String args[]) {
14*fd76c71bSTreehugger Robot  *       try {
15*fd76c71bSTreehugger Robot  *         Double d = new Double(args[0]);
16*fd76c71bSTreehugger Robot  *         fc.set_result(Math.sin(d.doubleValue()));
17*fd76c71bSTreehugger Robot  *       } catch (Exception e) {
18*fd76c71bSTreehugger Robot  *         fc.set_error("sin(" + args[0] + "):" + e);
19*fd76c71bSTreehugger Robot  *       }
20*fd76c71bSTreehugger Robot  *     }
21*fd76c71bSTreehugger Robot  *     ...
22*fd76c71bSTreehugger Robot  *   }
23*fd76c71bSTreehugger Robot  *   SQLite.Database db = new SQLite.Database();
24*fd76c71bSTreehugger Robot  *   db.open("db", 0);
25*fd76c71bSTreehugger Robot  *   db.create_function("sin", 1, SinFunc);
26*fd76c71bSTreehugger Robot  *   ...
27*fd76c71bSTreehugger Robot  *   db.exec("select sin(1.0) from test", null);
28*fd76c71bSTreehugger Robot  * </PRE>
29*fd76c71bSTreehugger Robot  */
30*fd76c71bSTreehugger Robot 
31*fd76c71bSTreehugger Robot public interface Function {
32*fd76c71bSTreehugger Robot 
33*fd76c71bSTreehugger Robot     /**
34*fd76c71bSTreehugger Robot      * Callback for regular function.
35*fd76c71bSTreehugger Robot      *
36*fd76c71bSTreehugger Robot      * @param fc function's context for reporting result
37*fd76c71bSTreehugger Robot      * @param args String array of arguments
38*fd76c71bSTreehugger Robot      */
39*fd76c71bSTreehugger Robot 
function(FunctionContext fc, String args[])40*fd76c71bSTreehugger Robot     public void function(FunctionContext fc, String args[]);
41*fd76c71bSTreehugger Robot 
42*fd76c71bSTreehugger Robot     /**
43*fd76c71bSTreehugger Robot      * Callback for one step in aggregate function.
44*fd76c71bSTreehugger Robot      *
45*fd76c71bSTreehugger Robot      * @param fc function's context for reporting result
46*fd76c71bSTreehugger Robot      * @param args String array of arguments
47*fd76c71bSTreehugger Robot      */
48*fd76c71bSTreehugger Robot 
step(FunctionContext fc, String args[])49*fd76c71bSTreehugger Robot     public void step(FunctionContext fc, String args[]);
50*fd76c71bSTreehugger Robot 
51*fd76c71bSTreehugger Robot     /**
52*fd76c71bSTreehugger Robot      * Callback for final step in aggregate function.
53*fd76c71bSTreehugger Robot      *
54*fd76c71bSTreehugger Robot      * @param fc function's context for reporting result
55*fd76c71bSTreehugger Robot      */
56*fd76c71bSTreehugger Robot 
last_step(FunctionContext fc)57*fd76c71bSTreehugger Robot     public void last_step(FunctionContext fc);
58*fd76c71bSTreehugger Robot 
59*fd76c71bSTreehugger Robot }
60