Changeset 3526

Show
Ignore:
Timestamp:
08/16/09 19:28:20 (3 years ago)
Author:
leo
Message:

changed to report detailed error codes when reporting error

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  
    3535 * SQLite functions. 
    3636 */ 
    37 abstract class DB implements Codes 
    38 { 
     37abstract class DB implements Codes { 
    3938    /** The JDBC Connection that 'owns' this database instance. */ 
    4039    Conn conn = null; 
     
    6362    abstract int enable_load_extension(boolean enable) throws SQLException; 
    6463 
    65     final synchronized void exec(String sql) throws SQLException 
    66     { 
     64    final synchronized void exec(String sql) throws SQLException { 
    6765        long pointer = 0; 
    68         try 
    69         { 
     66        try { 
    7067            pointer = prepare(sql); 
    71             switch (step(pointer)) 
    72             { 
     68            switch (step(pointer)) { 
    7369            case SQLITE_DONE: 
    7470                ensureAutoCommit(); 
     
    8076            } 
    8177        } 
    82         finally 
    83         { 
     78        finally { 
    8479            finalize(pointer); 
    8580        } 
    8681    } 
    8782 
    88     final synchronized void open(Conn conn, String file) throws SQLException 
    89     { 
     83    final synchronized void open(Conn conn, String file) throws SQLException { 
    9084        this.conn = conn; 
    9185        _open(file); 
    9286    } 
    9387 
    94     final synchronized void close() throws SQLException 
    95     { 
     88    final synchronized void close() throws SQLException { 
    9689        // finalize any remaining statements before closing db 
    97         synchronized (stmts) 
    98         { 
     90        synchronized (stmts) { 
    9991            Iterator i = stmts.entrySet().iterator(); 
    100             while (i.hasNext()) 
    101             { 
     92            while (i.hasNext()) { 
    10293                Map.Entry entry = (Map.Entry) i.next(); 
    10394                Stmt stmt = (Stmt) entry.getValue(); 
    10495                finalize(((Long) entry.getKey()).longValue()); 
    105                 if (stmt != null) 
    106                 { 
     96                if (stmt != null) { 
    10797                    stmt.pointer = 0; 
    10898                } 
     
    115105 
    116106        // clean up commit object 
    117         if (begin != 0) 
    118         { 
     107        if (begin != 0) { 
    119108            finalize(begin); 
    120109            begin = 0; 
    121110        } 
    122         if (commit != 0) 
    123         { 
     111        if (commit != 0) { 
    124112            finalize(commit); 
    125113            commit = 0; 
     
    129117    } 
    130118 
    131     final synchronized void prepare(Stmt stmt) throws SQLException 
    132     { 
     119    final synchronized void prepare(Stmt stmt) throws SQLException { 
    133120        if (stmt.pointer != 0) 
    134121            finalize(stmt); 
     
    137124    } 
    138125 
    139     final synchronized int finalize(Stmt stmt) throws SQLException 
    140     { 
     126    final synchronized int finalize(Stmt stmt) throws SQLException { 
    141127        if (stmt.pointer == 0) 
    142128            return 0; 
    143129        int rc = SQLITE_ERROR; 
    144         try 
    145         { 
     130        try { 
    146131            rc = finalize(stmt.pointer); 
    147132        } 
    148         finally 
    149         { 
     133        finally { 
    150134            stmts.remove(new Long(stmt.pointer)); 
    151135            stmt.pointer = 0; 
     
    245229    // COMPOUND FUNCTIONS //////////////////////////////////////////// 
    246230 
    247     final synchronized String[] column_names(long stmt) throws SQLException 
    248     { 
     231    final synchronized String[] column_names(long stmt) throws SQLException { 
    249232        String[] names = new String[column_count(stmt)]; 
    250233        for (int i = 0; i < names.length; i++) 
     
    253236    } 
    254237 
    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 { 
    257239        pos++; 
    258         if (v == null) 
    259         { 
     240        if (v == null) { 
    260241            return bind_null(stmt, pos); 
    261242        } 
    262         else if (v instanceof Integer) 
    263         { 
     243        else if (v instanceof Integer) { 
    264244            return bind_int(stmt, pos, ((Integer) v).intValue()); 
    265245        } 
    266         else if (v instanceof Short) 
    267         { 
     246        else if (v instanceof Short) { 
    268247            return bind_int(stmt, pos, ((Short) v).intValue()); 
    269248        } 
    270         else if (v instanceof Long) 
    271         { 
     249        else if (v instanceof Long) { 
    272250            return bind_long(stmt, pos, ((Long) v).longValue()); 
    273251        } 
    274         else if (v instanceof Float) 
    275         { 
     252        else if (v instanceof Float) { 
    276253            return bind_double(stmt, pos, ((Float) v).doubleValue()); 
    277254        } 
    278         else if (v instanceof Double) 
    279         { 
     255        else if (v instanceof Double) { 
    280256            return bind_double(stmt, pos, ((Double) v).doubleValue()); 
    281257        } 
    282         else if (v instanceof String) 
    283         { 
     258        else if (v instanceof String) { 
    284259            return bind_text(stmt, pos, (String) v); 
    285260        } 
    286         else if (v instanceof byte[]) 
    287         { 
     261        else if (v instanceof byte[]) { 
    288262            return bind_blob(stmt, pos, (byte[]) v); 
    289263        } 
    290         else 
    291         { 
     264        else { 
    292265            throw new SQLException("unexpected param type: " + v.getClass()); 
    293266        } 
    294267    } 
    295268 
    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 { 
    298270        if (count < 1) 
    299271            throw new SQLException("count (" + count + ") < 1"); 
     
    304276        int[] changes = new int[count]; 
    305277 
    306         try 
    307         { 
    308             for (int i = 0; i < count; i++) 
    309             { 
     278        try { 
     279            for (int i = 0; i < count; i++) { 
    310280                reset(stmt); 
    311281                for (int j = 0; j < params; j++) 
     
    314284 
    315285                rc = step(stmt); 
    316                 if (rc != SQLITE_DONE) 
    317                 { 
     286                if (rc != SQLITE_DONE) { 
    318287                    reset(stmt); 
    319288                    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); 
    321291                    throwex(); 
    322292                } 
     
    325295            } 
    326296        } 
    327         finally 
    328         { 
     297        finally { 
    329298            ensureAutoCommit(); 
    330299        } 
     
    334303    } 
    335304 
    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) { 
    340307            final int params = bind_parameter_count(stmt.pointer); 
    341308            if (params != vals.length) 
    342                 throw new SQLException("assertion failure: param count (" + params + ") != value count (" + vals.length 
    343                         + ")"); 
     309                throw new SQLException("assertion failure: param count (" + params 
     310                        + ") != value count (" + vals.length + ")"); 
    344311 
    345312            for (int i = 0; i < params; i++) 
     
    348315        } 
    349316 
    350         switch (step(stmt.pointer)) 
    351         { 
     317        int statusCode = step(stmt.pointer); 
     318        switch (statusCode) { 
    352319        case SQLITE_DONE: 
    353320            reset(stmt.pointer); 
     
    364331        default: 
    365332            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 { 
    372338        if (execute(stmt, vals)) 
    373339            throw new SQLException("query returns results"); 
     
    376342    } 
    377343 
    378     final void throwex() throws SQLException 
    379     { 
     344    final void throwex() throws SQLException { 
    380345        throw new SQLException(errmsg()); 
    381346    } 
    382347 
    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 { 
    385353        SQLiteErrorCode code = SQLiteErrorCode.getErrorCode(errorCode); 
    386         throw new SQLException(String.format("%s (%s)", code, errmsg())); 
     354        return new SQLException(String.format("%s (%s)", code, errmsg())); 
    387355    } 
    388356 
     
    418386     * mode. 
    419387     */ 
    420     final void ensureAutoCommit() throws SQLException 
    421     { 
     388    final void ensureAutoCommit() throws SQLException { 
    422389        if (!conn.getAutoCommit()) 
    423390            return; 
     
    428395            commit = prepare("commit;"); 
    429396 
    430         try 
    431         { 
     397        try { 
    432398            if (step(begin) != SQLITE_DONE) 
    433399                return; // assume we are in a transaction 
    434             if (step(commit) != SQLITE_DONE) 
    435             { 
     400            if (step(commit) != SQLITE_DONE) { 
    436401                reset(commit); 
    437402                throwex(); 
     
    439404            //throw new SQLException("unable to auto-commit"); 
    440405        } 
    441         finally 
    442         { 
     406        finally { 
    443407            reset(begin); 
    444408            reset(commit); 
  • XerialJ/trunk/sqlite-jdbc/src/main/java/org/sqlite/RS.java

    r2254 r3526  
    1616package org.sqlite; 
    1717 
    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; 
     18import java.sql.Date; 
     19import java.sql.ResultSet; 
     20import java.sql.ResultSetMetaData; 
     21import java.sql.SQLException; 
     22import java.sql.SQLWarning; 
     23import java.sql.Statement; 
     24import java.sql.Time; 
     25import java.sql.Timestamp; 
     26import java.sql.Types; 
    2427import java.util.Calendar; 
    25 import java.util.Map; 
    2628 
    2729/** 
    2830 * Implements a JDBC ResultSet. 
    2931 */ 
    30 final class RS extends Unused implements ResultSet, ResultSetMetaData, Codes 
    31 { 
     32final class RS extends Unused implements ResultSet, ResultSetMetaData, Codes { 
    3233    private final Stmt stmt; 
    3334    private final DB db; 
    3435 
    35     boolean open = false   ; // true means have results and can iterate them 
    36     int maxRows;              // max. number of rows as set by a Statement 
    37     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() 
    3839    String[] colsMeta = null; // same as cols, but used by Meta interface 
    3940    boolean[][] meta = null; 
    4041 
    4142    private int limitRows; // 0 means no limit, must check against maxRows 
    42     private int row = 1;   // number of current row, starts at 1 
    43     private int lastCol;   // last column accessed, for wasNull(). -1 if none 
     43    private int row = 1; // number of current row, starts at 1 
     44    private int lastCol; // last column accessed, for wasNull(). -1 if none 
    4445 
    4546    RS(Stmt stmt) { 
    4647        this.stmt = stmt; 
    47         this.db   = stmt.db; 
    48     } 
    49  
     48        this.db = stmt.db; 
     49    } 
    5050 
    5151    // INTERNAL FUNCTIONS /////////////////////////////////////////// 
    5252 
    53     boolean isOpen() { return open; } 
     53    boolean isOpen() { 
     54        return open; 
     55    } 
    5456 
    5557    /* Throws SQLException if ResultSet is not open. */ 
    5658    void checkOpen() throws SQLException { 
    57         if (!open) throw new SQLException("ResultSet closed"); 
     59        if (!open) 
     60            throw new SQLException("ResultSet closed"); 
    5861    } 
    5962 
    6063    // takes col in [1,x] form, returns in [0,x-1] form 
    6164    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 + "]"); 
    6669        return --col; 
    6770    } 
     
    6972    // takes col in [1,x] form, marks it as last accessed and returns [0,x-1] 
    7073    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; 
    7278    } 
    7379 
    7480    private void checkMeta() throws SQLException { 
    7581        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    } 
    7985 
    8086    // ResultSet Functions ////////////////////////////////////////// 
     
    99105        checkOpen(); 
    100106        int c = -1; 
    101         for (int i=0; i < cols.length; i++) { 
     107        for (int i = 0; i < cols.length; i++) { 
    102108            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()) == '.')) { 
    105112                if (c == -1) 
    106113                    c = i; 
    107114                else 
    108                     throw new SQLException("ambiguous column: '"+col+"'"); 
     115                    throw new SQLException("ambiguous column: '" + col + "'"); 
    109116            } 
    110117        } 
    111118        if (c == -1) 
    112             throw new SQLException("no such column: '"+col+"'"); 
     119            throw new SQLException("no such column: '" + col + "'"); 
    113120        else 
    114121            return c + 1; 
     
    116123 
    117124    public boolean next() throws SQLException { 
    118         if (!open) return false;  // finished ResultSet 
     125        if (!open) 
     126            return false; // finished ResultSet 
    119127        lastCol = -1; 
    120128 
    121129        // 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        } 
    123134 
    124135        // 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; 
    127140 
    128141        // 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; 
    138155        } 
    139156    } 
    140157 
    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 
    144166    public void setFetchSize(int rows) throws SQLException { 
    145167        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; 
    149170    } 
    150171 
    151172    public int getFetchDirection() throws SQLException { 
    152         checkOpen(); return ResultSet.FETCH_FORWARD; } 
     173        checkOpen(); 
     174        return ResultSet.FETCH_FORWARD; 
     175    } 
     176 
    153177    public void setFetchDirection(int d) throws SQLException { 
    154178        checkOpen(); 
     
    157181    } 
    158182 
    159     public boolean isAfterLast() throws SQLException { return !open; } 
     183    public boolean isAfterLast() throws SQLException { 
     184        return !open; 
     185    } 
     186 
    160187    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 
    163195    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    } 
    169206 
    170207    public boolean wasNull() throws SQLException { 
     
    172209    } 
    173210 
    174  
    175211    // DATA ACCESS FUNCTIONS //////////////////////////////////////// 
    176212 
    177213    public boolean getBoolean(int col) throws SQLException { 
    178         return getInt(col) == 0 ? false : true; } 
     214        return getInt(col) == 0 ? false : true; 
     215    } 
     216 
    179217    public boolean getBoolean(String col) throws SQLException { 
    180         return getBoolean(findColumn(col)); } 
     218        return getBoolean(findColumn(col)); 
     219    } 
    181220 
    182221    public byte getByte(int col) throws SQLException { 
    183         return (byte)getInt(col); } 
     222        return (byte) getInt(col); 
     223    } 
     224 
    184225    public byte getByte(String col) throws SQLException { 
    185         return getByte(findColumn(col)); } 
     226        return getByte(findColumn(col)); 
     227    } 
    186228 
    187229    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 
    189233    public byte[] getBytes(String col) throws SQLException { 
    190         return getBytes(findColumn(col)); } 
     234        return getBytes(findColumn(col)); 
     235    } 
    191236 
    192237    public Date getDate(int col) throws SQLException { 
     
    195240        return new Date(db.column_long(stmt.pointer, markCol(col))); 
    196241    } 
     242 
    197243    public Date getDate(int col, Calendar cal) throws SQLException { 
    198244        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    199245            return null; 
    200         if (cal == null) return getDate(col); 
     246        if (cal == null) 
     247            return getDate(col); 
    201248        cal.setTimeInMillis(db.column_long(stmt.pointer, markCol(col))); 
    202249        return new Date(cal.getTime().getTime()); 
    203250    } 
     251 
    204252    public Date getDate(String col) throws SQLException { 
    205         return getDate(findColumn(col), Calendar.getInstance()); } 
     253        return getDate(findColumn(col), Calendar.getInstance()); 
     254    } 
     255 
    206256    public Date getDate(String col, Calendar cal) throws SQLException { 
    207         return getDate(findColumn(col), cal); } 
     257        return getDate(findColumn(col), cal); 
     258    } 
    208259 
    209260    public double getDouble(int col) throws SQLException { 
     
    212263        return db.column_double(stmt.pointer, markCol(col)); 
    213264    } 
     265 
    214266    public double getDouble(String col) throws SQLException { 
    215         return getDouble(findColumn(col)); } 
     267        return getDouble(findColumn(col)); 
     268    } 
    216269 
    217270    public float getFloat(int col) throws SQLException { 
    218271        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    219272            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 
    222276    public float getFloat(String col) throws SQLException { 
    223         return getFloat(findColumn(col)); } 
     277        return getFloat(findColumn(col)); 
     278    } 
    224279 
    225280    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 
    227284    public int getInt(String col) throws SQLException { 
    228         return getInt(findColumn(col)); } 
     285        return getInt(findColumn(col)); 
     286    } 
    229287 
    230288    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 
    232292    public long getLong(String col) throws SQLException { 
    233         return getLong(findColumn(col)); } 
     293        return getLong(findColumn(col)); 
     294    } 
    234295 
    235296    public short getShort(int col) throws SQLException { 
    236         return (short)getInt(col); } 
     297        return (short) getInt(col); 
     298    } 
     299 
    237300    public short getShort(String col) throws SQLException { 
    238         return getShort(findColumn(col)); } 
     301        return getShort(findColumn(col)); 
     302    } 
    239303 
    240304    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 
    242308    public String getString(String col) throws SQLException { 
    243         return getString(findColumn(col)); } 
     309        return getString(findColumn(col)); 
     310    } 
    244311 
    245312    public Time getTime(int col) throws SQLException { 
    246313        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    247314            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 
    249318    public Time getTime(int col, Calendar cal) throws SQLException { 
    250         if (cal == null) return getTime(col); 
     319        if (cal == null) 
     320            return getTime(col); 
    251321        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    252322            return null; 
     
    254324        return new Time(cal.getTime().getTime()); 
    255325    } 
     326 
    256327    public Time getTime(String col) throws SQLException { 
    257         return getTime(findColumn(col)); } 
     328        return getTime(findColumn(col)); 
     329    } 
     330 
    258331    public Time getTime(String col, Calendar cal) throws SQLException { 
    259         return getTime(findColumn(col), cal); } 
     332        return getTime(findColumn(col), cal); 
     333    } 
    260334 
    261335    public Timestamp getTimestamp(int col) throws SQLException { 
    262336        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    263337            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 
    265341    public Timestamp getTimestamp(int col, Calendar cal) throws SQLException { 
    266         if (cal == null) return getTimestamp(col); 
     342        if (cal == null) 
     343            return getTimestamp(col); 
    267344        if (db.column_type(stmt.pointer, markCol(col)) == SQLITE_NULL) 
    268345            return null; 
     
    270347        return new Timestamp(cal.getTime().getTime()); 
    271348    } 
     349 
    272350    public Timestamp getTimestamp(String col) throws SQLException { 
    273         return getTimestamp(findColumn(col)); } 
     351        return getTimestamp(findColumn(col)); 
     352    } 
     353 
    274354    public Timestamp getTimestamp(String c, Calendar ca) throws SQLException { 
    275         return getTimestamp(findColumn(c), ca); } 
     355        return getTimestamp(findColumn(c), ca); 
     356    } 
    276357 
    277358    public Object getObject(int col) throws SQLException { 
    278359        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); 
    292375        } 
    293376    } 
     377 
    294378    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 
    300394    public void clearWarnings() throws SQLException {} 
    301395 
     
    306400 
    307401    public ResultSetMetaData getMetaData() throws SQLException { 
    308         return this; } 
     402        return this; 
     403    } 
    309404 
    310405    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 
    312409    public String getColumnClassName(int col) throws SQLException { 
    313         checkCol(col); return "java.lang.Object"; } 
     410        checkCol(col); 
     411        return "java.lang.Object"; 
     412    } 
     413 
    314414    public int getColumnCount() throws SQLException { 
    315         checkCol(1); return colsMeta.length; 
    316     } 
     415        checkCol(1); 
     416        return colsMeta.length; 
     417    } 
     418 
    317419    public int getColumnDisplaySize(int col) throws SQLException { 
    318         return Integer.MAX_VALUE; } 
     420        return Integer.MAX_VALUE; 
     421    } 
     422 
    319423    public String getColumnLabel(int col) throws SQLException { 
    320         return getColumnName(col); } 
     424        return getColumnName(col); 
     425    } 
     426 
    321427    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 
    323431    public int getColumnType(int col) throws SQLException { 
    324432        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; 
    332444        } 
    333445    } 
     446 
    334447    public String getColumnTypeName(int col) throws SQLException { 
    335448        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"; 
    342460        } 
    343461    } 
    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 
    347475    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 
    349479    public int isNullable(int col) throws SQLException { 
    350480        checkMeta(); 
    351         return meta[checkCol(col)][1] ? columnNoNulls: columnNullable; 
    352     } 
     481        return meta[checkCol(col)][1] ? columnNoNulls : columnNullable; 
     482    } 
     483 
    353484    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 
    357497    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    } 
    369532}