summaryrefslogtreecommitdiffstats
path: root/sql/src/main/java/SQLite/Function.java
blob: 5aa5e33564a992f88571c35fedb91df70881530f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package SQLite;

/**
 * Callback interface for SQLite's user defined functions.
 * Each callback method receives a
 * <A HREF="FunctionContext.html">FunctionContext</A> object
 * which is used to set the function result or error code.
 * <BR><BR>
 * Example:<BR>
 *
 * <PRE>
 *   class SinFunc implements SQLite.Function {
 *     public void function(SQLite.FunctionContext fc, String args[]) {
 *       try {
 *         Double d = new Double(args[0]);
 *         fc.set_result(Math.sin(d.doubleValue()));
 *       } catch (Exception e) {
 *         fc.set_error("sin(" + args[0] + "):" + e);
 *       }
 *     }
 *     ...
 *   }
 *   SQLite.Database db = new SQLite.Database();
 *   db.open("db", 0);
 *   db.create_function("sin", 1, SinFunc);
 *   ...
 *   db.exec("select sin(1.0) from test", null);
 * </PRE>
 */

public interface Function {

    /**
     * Callback for regular function.
     *
     * @param fc function's context for reporting result
     * @param args String array of arguments
     */

    public void function(FunctionContext fc, String args[]);

    /**
     * Callback for one step in aggregate function.
     *
     * @param fc function's context for reporting result
     * @param args String array of arguments
     */

    public void step(FunctionContext fc, String args[]);

    /**
     * Callback for final step in aggregate function.
     *
     * @param fc function's context for reporting result
     */

    public void last_step(FunctionContext fc);

}