1. Taro L. Saito
  2. sqlite-jdbc
Issue #81 new

The method getObject in RS class processes null value incorrectly.

Anonymous created an issue

The method DO NOT update lastCol field where value is SQLITE_NULL. In this situation, wasNull return wrong value.

Comments (1)

  1. escabe

    The following code illustrates this issue (at least I think we are talking about the same issue here):

    public class MainClass {
        public static void main(String[] args) throws ClassNotFoundException {
            Class.forName("org.sqlite.JDBC");
            Connection connection = null;
            try {
                connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
                Statement statement = connection.createStatement();
                statement.executeUpdate("drop table if exists example");
                statement.executeUpdate("create table example (col1 blob, col2 integer)");
                statement.executeUpdate("insert into example values(null,42)");
                ResultSet rs = statement.executeQuery("select * from example");
                while(rs.next()) {
                    Object blobdata = rs.getObject(1);
                    if (rs.wasNull()) {
                        System.out.println("BLOB was null");
                    } else {
                        System.out.println(blobdata.toString());
                    }
                }
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    

    As this will throw an exception:

    java.sql.SQLException: column -1 out of bounds [1,2]
        at org.sqlite.RS.checkCol(RS.java:99)
        at org.sqlite.RS.markCol(RS.java:112)
        at org.sqlite.RS.wasNull(RS.java:308)
        at MainClass.main(MainClass.java:19)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
    
  2. Log in to comment