Vm.java revision 7a647e8547e57ca573541be55b3728ef7ce376fe
1417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespackage SQLite; 2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/** 4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Class to represent compiled SQLite VM. 5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic class Vm { 8417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 10417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Internal handle for the compiled SQLite VM. 11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes private long handle = 0; 14417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Internal last error code for compile()/step() methods. 17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 18417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 19417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes protected int error_code = 0; 20417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 21417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 22417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Perform one step on compiled SQLite VM. 23417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * The result row is passed to the given callback interface.<BR><BR> 24417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * 25417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Example:<BR> 26417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * <PRE> 27417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * ... 28417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * try { 29417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Vm vm = db.compile("select * from x; select * from y;"); 30417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * while (vm.step(cb)) { 31417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * ... 32417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * } 33417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * while (vm.compile()) { 34417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * while (vm.step(cb)) { 35417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * ... 36417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * } 37417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * } 38417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * } catch (SQLite.Exception e) { 39417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * } 40417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * </PRE> 41417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * 42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * @param cb the object implementing the callback methods. 43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * @return true as long as more row data can be retrieved, 44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * false, otherwise. 45417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 46417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 47417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public native boolean step(Callback cb) throws SQLite.Exception; 48417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Compile the next SQL statement for the SQLite VM instance. 51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * @return true when SQL statement has been compiled, false 52417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * on end of statement sequence. 53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public native boolean compile() throws SQLite.Exception; 56417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 57417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 58417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Abort the compiled SQLite VM. 59417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 60417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 61417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public native void stop() throws SQLite.Exception; 62417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 63417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 64417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Destructor for object. 65417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 66417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 67417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes protected native void finalize(); 68417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 69417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /** 70417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Internal native initializer. 71417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */ 72417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 73417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes private static native void internal_init(); 74417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 75417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes static { 767a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes internal_init(); 77417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 78417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes} 79