Skip to content

Commit

Permalink
Merge pull request #115 from RobertZenz/jdbc3resultset-char-datatype-…
Browse files Browse the repository at this point in the history
…detection

Added detection of the CHAR datatype.
  • Loading branch information
gitblit authored Jun 23, 2016
2 parents 4484854 + c80e783 commit ac2a972
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/sqlite/jdbc3/JDBC3ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public int getColumnType(int col) throws SQLException {

if (valueType == SQLITE_TEXT || valueType == SQLITE_NULL) {
if ("CHARACTER".equals(typeName) || "NCHAR".equals(typeName) ||
"NATIVE CHARACTER".equals(typeName)) {
"NATIVE CHARACTER".equals(typeName) || "CHAR".equals(typeName)) {
return Types.CHAR;
}

Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/sqlite/RSMetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public void columnTypes() throws SQLException
"col17 CLOB, col18 BLOB, col19 REAL, col20 DOUBLE, " +
"col21 DOUBLE PRECISION, col22 FLOAT, col23 NUMERIC, " +
"col24 DECIMAL(10,5), col25 BOOLEAN, col26 DATE, col27 DATETIME, " +
"col28 TIMESTAMP)"
"col28 TIMESTAMP, col29 CHAR(70))"
);
// insert empty data into table otherwise getColumnType returns null
stat.executeUpdate(
"insert into tbl values (1, 2, 3, 4, 5, 6, 7, 8, 9," +
"'c', 'varchar', 'varying', 'n', 'n','nvarchar', 'text', 'clob'," +
"null, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 0, 12345, 123456, 0)");
"null, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 0, 12345, 123456, 0, 'char')");
meta = stat.executeQuery(
"select col1, col2, col3, col4, col5, col6, col7, col8, col9, " +
"col10, col11, col12, col13, col14, col15, col16, col17, col18, " +
"col19, col20, col21, col22, col23, col24, col25, col26, col27, " +
"col28, " +
"col28, col29, " +
"cast(col1 as boolean) from tbl"
).getMetaData();

Expand Down Expand Up @@ -126,8 +126,9 @@ public void columnTypes() throws SQLException
assertEquals(Types.DATE, meta.getColumnType(27));

assertEquals(Types.TIMESTAMP, meta.getColumnType(28));
assertEquals(Types.CHAR, meta.getColumnType(29));

assertEquals(Types.BOOLEAN, meta.getColumnType(29));
assertEquals(Types.BOOLEAN, meta.getColumnType(30));

assertEquals(10, meta.getPrecision(24));
assertEquals(5, meta.getScale(24));
Expand Down

0 comments on commit ac2a972

Please sign in to comment.