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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
package SQLite;
/**
* Class to represent compiled SQLite3 statement.
*
* Note, that all native methods of this class are
* not synchronized, i.e. it is up to the caller
* to ensure that only one thread is in these
* methods at any one time.
*/
public class Stmt {
/**
* Internal handle for the SQLite3 statement.
*/
private long handle = 0;
/**
* Internal last error code for prepare()/step() methods.
*/
protected int error_code = 0;
/**
* Prepare the next SQL statement for the Stmt instance.
* @return true when the next piece of the SQL statement sequence
* has been prepared, false on end of statement sequence.
*/
public native boolean prepare() throws SQLite.Exception;
/**
* Perform one step of compiled SQLite3 statement.
*
* Example:<BR>
* <PRE>
* ...
* try {
* Stmt s = db.prepare("select * from x; select * from y;");
* s.bind(...);
* ...
* s.bind(...);
* while (s.step(cb)) {
* Object o = s.value(...);
* ...
* }
* // s.reset() for re-execution or
* // s.prepare() for the next piece of SQL
* while (s.prepare()) {
* s.bind(...);
* ...
* s.bind(...);
* while (s.step(cb)) {
* Object o = s.value(...);
* ...
* }
* }
* } catch (SQLite.Exception e) {
* s.close();
* }
* </PRE>
*
* @return true when row data is available, false on end
* of result set.
*/
public native boolean step() throws SQLite.Exception;
/**
* Close the compiled SQLite3 statement.
*/
public native void close() throws SQLite.Exception;
/**
* Reset the compiled SQLite3 statement without
* clearing parameter bindings.
*/
public native void reset() throws SQLite.Exception;
/**
* Clear all bound parameters of the compiled SQLite3 statement.
*/
public native void clear_bindings() throws SQLite.Exception;
/**
* Bind positional integer value to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param value value of parameter
*/
public native void bind(int pos, int value) throws SQLite.Exception;
/**
* Bind positional long value to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param value value of parameter
*/
public native void bind(int pos, long value) throws SQLite.Exception;
/**
* Bind positional double value to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param value value of parameter
*/
public native void bind(int pos, double value) throws SQLite.Exception;
/**
* Bind positional byte array to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param value value of parameter, may be null
*/
public native void bind(int pos, byte[] value) throws SQLite.Exception;
/**
* Bind positional String to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param value value of parameter, may be null
*/
public native void bind(int pos, String value) throws SQLite.Exception;
/**
* Bind positional SQL null to compiled SQLite3 statement.
* @param pos parameter index, 1-based
*/
public native void bind(int pos) throws SQLite.Exception;
/**
* Bind positional zero'ed blob to compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @param length byte size of zero blob
*/
public native void bind_zeroblob(int pos, int length)
throws SQLite.Exception;
/**
* Return number of parameters in compiled SQLite3 statement.
* @return int number of parameters
*/
public native int bind_parameter_count() throws SQLite.Exception;
/**
* Return name of parameter in compiled SQLite3 statement.
* @param pos parameter index, 1-based
* @return String parameter name
*/
public native String bind_parameter_name(int pos) throws SQLite.Exception;
/**
* Return index of named parameter in compiled SQLite3 statement.
* @param name of parameter
* @return int index of parameter, 1-based
*/
public native int bind_parameter_index(String name)
throws SQLite.Exception;
/**
* Retrieve integer column from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return int column value
*/
public native int column_int(int col) throws SQLite.Exception;
/**
* Retrieve long column from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return long column value
*/
public native long column_long(int col) throws SQLite.Exception;
/**
* Retrieve double column from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return double column value
*/
public native double column_double(int col) throws SQLite.Exception;
/**
* Retrieve blob column from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return byte[] column value
*/
public native byte[] column_bytes(int col) throws SQLite.Exception;
/**
* Retrieve string column from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return String column value
*/
public native String column_string(int col) throws SQLite.Exception;
/**
* Retrieve column type from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return column type code, e.g. SQLite.Constants.SQLITE_INTEGER
*/
public native int column_type(int col) throws SQLite.Exception;
/**
* Retrieve number of columns of exec'ed SQLite3 statement.
* @return int number of columns
*/
public native int column_count() throws SQLite.Exception;
/**
* Retrieve column data as object from exec'ed SQLite3 statement.
* @param col column number, 0-based
* @return Object or null
*/
public Object column(int col) throws SQLite.Exception {
switch (column_type(col)) {
case Constants.SQLITE_INTEGER:
return new Long(column_long(col));
case Constants.SQLITE_FLOAT:
return new Double(column_double(col));
case Constants.SQLITE_BLOB:
return column_bytes(col);
case Constants.SQLITE3_TEXT:
return column_string(col);
}
return null;
}
/**
* Return table name of column of SQLite3 statement.
* @param col column number, 0-based
* @return String or null
*/
public native String column_table_name(int col) throws SQLite.Exception;
/**
* Return database name of column of SQLite3 statement.
* @param col column number, 0-based
* @return String or null
*/
public native String column_database_name(int col) throws SQLite.Exception;
/**
* Return declared column type of SQLite3 statement.
* @param col column number, 0-based
* @return String or null
*/
public native String column_decltype(int col) throws SQLite.Exception;
/**
* Return column name of column of SQLite3 statement.
* @param col column number, 0-based
* @return String or null
*/
public native String column_name(int col) throws SQLite.Exception;
/**
* Return origin column name of column of SQLite3 statement.
* @param col column number, 0-based
* @return String or null
*/
public native String column_origin_name(int col) throws SQLite.Exception;
/**
* Return statement status information.
* @param op which counter to report
* @param flg reset flag
* @return counter
*/
public native int status(int op, boolean flg);
/**
* Destructor for object.
*/
protected native void finalize();
/**
* Internal native initializer.
*/
private static native void internal_init();
static {
internal_init();
}
}
|