Skip to content

Commit e6a9f5e

Browse files
committed
fixed reading boolean in detached result set (database metadata). fixes 2586
1 parent f78e975 commit e6a9f5e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ public static Object convert(Object value, Class<?> type, ClickHouseColumn colum
232232
} else if (type == String.class) {
233233
return value.toString();
234234
} else if (type == Boolean.class || type == boolean.class) {
235-
return Boolean.parseBoolean(value.toString());
235+
String str = value.toString();
236+
return !("false".equalsIgnoreCase(str) || "0".equalsIgnoreCase(str));
236237
} else if (type == Byte.class || type == byte.class) {
237238
return Byte.parseByte(value.toString());
238239
} else if (type == Short.class || type == short.class) {

jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testGetColumns() throws Exception {
3737
final String tableName = "get_columns_metadata_test";
3838
try (Statement stmt = conn.createStatement()) {
3939
stmt.executeUpdate("" +
40-
"CREATE TABLE " + tableName + " (id Int32, name String, v1 Nullable(Int8)) " +
40+
"CREATE TABLE " + tableName + " (id Int32, name String NOT NULL, v1 Nullable(Int8)) " +
4141
"ENGINE MergeTree ORDER BY ()");
4242
}
4343

@@ -109,6 +109,7 @@ public void testGetColumns() throws Exception {
109109
assertEquals(rs.getInt("DATA_TYPE"), Types.INTEGER);
110110
assertEquals(rs.getObject("DATA_TYPE"), Types.INTEGER);
111111
assertEquals(rs.getString("TYPE_NAME"), "Int32");
112+
assertFalse(rs.getBoolean("NULLABLE"));
112113

113114
assertTrue(rs.next());
114115
assertEquals(rs.getString("TABLE_SCHEM"), getDatabase());
@@ -117,6 +118,7 @@ public void testGetColumns() throws Exception {
117118
assertEquals(rs.getInt("DATA_TYPE"), Types.VARCHAR);
118119
assertEquals(rs.getObject("DATA_TYPE"), Types.VARCHAR);
119120
assertEquals(rs.getString("TYPE_NAME"), "String");
121+
assertFalse(rs.getBoolean("NULLABLE"));
120122

121123
assertTrue(rs.next());
122124
assertEquals(rs.getString("TABLE_SCHEM"), getDatabase());
@@ -125,6 +127,7 @@ public void testGetColumns() throws Exception {
125127
assertEquals(rs.getInt("DATA_TYPE"), Types.TINYINT);
126128
assertEquals(rs.getObject("DATA_TYPE"), Types.TINYINT);
127129
assertEquals(rs.getString("TYPE_NAME"), "Nullable(Int8)");
130+
assertTrue(rs.getBoolean("NULLABLE"));
128131
}
129132
}
130133
}

0 commit comments

Comments
 (0)