From 21b091df192fcf054836d9e0fcee98276e80d036 Mon Sep 17 00:00:00 2001 From: Tongtong Date: Wed, 17 Jul 2024 15:21:57 +0800 Subject: [PATCH] Update DuckDBResultSet.java 1. use mybatis with duckdb call getObject with column name throw exception, fix it; 2. LocalDate type not support, meet this error ,fix it --- src/main/java/org/duckdb/DuckDBResultSet.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/duckdb/DuckDBResultSet.java b/src/main/java/org/duckdb/DuckDBResultSet.java index 1b7a281c..431cfa87 100644 --- a/src/main/java/org/duckdb/DuckDBResultSet.java +++ b/src/main/java/org/duckdb/DuckDBResultSet.java @@ -27,6 +27,7 @@ import java.sql.Struct; import java.sql.Time; import java.sql.Timestamp; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.OffsetTime; @@ -1249,6 +1250,14 @@ public T getObject(int columnIndex, Class type) throws SQLException { } else { throw new SQLException("Can't convert value to Timestamp " + type.toString()); } + } else if (type == LocalDate.class) { + if(sqlType == DuckDBColumnType.DATE) { + final Date date = getDate(columnIndex); + if (date == null) return null; + return type.cast(date.toLocalDate()); + }else { + throw new SQLException("Can't convert value to LocalDate " + type.toString()); + } } else if (type == LocalDateTime.class) { if (isTimestamp(sqlType)) { return type.cast(getLocalDateTime(columnIndex)); @@ -1286,7 +1295,19 @@ public T getObject(int columnIndex, Class type) throws SQLException { } public T getObject(String columnLabel, Class type) throws SQLException { - throw new SQLFeatureNotSupportedException("getObject"); + if (type == null) { + throw new SQLException("type is null"); + } + if (columnLabel == null || columnLabel.isEmpty()) { + throw new SQLException("columnLabel is null"); + } + int index = -1; + for (int i = 0; i < meta.column_names.length; i++) { + if (columnLabel.equals(meta.column_names[i])) index=i; + } + if (index == -1) throw new SQLException(columnLabel + " is not in " + meta.column_names); + index = index + 1; + return getObject(index, type); } @Override