1417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespackage SQLite;
2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/**
4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Callback interface for SQLite's user defined functions.
5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Each callback method receives a
6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * <A HREF="FunctionContext.html">FunctionContext</A> object
7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * which is used to set the function result or error code.
8417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * <BR><BR>
9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Example:<BR>
10417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *
11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * <PRE>
12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   class SinFunc implements SQLite.Function {
13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *     public void function(SQLite.FunctionContext fc, String args[]) {
14417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *       try {
15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *         Double d = new Double(args[0]);
16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *         fc.set_result(Math.sin(d.doubleValue()));
17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *       } catch (Exception e) {
18417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *         fc.set_error("sin(" + args[0] + "):" + e);
19417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *       }
20417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *     }
21417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *     ...
22417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   }
23417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   SQLite.Database db = new SQLite.Database();
24417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   db.open("db", 0);
25417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   db.create_function("sin", 1, SinFunc);
26417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   ...
27417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *   db.exec("select sin(1.0) from test", null);
28417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * </PRE>
29417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */
30417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
31417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic interface Function {
32417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
33417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
34417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Callback for regular function.
35417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
36417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param fc function's context for reporting result
37417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param args String array of arguments
38417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
39417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
40417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void function(FunctionContext fc, String args[]);
41417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Callback for one step in aggregate function.
44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
45417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param fc function's context for reporting result
46417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param args String array of arguments
47417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
48417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void step(FunctionContext fc, String args[]);
50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
52417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Callback for final step in aggregate function.
53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param fc function's context for reporting result
55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
56417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
57417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void last_step(FunctionContext fc);
58417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
59417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes}
60