Grace Batumbya avatar Grace Batumbya committed e58aa26

Fixes #12: MetaData.getColumns() should return "YES" or "NO" for IS_NULLABLE column

Comments (0)

Files changed (2)

src/main/java/org/sqlite/MetaData.java

                 + "2000000000 as BUFFER_LENGTH, " + "10   as DECIMAL_DIGITS, " + "10   as NUM_PREC_RADIX, "
                 + "colnullable as NULLABLE, " + "null as REMARKS, " + "null as COLUMN_DEF, "
                 + "0    as SQL_DATA_TYPE, " + "0    as SQL_DATETIME_SUB, " + "2000000000 as CHAR_OCTET_LENGTH, "
-                + "ordpos as ORDINAL_POSITION, " + "(case colnullable when 0 then 'N' when 1 then 'Y' else '' end)"
+                + "ordpos as ORDINAL_POSITION, " + "(case colnullable when 0 then 'NO' when 1 then 'YES' else '' end)"
                 + "    as IS_NULLABLE, " + "null as SCOPE_CATLOG, " + "null as SCOPE_SCHEMA, "
                 + "null as SCOPE_TABLE, " + "null as SOURCE_DATA_TYPE from (";
 

src/test/java/org/sqlite/DBMetaDataTest.java

     public void connect() throws Exception {
         conn = DriverManager.getConnection("jdbc:sqlite:");
         stat = conn.createStatement();
-        stat.executeUpdate("create table test (id integer primary key, fn float, sn);");
+        stat.executeUpdate("create table test (id integer primary key, fn float, sn not null);");
         stat.executeUpdate("create view testView as select * from test;");
         meta = conn.getMetaData();
     }
         assertTrue(rs.next());
         assertEquals(rs.getString("COLUMN_NAME"), "fn");
         assertEquals(rs.getInt("DATA_TYPE"), Types.FLOAT);
+        assertEquals(rs.getString("IS_NULLABLE"), "YES");
         assertFalse(rs.next());
 
         rs = meta.getColumns(null, null, "test", "sn");
         assertTrue(rs.next());
         assertEquals(rs.getString("COLUMN_NAME"), "sn");
+        assertEquals(rs.getString("IS_NULLABLE"), "NO");
         assertFalse(rs.next());
 
         rs = meta.getColumns(null, null, "test", "%");
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.