xref: /aosp_15_r20/external/javasqlite/src/main/java/SQLite/Callback.java (revision fd76c71b147b98c03334ec0945352cee0b39aab1)
1*fd76c71bSTreehugger Robot package SQLite;
2*fd76c71bSTreehugger Robot 
3*fd76c71bSTreehugger Robot /**
4*fd76c71bSTreehugger Robot  * Callback interface for SQLite's query results.
5*fd76c71bSTreehugger Robot  * <BR><BR>
6*fd76c71bSTreehugger Robot  * Example:<BR>
7*fd76c71bSTreehugger Robot  *
8*fd76c71bSTreehugger Robot  * <PRE>
9*fd76c71bSTreehugger Robot  *   class TableFmt implements SQLite.Callback {
10*fd76c71bSTreehugger Robot  *     public void columns(String cols[]) {
11*fd76c71bSTreehugger Robot  *       System.out.println("&lt;TH&gt;&lt;TR&gt;");
12*fd76c71bSTreehugger Robot  *       for (int i = 0; i &lt; cols.length; i++) {
13*fd76c71bSTreehugger Robot  *         System.out.println("&lt;TD&gt;" + cols[i] + "&lt;/TD&gt;");
14*fd76c71bSTreehugger Robot  *       }
15*fd76c71bSTreehugger Robot  *       System.out.println("&lt;/TR&gt;&lt;/TH&gt;");
16*fd76c71bSTreehugger Robot  *     }
17*fd76c71bSTreehugger Robot  *     public boolean newrow(String cols[]) {
18*fd76c71bSTreehugger Robot  *       System.out.println("&lt;TR&gt;");
19*fd76c71bSTreehugger Robot  *       for (int i = 0; i &lt; cols.length; i++) {
20*fd76c71bSTreehugger Robot  *         System.out.println("&lt;TD&gt;" + cols[i] + "&lt;/TD&gt;");
21*fd76c71bSTreehugger Robot  *       }
22*fd76c71bSTreehugger Robot  *       System.out.println("&lt;/TR&gt;");
23*fd76c71bSTreehugger Robot  *       return false;
24*fd76c71bSTreehugger Robot  *     }
25*fd76c71bSTreehugger Robot  *   }
26*fd76c71bSTreehugger Robot  *   ...
27*fd76c71bSTreehugger Robot  *   SQLite.Database db = new SQLite.Database();
28*fd76c71bSTreehugger Robot  *   db.open("db", 0);
29*fd76c71bSTreehugger Robot  *   System.out.println("&lt;TABLE&gt;");
30*fd76c71bSTreehugger Robot  *   db.exec("select * from TEST", new TableFmt());
31*fd76c71bSTreehugger Robot  *   System.out.println("&lt;/TABLE&gt;");
32*fd76c71bSTreehugger Robot  *   ...
33*fd76c71bSTreehugger Robot  * </PRE>
34*fd76c71bSTreehugger Robot  */
35*fd76c71bSTreehugger Robot 
36*fd76c71bSTreehugger Robot public interface Callback {
37*fd76c71bSTreehugger Robot 
38*fd76c71bSTreehugger Robot     /**
39*fd76c71bSTreehugger Robot      * Reports column names of the query result.
40*fd76c71bSTreehugger Robot      * This method is invoked first (and once) when
41*fd76c71bSTreehugger Robot      * the SQLite engine returns the result set.<BR><BR>
42*fd76c71bSTreehugger Robot      *
43*fd76c71bSTreehugger Robot      * @param coldata string array holding the column names
44*fd76c71bSTreehugger Robot      */
45*fd76c71bSTreehugger Robot 
columns(String coldata[])46*fd76c71bSTreehugger Robot     public void columns(String coldata[]);
47*fd76c71bSTreehugger Robot 
48*fd76c71bSTreehugger Robot     /**
49*fd76c71bSTreehugger Robot      * Reports type names of the columns of the query result.
50*fd76c71bSTreehugger Robot      * This is available from SQLite 2.6.0 on and needs
51*fd76c71bSTreehugger Robot      * the PRAGMA show_datatypes to be turned on.<BR><BR>
52*fd76c71bSTreehugger Robot      *
53*fd76c71bSTreehugger Robot      * @param types string array holding column types
54*fd76c71bSTreehugger Robot      */
55*fd76c71bSTreehugger Robot 
types(String types[])56*fd76c71bSTreehugger Robot     public void types(String types[]);
57*fd76c71bSTreehugger Robot 
58*fd76c71bSTreehugger Robot     /**
59*fd76c71bSTreehugger Robot      * Reports row data of the query result.
60*fd76c71bSTreehugger Robot      * This method is invoked for each row of the
61*fd76c71bSTreehugger Robot      * result set. If true is returned the running
62*fd76c71bSTreehugger Robot      * SQLite query is aborted.<BR><BR>
63*fd76c71bSTreehugger Robot      *
64*fd76c71bSTreehugger Robot      * @param rowdata string array holding the column values of the row
65*fd76c71bSTreehugger Robot      */
66*fd76c71bSTreehugger Robot 
newrow(String rowdata[])67*fd76c71bSTreehugger Robot     public boolean newrow(String rowdata[]);
68*fd76c71bSTreehugger Robot }
69