1417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespackage SQLite;
2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/**
4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Context for execution of SQLite's user defined functions.
5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * A reference to an instance of this class is passed to
6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * user defined functions.
7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */
8417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic class FunctionContext {
10417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal handle for the native SQLite API.
13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
14417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private long handle = 0;
16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
18417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result from string.
19417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
20417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param r result string
21417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
22417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
23417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_result(String r);
24417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
25417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
26417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result from integer.
27417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
28417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param r result integer
29417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
30417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
31417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_result(int r);
32417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
33417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
34417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result from double.
35417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
36417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param r result double
37417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
38417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
39417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_result(double r);
40417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
41417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result from error message.
43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param r result string (error message)
45417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
46417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
47417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_error(String r);
48417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result from byte array.
51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Only provided by SQLite3 databases.
52417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param r result byte array
54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
56417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_result(byte[] r);
57417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
58417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
59417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Set function result as empty blob given size.
60417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Only provided by SQLite3 databases.
61417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     *
62417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param n size for empty blob
63417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
64417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
65417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void set_result_zeroblob(int n);
66417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
67417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
68417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Retrieve number of rows for aggregate function.
69417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
70417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
71417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native int count();
72417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
73417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
74417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal native initializer.
75417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
76417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
77417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private static native void internal_init();
78417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
79417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    static {
807a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	internal_init();
81417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
82417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes}
83