Hi Evgenij ,
3. 1.4.200 definitely has a bug, but I have no idea why you ever use
> `ResultSet.getTimestamp()` on a `TIME` column. Applications normally use
> ResultSet.getObject(column, LocalTime.class) (this is the best choice for
> H2) or legacy ResultSet.getTime(column) (has problems at least in one time
> zone due to own design flaws of java.sql.Time). Even more, conversion from
> TIME to TIMESTAMP was aligned with the SQL Standard in H2 1.4.200 (due to
> bug in JDBC layer in this version you need to use CAST directly in the SQL
> code to see how it works). This conversion in not compatible with old
> versions of H2 anyway.,
>
1.4.200s getDate() has also problems with ancient dates. When accessing h2
using SQL Workbench/J the following commands:
---
create table test (someDate Date, someTimestamp Timestamp);
insert into test (someDate, someTimestamp) values ('0001-01-01',
'0001-01-01 00:00:00');
select * from test;
---
return '0001-01-03' and '0001-01-03 00:06:32.000'. Since
LocalDate/LocalDateTime seem to work without problems, I tried to change
the getters in org.h2.jdbc.JdbcResultSet to e.g.
public Timestamp getTimestamp(int columnIndex) throws SQLException {
LocalDateTime localDateTime = getObject(columnIndex, LocalDateTime.class);
return localDateTime != null ? Timestamp.valueOf(localDateTime) : null;
}
and the setters in org.h2.jdbc.JdbcPreparedStatement to e.g.
public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws
SQLException {
if (isDebugEnabled()) {
debugCode("setTimestamp(" + parameterIndex + ", " +
quoteTimestamp(x) + ");");
}
setObject(parameterIndex, x != null ? x.toLocalDateTime() : null);
}
With this change the correct values are returned. Would you accept a pull
request that implements this change? Or will this cause other problems?
Best regards,
Niklas
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/h2-database/5086849b-e445-427a-b60a-7cdf27685702n%40googlegroups.com.