Skip to content

Commit

Permalink
Merge pull request #1 from Stongtong/Stongtong-patch-1
Browse files Browse the repository at this point in the history
Update DuckDBResultSet.java
  • Loading branch information
Stongtong authored Jul 17, 2024
2 parents 53fdd83 + 21b091d commit 5ded9c2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/org/duckdb/DuckDBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1249,6 +1250,14 @@ public <T> T getObject(int columnIndex, Class<T> 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));
Expand Down Expand Up @@ -1286,7 +1295,19 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
}

public <T> T getObject(String columnLabel, Class<T> 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
Expand Down

0 comments on commit 5ded9c2

Please sign in to comment.