Skip to content

Commit

Permalink
Fix to JdbcQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz committed Jun 10, 2024
1 parent 6b51b21 commit 9f2ad32
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.TimeZone;
import raw.client.api.LocationDescription;
import raw.runtime.truffle.runtime.exceptions.rdbms.JdbcExceptionHandler;
import raw.runtime.truffle.runtime.exceptions.rdbms.JdbcReaderRawTruffleException;
Expand All @@ -36,6 +40,10 @@ public class JdbcQuery {
private final JdbcExceptionHandler exceptionHandler;
private final String url;

// required to extract time and timestamp values
private final ZoneId timezone = ZoneId.of("UTC");
private final Calendar zonedCalendar = Calendar.getInstance(TimeZone.getTimeZone(timezone));

@TruffleBoundary
public JdbcQuery(
LocationDescription locationDescription,
Expand Down Expand Up @@ -177,7 +185,8 @@ DateObject getDate(String colName, Node node) {
TimeObject getTime(String colName, Node node) {
try {
java.sql.Time sqlTime = rs.getTime(colName);
return new TimeObject(sqlTime.toLocalTime());
LocalTime localTime = LocalTime.ofNanoOfDay(sqlTime.getTime() * 1000000);
return new TimeObject(localTime);
} catch (SQLException e) {
throw exceptionHandler.columnParseError(e, colName, node);
}
Expand All @@ -186,7 +195,7 @@ TimeObject getTime(String colName, Node node) {
@TruffleBoundary
TimestampObject getTimestamp(String colName, Node node) {
try {
java.sql.Timestamp sqlTimestamp = rs.getTimestamp(colName);
java.sql.Timestamp sqlTimestamp = rs.getTimestamp(colName, zonedCalendar);
return new TimestampObject(sqlTimestamp.toLocalDateTime());
} catch (SQLException e) {
throw exceptionHandler.columnParseError(e, colName, node);
Expand Down

0 comments on commit 9f2ad32

Please sign in to comment.