Commits

rkonoval committed 975459c

#81: The method getObject in RS class processes null value incorrectly

Problem:
RS.wasNull() returns incorrect values or sometimes exception is thrown (index out of range) after getObject()
Reason:
getObject doesn't remember last accessed column if value in column is null
Fix:
remember last accessed column in getObject

Comments (0)

Files changed (2)

src/main/java/org/sqlite/RS.java

      * @see java.sql.ResultSet#getObject(int)
      */
     public Object getObject(int col) throws SQLException {
-        switch (db.column_type(stmt.pointer, checkCol(col))) {
+        switch (db.column_type(stmt.pointer, markCol(col))) {
         case SQLITE_INTEGER:
             long val = getLong(col);
             if (val > Integer.MAX_VALUE || val < Integer.MIN_VALUE) {

src/test/java/org/sqlite/StatementTest.java

     }
 
     @Test
+    public void nullsForGetObject() throws SQLException {
+        ResultSet rs = stat.executeQuery("select 1, null union all select null, null;");
+        assertTrue(rs.next());
+        assertNotNull(rs.getString(1));
+        assertFalse(rs.wasNull());
+        assertNull(rs.getObject(2));
+        assertTrue(rs.wasNull());
+        assertTrue(rs.next());
+        assertNull(rs.getObject(2));
+        assertTrue(rs.wasNull());
+        assertNull(rs.getObject(1));
+        assertTrue(rs.wasNull());
+        assertFalse(rs.next());
+        rs.close();
+    }
+
+    @Test
     public void tempTable() throws SQLException {
         assertEquals(stat.executeUpdate("create temp table myTemp (a);"), 0);
         assertEquals(stat.executeUpdate("insert into myTemp values (2);"), 1);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.