Skip to content

Commit 0c8242d

Browse files
author
Paultagoras
committed
Override getObject for integer metadata
1 parent 36d52d7 commit 0c8242d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ public MetadataResultSet transform(String columnLabel, ClickHouseColumn column,
4949
return this;
5050
}
5151

52+
@Override
53+
public Object getObject(String columnLabel) throws SQLException {
54+
try {
55+
return getInt(columnLabel);
56+
} catch (SQLException e) {
57+
// If the column is not an integer, fall back to the default behavior
58+
return super.getObject(columnLabel);
59+
}
60+
}
61+
62+
@Override
63+
public Object getObject(int columnIndex) throws SQLException {
64+
if (columnIndex < 1 || columnIndex > cachedColumnLabels.length) {
65+
throw new SQLException("Invalid column index: " + columnIndex);
66+
}
67+
return getObject(cachedColumnLabels[columnIndex - 1]);
68+
}
69+
70+
5271
@Override
5372
public String getString(String columnLabel) throws SQLException {
5473
String value = super.getString(columnLabel);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void testGetColumns() throws Exception {
6262
assertEquals(rs.getString("TABLE_NAME"), tableName);
6363
assertEquals(rs.getString("TYPE_NAME"), columnTypeNames.get(colIndex));
6464
assertEquals(rs.getInt("DATA_TYPE"), columnJDBCDataTypes.get(colIndex));
65+
assertEquals(rs.getObject("DATA_TYPE"), columnJDBCDataTypes.get(colIndex));
6566
assertEquals(rs.getInt("COLUMN_SIZE"), columnSizes.get(colIndex));
6667
assertEquals(rs.getInt("ORDINAL_POSITION"), colIndex + 1);
6768
assertEquals(rs.getInt("NULLABLE"), columnNullable.get(colIndex) ? DatabaseMetaData.attributeNullable : DatabaseMetaData.attributeNoNulls);

0 commit comments

Comments
 (0)