Changeset 3526
- Timestamp:
- 08/16/09 19:28:20 (3 years ago)
- Location:
- XerialJ/trunk/sqlite-jdbc/src/main/java/org/sqlite
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
XerialJ/trunk/sqlite-jdbc/src/main/java/org/sqlite/DB.java
r3229 r3526 35 35 * SQLite functions. 36 36 */ 37 abstract class DB implements Codes 38 { 37 abstract class DB implements Codes { 39 38 /** The JDBC Connection that 'owns' this database instance. */ 40 39 Conn conn = null; … … 63 62 abstract int enable_load_extension(boolean enable) throws SQLException; 64 63 65 final synchronized void exec(String sql) throws SQLException 66 { 64 final synchronized void exec(String sql) throws SQLException { 67 65 long pointer = 0; 68 try 69 { 66 try { 70 67 pointer = prepare(sql); 71 switch (step(pointer)) 72 { 68 switch (step(pointer)) { 73 69 case SQLITE_DONE: 74 70 ensureAutoCommit(); … … 80 76 } 81 77 } 82 finally 83 { 78 finally { 84 79 finalize(pointer); 85 80 } 86 81 } 87 82 88 final synchronized void open(Conn conn, String file) throws SQLException 89 { 83 final synchronized void open(Conn conn, String file) throws SQLException { 90 84 this.conn = conn; 91 85 _open(file); 92 86 } 93 87 94 final synchronized void close() throws SQLException 95 { 88 final synchronized void close() throws SQLException { 96 89 // finalize any remaining statements before closing db 97 synchronized (stmts) 98 { 90 synchronized (stmts) { 99 91 Iterator i = stmts.entrySet().iterator(); 100 while (i.hasNext()) 101 { 92 while (i.hasNext()) { 102 93 Map.Entry entry = (Map.Entry) i.next(); 103 94 Stmt stmt = (Stmt) entry.getValue(); 104 95 finalize(((Long) entry.getKey()).longValue()); 105 if (stmt != null) 106 { 96 if (stmt != null) { 107 97 stmt.pointer = 0; 108 98 } … … 115 105 116 106 // clean up commit object 117 if (begin != 0) 118 { 107 if (begin != 0) { 119 108 finalize(begin); 120 109 begin = 0; 121 110 } 122 if (commit != 0) 123 { 111 if (commit != 0) { 124 112 finalize(commit); 125 113 commit = 0; … … 129 117 } 130 118 131 final synchronized void prepare(Stmt stmt) throws SQLException 132 { 119 final synchronized void prepare(Stmt stmt) throws SQLException { 133 120 if (stmt.pointer != 0) 134 121 finalize(stmt); … … 137 124 } 138 125 139 final synchronized int finalize(Stmt stmt) throws SQLException 140 { 126 final synchronized int finalize(Stmt stmt) throws SQLException { 141 127 if (stmt.pointer == 0) 142 128 return 0; 143 129 int rc = SQLITE_ERROR; 144 try 145 { 130 try { 146 131 rc = finalize(stmt.pointer); 147 132 } 148 finally 149 { 133 finally { 150 134 stmts.remove(new Long(stmt.pointer)); 151 135 stmt.pointer = 0; … … 245 229 // COMPOUND FUNCTIONS //////////////////////////////////////////// 246 230 247 final synchronized String[] column_names(long stmt) throws SQLException 248 { 231 final synchronized String[] column_names(long stmt) throws SQLException { 249 232 String[] names = new String[column_count(stmt)]; 250 233 for (int i = 0; i < names.length; i++) … … 253 236 } 254 237 255 final synchronized int sqlbind(long stmt, int pos, Object v) throws SQLException 256 { 238 final synchronized int sqlbind(long stmt, int pos, Object v) throws SQLException { 257 239 pos++; 258 if (v == null) 259 { 240 if (v == null) { 260 241 return bind_null(stmt, pos); 261 242 } 262 else if (v instanceof Integer) 263 { 243 else if (v instanceof Integer) { 264 244 return bind_int(stmt, pos, ((Integer) v).intValue()); 265 245 } 266 else if (v instanceof Short) 267 { 246 else if (v instanceof Short) { 268 247 return bind_int(stmt, pos, ((Short) v).intValue()); 269 248 } 270 else if (v instanceof Long) 271 { 249 else if (v instanceof Long) { 272 250 return bind_long(stmt, pos, ((Long) v).longValue()); 273 251 } 274 else if (v instanceof Float) 275 { 252 else if (v instanceof Float) { 276 253 return bind_double(stmt, pos, ((Float) v).doubleValue()); 277 254 } 278 else if (v instanceof Double) 279 { 255 else if (v instanceof Double) { 280 256 return bind_double(stmt, pos, ((Double) v).doubleValue()); 281 257 } 282 else if (v instanceof String) 283 { 258 else if (v instanceof String) { 284 259 return bind_text(stmt, pos, (String) v); 285 260 } 286 else if (v instanceof byte[]) 287 { 261 else if (v instanceof byte[]) { 288 262 return bind_blob(stmt, pos, (byte[]) v); 289 263 } 290 else 291 { 264 else { 292 265 throw new SQLException("unexpected param type: " + v.getClass()); 293 266 } 294 267 } 295 268 296 final synchronized int[] executeBatch(long stmt, int count, Object[] vals) throws SQLException 297 { 269 final synchronized int[] executeBatch(long stmt, int count, Object[] vals) throws SQLException { 298 270 if (count < 1) 299 271 throw new SQLException("count (" + count + ") < 1"); … … 304 276 int[] changes = new int[count]; 305 277 306 try 307 { 308 for (int i = 0; i < count; i++) 309 { 278 try { 279 for (int i = 0; i < count; i++) { 310 280 reset(stmt); 311 281 for (int j = 0; j < params; j++) … … 314 284 315 285 rc = step(stmt); 316 if (rc != SQLITE_DONE) 317 { 286 if (rc != SQLITE_DONE) { 318 287 reset(stmt); 319 288 if (rc == SQLITE_ROW) 320 throw new BatchUpdateException("batch entry " + i + ": query returns results", changes); 289 throw new BatchUpdateException("batch entry " + i 290 + ": query returns results", changes); 321 291 throwex(); 322 292 } … … 325 295 } 326 296 } 327 finally 328 { 297 finally { 329 298 ensureAutoCommit(); 330 299 } … … 334 303 } 335 304 336 final synchronized boolean execute(Stmt stmt, Object[] vals) throws SQLException 337 { 338 if (vals != null) 339 { 305 final synchronized boolean execute(Stmt stmt, Object[] vals) throws SQLException { 306 if (vals != null) { 340 307 final int params = bind_parameter_count(stmt.pointer); 341 308 if (params != vals.length) 342 throw new SQLException("assertion failure: param count (" + params + ") != value count (" + vals.length343 + ") ");309 throw new SQLException("assertion failure: param count (" + params 310 + ") != value count (" + vals.length + ")"); 344 311 345 312 for (int i = 0; i < params; i++) … … 348 315 } 349 316 350 switch (step(stmt.pointer))351 {317 int statusCode = step(stmt.pointer); 318 switch (statusCode) { 352 319 case SQLITE_DONE: 353 320 reset(stmt.pointer); … … 364 331 default: 365 332 finalize(stmt); 366 throw new SQLException(errmsg()); 367 } 368 } 369 370 final synchronized int executeUpdate(Stmt stmt, Object[] vals) throws SQLException 371 { 333 throw newSQLException(statusCode); 334 } 335 } 336 337 final synchronized int executeUpdate(Stmt stmt, Object[] vals) throws SQLException { 372 338 if (execute(stmt, vals)) 373 339 throw new SQLException("query returns results"); … … 376 342 } 377 343 378 final void throwex() throws SQLException 379 { 344 final void throwex() throws SQLException { 380 345 throw new SQLException(errmsg()); 381 346 } 382 347 383 final void throwex(int errorCode) throws SQLException 384 { 348 final void throwex(int errorCode) throws SQLException { 349 throw newSQLException(errorCode); 350 } 351 352 private SQLException newSQLException(int errorCode) throws SQLException { 385 353 SQLiteErrorCode code = SQLiteErrorCode.getErrorCode(errorCode); 386 thrownew SQLException(String.format("%s (%s)", code, errmsg()));354 return new SQLException(String.format("%s (%s)", code, errmsg())); 387 355 } 388 356 … … 418 386 * mode. 419 387 */ 420 final void ensureAutoCommit() throws SQLException 421 { 388 final void ensureAutoCommit() throws SQLException { 422 389 if (!conn.getAutoCommit()) 423 390 return; … … 428 395 commit = prepare("commit;"); 429 396 430 try 431 { 397 try { 432 398 if (step(begin) != SQLITE_DONE) 433 399 return; // assume we are in a transaction 434 if (step(commit) != SQLITE_DONE) 435 { 400 if (step(commit) != SQLITE_DONE) { 436 401 reset(commit); 437 402 throwex(); … … 439 404 //throw new SQLException("unable to auto-commit"); 440 405 } 441 finally 442 { 406 finally { 443 407 reset(begin); 444 408 reset(commit); -
XerialJ/trunk/sqlite-jdbc/src/main/java/org/sqlite/RS.java
r2254 r3526 16 16 package org.sqlite; 17 17 18 import java.sql.*; 19 20 import java.io.InputStream; 21 import java.io.Reader; 22 import java.math.BigDecimal; 23 import java.net.URL; 18 import java.sql.Date; 19 import java.sql.ResultSet; 20 import java.sql.ResultSetMetaData; 21 import java.sql.SQLException; 22 import java.sql.SQLWarning; 23 import java.sql.Statement; 24 import java.sql.Time; 25 import java.sql.Timestamp; 26 import java.sql.Types; 24 27 import java.util.Calendar; 25 import java.util.Map;26 28 27 29 /** 28 30 * Implements a JDBC ResultSet. 29 31 */ 30 final class RS extends Unused implements ResultSet, ResultSetMetaData, Codes 31 { 32 final class RS extends Unused implements ResultSet, ResultSetMetaData, Codes { 32 33 private final Stmt stmt; 33 34 private final DB db; 34 35 35 boolean open = false ;// true means have results and can iterate them36 int maxRows; // max. number of rows as set by a Statement37 String[] cols = null; // if null, the RS is closed()36 boolean open = false; // true means have results and can iterate them 37 int maxRows; // max. number of rows as set by a Statement 38 String[] cols = null; // if null, the RS is closed() 38 39 String[] colsMeta = null; // same as cols, but used by Meta interface 39 40 boolean[][] meta = null; 40 41 41 42 private int limitRows; // 0 means no limit, must check against maxRows 42 private int row = 1; // number of current row, starts at 143 private int lastCol; // last column accessed, for wasNull(). -1 if none43 private int row = 1; // number of current row, starts at 1 44 private int lastCol; // last column accessed, for wasNull(). -1 if none 44 45 45 46 RS(Stmt stmt) { 46 47 this.stmt = stmt; 47 this.db = stmt.db; 48 } 49 48 this.db = stmt.db; 49 } 50 50 51 51 // INTERNAL FUNCTIONS /////////////////////////////////////////// 52 52 53 boolean isOpen() { return open; } 53 boolean isOpen() { 54 return open; 55 } 54 56 55 57 /* Throws SQLException if ResultSet is not open. */ 56 58 void checkOpen() throws SQLException { 57 if (!open) throw new SQLException("ResultSet closed"); 59 if (!open) 60 throw new SQLException("ResultSet closed"); 58 61 } 59 62 60 63 // takes col in [1,x] form, returns in [0,x-1] form 61 64 private int checkCol(int col) throws SQLException { 62 if (colsMeta == null) throw new IllegalStateException(63 "SQLite JDBC: inconsistent internal state");64 if (col < 1 || col > colsMeta.length) throw new SQLException(65 "column " + col + " out of bounds [1," + colsMeta.length + "]");65 if (colsMeta == null) 66 throw new IllegalStateException("SQLite JDBC: inconsistent internal state"); 67 if (col < 1 || col > colsMeta.length) 68 throw new SQLException("column " + col + " out of bounds [1," + colsMeta.length + "]"); 66 69 return --col; 67 70 } … … 69 72 // takes col in [1,x] form, marks it as last accessed and returns [0,x-1] 70 73 private int markCol(int col) throws SQLException { 71 checkOpen(); checkCol(col); lastCol = col; return --col; 74 checkOpen(); 75 checkCol(col); 76 lastCol = col; 77 return --col; 72 78 } 73 79 74 80 private void checkMeta() throws SQLException { 75 81 checkCol(1); 76 if (meta == null) meta = db.column_metadata(stmt.pointer);77 }78 82 if (meta == null) 83 meta = db.column_metadata(stmt.pointer); 84 } 79 85 80 86 // ResultSet Functions ////////////////////////////////////////// … … 99 105 checkOpen(); 100 106 int c = -1; 101 for (int i =0; i < cols.length; i++) {107 for (int i = 0; i < cols.length; i++) { 102 108 if (col.equalsIgnoreCase(cols[i]) 103 || (cols[i].toUpperCase().endsWith(col.toUpperCase()) && 104 cols[i].charAt(cols[i].length() - col.length()) == '.')) { 109 || (cols[i].toUpperCase().endsWith(col.toUpperCase()) && cols[i].charAt(cols[i] 110 .length() 111 - col.length()) == '.')) { 105 112 if (c == -1) 106 113 c = i; 107 114 else 108 throw new SQLException("ambiguous column: '" +col+"'");115 throw new SQLException("ambiguous column: '" + col + "'"); 109 116 } 110 117 } 111 118 if (c == -1) 112 throw new SQLException("no such column: '" +col+"'");119 throw new SQLException("no such column: '" + col + "'"); 113 120 else 114 121 return c + 1; … … 116 123 117 124 public boolean next() throws SQLException { 118 if (!open) return false; // finished ResultSet 125 if (!open) 126 return false; // finished ResultSet 119 127 lastCol = -1; 120 128 121 129 // first row is loaded by execute(), so do not step() again 122 if (row == 1) { row++; return true; } 130 if (row == 1) { 131 row++; 132 return true; 133 } 123 134 124 135 // check if we are row limited by the statement or the ResultSet 125 if (maxRows != 0 && row > maxRows) return false; 126 if (limitRows != 0 && row >= limitRows) return false; 136 if (maxRows != 0 && row > maxRows) 137 return false; 138 if (limitRows != 0 && row >= limitRows) 139 return false; 127 140 128 141 // do the real work 129 switch (db.step(stmt.pointer)) { 130 case SQLITE_DONE: 131 close(); // agressive closing to avoid writer starvation 132 return false; 133 case SQLITE_ROW: row++; return true; 134 case SQLITE_BUSY: 135 throw new SQLException("database locked"); 136 default: 137 db.throwex(); return false; 142 int statusCode = db.step(stmt.pointer); 143 switch (statusCode) { 144 case SQLITE_DONE: 145 close(); // agressive closing to avoid writer starvation 146 return false; 147 case SQLITE_ROW: 148 row++; 149 return true; 150 case SQLITE_BUSY: 151 throw new SQLException("database locked"); 152 default: 153 db.throwex(statusCode); 154 return false; 138 155 } 139 156 } 140 157 141 public int getType() throws SQLException { return TYPE_FORWARD_ONLY; } 142 143 public int getFetchSize() throws SQLException { return limitRows; } 158 public int getType() throws SQLException { 159 return TYPE_FORWARD_ONLY; 160 } 161 162 public int getFetchSize() throws SQLException { 163 return limitRows; 164 } 165 144 166 public void setFetchSize(int rows) throws SQLException { 145 167 if (0 > rows || (maxRows != 0 && rows > maxRows)) 146 throw new SQLException("fetch size " + rows 147 + " out of bounds " + maxRows); 148 limitRows = rows; 168 throw new SQLException("fetch size " + rows + " out of bounds " + maxRows); 169 limitRows = rows; 149 170 } 150 171 151 172 public int getFetchDirection() throws SQLException { 152 checkOpen(); return ResultSet.FETCH_FORWARD; } 173 checkOpen(); 174 return ResultSet.FETCH_FORWARD; 175 } 176 153 177 public void setFetchDirection(int d) throws SQLException { 154 178 checkOpen(); … … 157 181 } 158 182 159 public boolean isAfterLast() throws SQLException { return !open; } 183 public boolean isAfterLast() throws SQLException { 184 return !open; 185 } 186 160 187 public boolean isBeforeFirst() throws SQLException { 161 return open && row == 1; } 162 public boolean isFirst() throws SQLException { return row == 2; } 188 return open && row == 1; 189 } 190 191 public boolean isFirst() throws SQLException { 192 return row == 2; 193 } 194 163 195 public boolean isLast() throws SQLException { // FIXME 164 throw new SQLException("function not yet implemented for SQLite"); } 165 166 protected void finalize() throws SQLException { close(); } 167 168 public int getRow() throws SQLException { return row; } 196 throw new SQLException("function not yet implemented for SQLite"); 197 } 198 199 protected void finalize() throws SQLException { 200 close(); 201 } 202 203 public int getRow() throws SQLException { 204 return row; 205 } 169 206 170 207 public boolean wasNull() throws SQLException { … … 172 209 } 173 210 174 175 211 // DATA ACCESS FUNCTIONS //////////////////////////////////////// 176 212 177 213 public boolean getBoolean(int col) throws SQLException { 178 return getInt(col) == 0 ? false : true; } 214 return getInt(col) == 0 ? false : true; 215 } 216 179 217 public boolean getBoolean(String col) throws SQLException { 180 return getBoolean(findColumn(col)); } 218 return getBoolean(findColumn(col)); 219 } 181 220 182 221 public byte getByte(int col) throws SQLException { 183 return (byte)getInt(col); } 222 return (byte) getInt(col); 223 } 224 184 225 public byte getByte(String col) throws SQLException { 185 return getByte(findColumn(col)); } 226 return getByte(findColumn(col)); 227 } 186 228 187 229 public byte[] getBytes(int col) throws SQLException { 188 return db.column_blob(stmt.pointer, markCol(col)); } 230 return db.column_blob(stmt.pointer, markCol(col)); 231 } 232 189 233 public byte[] getBytes(String col) throws SQLException { 190 return getBytes(findColumn(col)); } 234 return getBytes(findColumn(col)); 235 } 191 236 192 237 public Date getDate(int col) throws SQLException { … … 195 240 return new Date(db.column_long(stmt.pointer, markCol(col))); 196 241 } 242 197 243 public Date getDate(int col, Calendar cal) throws SQLException { 198 244 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 199 245 return null; 200 if (cal == null) return getDate(col); 246 if (cal == null) 247 return getDate(col); 201 248 cal.setTimeInMillis(db.column_long(stmt.pointer, markCol(col))); 202 249 return new Date(cal.getTime().getTime()); 203 250 } 251 204 252 public Date getDate(String col) throws SQLException { 205 return getDate(findColumn(col), Calendar.getInstance()); } 253 return getDate(findColumn(col), Calendar.getInstance()); 254 } 255 206 256 public Date getDate(String col, Calendar cal) throws SQLException { 207 return getDate(findColumn(col), cal); } 257 return getDate(findColumn(col), cal); 258 } 208 259 209 260 public double getDouble(int col) throws SQLException { … … 212 263 return db.column_double(stmt.pointer, markCol(col)); 213 264 } 265 214 266 public double getDouble(String col) throws SQLException { 215 return getDouble(findColumn(col)); } 267 return getDouble(findColumn(col)); 268 } 216 269 217 270 public float getFloat(int col) throws SQLException { 218 271 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 219 272 return 0; 220 return (float)db.column_double(stmt.pointer, markCol(col)); 221 } 273 return (float) db.column_double(stmt.pointer, markCol(col)); 274 } 275 222 276 public float getFloat(String col) throws SQLException { 223 return getFloat(findColumn(col)); } 277 return getFloat(findColumn(col)); 278 } 224 279 225 280 public int getInt(int col) throws SQLException { 226 return db.column_int(stmt.pointer, markCol(col)); } 281 return db.column_int(stmt.pointer, markCol(col)); 282 } 283 227 284 public int getInt(String col) throws SQLException { 228 return getInt(findColumn(col)); } 285 return getInt(findColumn(col)); 286 } 229 287 230 288 public long getLong(int col) throws SQLException { 231 return db.column_long(stmt.pointer, markCol(col)); } 289 return db.column_long(stmt.pointer, markCol(col)); 290 } 291 232 292 public long getLong(String col) throws SQLException { 233 return getLong(findColumn(col)); } 293 return getLong(findColumn(col)); 294 } 234 295 235 296 public short getShort(int col) throws SQLException { 236 return (short)getInt(col); } 297 return (short) getInt(col); 298 } 299 237 300 public short getShort(String col) throws SQLException { 238 return getShort(findColumn(col)); } 301 return getShort(findColumn(col)); 302 } 239 303 240 304 public String getString(int col) throws SQLException { 241 return db.column_text(stmt.pointer, markCol(col)); } 305 return db.column_text(stmt.pointer, markCol(col)); 306 } 307 242 308 public String getString(String col) throws SQLException { 243 return getString(findColumn(col)); } 309 return getString(findColumn(col)); 310 } 244 311 245 312 public Time getTime(int col) throws SQLException { 246 313 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 247 314 return null; 248 return new Time(db.column_long(stmt.pointer, markCol(col))); } 315 return new Time(db.column_long(stmt.pointer, markCol(col))); 316 } 317 249 318 public Time getTime(int col, Calendar cal) throws SQLException { 250 if (cal == null) return getTime(col); 319 if (cal == null) 320 return getTime(col); 251 321 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 252 322 return null; … … 254 324 return new Time(cal.getTime().getTime()); 255 325 } 326 256 327 public Time getTime(String col) throws SQLException { 257 return getTime(findColumn(col)); } 328 return getTime(findColumn(col)); 329 } 330 258 331 public Time getTime(String col, Calendar cal) throws SQLException { 259 return getTime(findColumn(col), cal); } 332 return getTime(findColumn(col), cal); 333 } 260 334 261 335 public Timestamp getTimestamp(int col) throws SQLException { 262 336 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 263 337 return null; 264 return new Timestamp(db.column_long(stmt.pointer, markCol(col))); } 338 return new Timestamp(db.column_long(stmt.pointer, markCol(col))); 339 } 340 265 341 public Timestamp getTimestamp(int col, Calendar cal) throws SQLException { 266 if (cal == null) return getTimestamp(col); 342 if (cal == null) 343 return getTimestamp(col); 267 344 if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 268 345 return null; … … 270 347 return new Timestamp(cal.getTime().getTime()); 271 348 } 349 272 350 public Timestamp getTimestamp(String col) throws SQLException { 273 return getTimestamp(findColumn(col)); } 351 return getTimestamp(findColumn(col)); 352 } 353 274 354 public Timestamp getTimestamp(String c, Calendar ca) throws SQLException { 275 return getTimestamp(findColumn(c), ca); } 355 return getTimestamp(findColumn(c), ca); 356 } 276 357 277 358 public Object getObject(int col) throws SQLException { 278 359 switch (db.column_type(stmt.pointer, checkCol(col))) { 279 case SQLITE_INTEGER: 280 long val = getLong(col); 281 if (val > (long)Integer.MAX_VALUE 282 || val < (long)Integer.MIN_VALUE) 283 return new Long(val); 284 else 285 return new Integer((int)val); 286 case SQLITE_FLOAT: return new Double(getDouble(col)); 287 case SQLITE_BLOB: return getBytes(col); 288 case SQLITE_NULL: return null; 289 case SQLITE_TEXT: 290 default: 291 return getString(col); 360 case SQLITE_INTEGER: 361 long val = getLong(col); 362 if (val > (long) Integer.MAX_VALUE || val < (long) Integer.MIN_VALUE) 363 return new Long(val); 364 else 365 return new Integer((int) val); 366 case SQLITE_FLOAT: 367 return new Double(getDouble(col)); 368 case SQLITE_BLOB: 369 return getBytes(col); 370 case SQLITE_NULL: 371 return null; 372 case SQLITE_TEXT: 373 default: 374 return getString(col); 292 375 } 293 376 } 377 294 378 public Object getObject(String col) throws SQLException { 295 return getObject(findColumn(col)); } 296 297 public Statement getStatement() { return stmt; } 298 public String getCursorName() throws SQLException { return null; } 299 public SQLWarning getWarnings() throws SQLException { return null; } 379 return getObject(findColumn(col)); 380 } 381 382 public Statement getStatement() { 383 return stmt; 384 } 385 386 public String getCursorName() throws SQLException { 387 return null; 388 } 389 390 public SQLWarning getWarnings() throws SQLException { 391 return null; 392 } 393 300 394 public void clearWarnings() throws SQLException {} 301 395 … … 306 400 307 401 public ResultSetMetaData getMetaData() throws SQLException { 308 return this; } 402 return this; 403 } 309 404 310 405 public String getCatalogName(int col) throws SQLException { 311 return db.column_table_name(stmt.pointer, checkCol(col)); } 406 return db.column_table_name(stmt.pointer, checkCol(col)); 407 } 408 312 409 public String getColumnClassName(int col) throws SQLException { 313 checkCol(col); return "java.lang.Object"; } 410 checkCol(col); 411 return "java.lang.Object"; 412 } 413 314 414 public int getColumnCount() throws SQLException { 315 checkCol(1); return colsMeta.length; 316 } 415 checkCol(1); 416 return colsMeta.length; 417 } 418 317 419 public int getColumnDisplaySize(int col) throws SQLException { 318 return Integer.MAX_VALUE; } 420 return Integer.MAX_VALUE; 421 } 422 319 423 public String getColumnLabel(int col) throws SQLException { 320 return getColumnName(col); } 424 return getColumnName(col); 425 } 426 321 427 public String getColumnName(int col) throws SQLException { 322 return db.column_name(stmt.pointer, checkCol(col)); } 428 return db.column_name(stmt.pointer, checkCol(col)); 429 } 430 323 431 public int getColumnType(int col) throws SQLException { 324 432 switch (db.column_type(stmt.pointer, checkCol(col))) { 325 case SQLITE_INTEGER: return Types.INTEGER; 326 case SQLITE_FLOAT: return Types.FLOAT; 327 case SQLITE_BLOB: return Types.BLOB; 328 case SQLITE_NULL: return Types.NULL; 329 case SQLITE_TEXT: 330 default: 331 return Types.VARCHAR; 433 case SQLITE_INTEGER: 434 return Types.INTEGER; 435 case SQLITE_FLOAT: 436 return Types.FLOAT; 437 case SQLITE_BLOB: 438 return Types.BLOB; 439 case SQLITE_NULL: 440 return Types.NULL; 441 case SQLITE_TEXT: 442 default: 443 return Types.VARCHAR; 332 444 } 333 445 } 446 334 447 public String getColumnTypeName(int col) throws SQLException { 335 448 switch (db.column_type(stmt.pointer, checkCol(col))) { 336 case SQLITE_INTEGER: return "integer"; 337 case SQLITE_FLOAT: return "float"; 338 case SQLITE_BLOB: return "blob"; 339 case SQLITE_NULL: return "null"; 340 case SQLITE_TEXT: 341 default: return "text"; 449 case SQLITE_INTEGER: 450 return "integer"; 451 case SQLITE_FLOAT: 452 return "float"; 453 case SQLITE_BLOB: 454 return "blob"; 455 case SQLITE_NULL: 456 return "null"; 457 case SQLITE_TEXT: 458 default: 459 return "text"; 342 460 } 343 461 } 344 public int getPrecision(int col) throws SQLException { return 0; } // FIXME 345 public int getScale(int col) throws SQLException { return 0; } 346 public String getSchemaName(int col) throws SQLException { return ""; } 462 463 public int getPrecision(int col) throws SQLException { 464 return 0; 465 } // FIXME 466 467 public int getScale(int col) throws SQLException { 468 return 0; 469 } 470 471 public String getSchemaName(int col) throws SQLException { 472 return ""; 473 } 474 347 475 public String getTableName(int col) throws SQLException { 348 return db.column_table_name(stmt.pointer, checkCol(col)); } 476 return db.column_table_name(stmt.pointer, checkCol(col)); 477 } 478 349 479 public int isNullable(int col) throws SQLException { 350 480 checkMeta(); 351 return meta[checkCol(col)][1] ? columnNoNulls: columnNullable; 352 } 481 return meta[checkCol(col)][1] ? columnNoNulls : columnNullable; 482 } 483 353 484 public boolean isAutoIncrement(int col) throws SQLException { 354 checkMeta(); return meta[checkCol(col)][2]; } 355 public boolean isCaseSensitive(int col) throws SQLException { return true; } 356 public boolean isCurrency(int col) throws SQLException { return false; } 485 checkMeta(); 486 return meta[checkCol(col)][2]; 487 } 488 489 public boolean isCaseSensitive(int col) throws SQLException { 490 return true; 491 } 492 493 public boolean isCurrency(int col) throws SQLException { 494 return false; 495 } 496 357 497 public boolean isDefinitelyWritable(int col) throws SQLException { 358 return true; } // FIXME: check db file constraints? 359 public boolean isReadOnly(int col) throws SQLException { return false; } 360 public boolean isSearchable(int col) throws SQLException { return true; } 361 public boolean isSigned(int col) throws SQLException { return false; } 362 public boolean isWritable(int col) throws SQLException { return true; } 363 364 public int getConcurrency() throws SQLException { return CONCUR_READ_ONLY; } 365 366 public boolean rowDeleted() throws SQLException { return false; } 367 public boolean rowInserted() throws SQLException { return false; } 368 public boolean rowUpdated() throws SQLException { return false; } 498 return true; 499 } // FIXME: check db file constraints? 500 501 public boolean isReadOnly(int col) throws SQLException { 502 return false; 503 } 504 505 public boolean isSearchable(int col) throws SQLException { 506 return true; 507 } 508 509 public boolean isSigned(int col) throws SQLException { 510 return false; 511 } 512 513 public boolean isWritable(int col) throws SQLException { 514 return true; 515 } 516 517 public int getConcurrency() throws SQLException { 518 return CONCUR_READ_ONLY; 519 } 520 521 public boolean rowDeleted() throws SQLException { 522 return false; 523 } 524 525 public boolean rowInserted() throws SQLException { 526 return false; 527 } 528 529 public boolean rowUpdated() throws SQLException { 530 return false; 531 } 369 532 }


