vert-x3 / vertx-jdbc-client

JDBC support for Vert.x
Apache License 2.0
126 stars 90 forks source link

JDBC Oracle and Timestamps #292

Open nikodemusP opened 2 years ago

nikodemusP commented 2 years ago

Version

Vertx 4.3.4, JDBCClient

Questions

Our Oracle-database is setup in the local-timezone "Europe/Vienna" and returns the local-time over JDBC. But within the convertion of the VertX-JDBC the time markt in any case to UTC.

If you do a

pool.preparedQuery("select SESSIONTIMEZONE as sessionTimeZone, sysdate as dateValue, to_char(sysdate,'yyyy-dd-mm hh24:mi:ss') localTime from dual")

The output will be:

"sessionTimeZone":"Europe/Vienna",
"dateValue":"2022-10-17T10:06:45Z",
"localTime":"2022-17-10 10:06:45"

I assume it is related to this code-part (JDBCDecoderImpl.java, Line 188):

        if (descriptor.jdbcType() == JDBCType.TIMESTAMP || descriptor.jdbcType() == JDBCType.TIMESTAMP_WITH_TIMEZONE) {
          return LocalDateTime.parse(value.toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME).atOffset(ZoneOffset.UTC);
        }

The database returns "2022-17-10T10:06:45" and the atOffset(ZoneOffset.UTC) marks this time as UTC-Time. I looked at the JDBC-driver of Oracle and there is no way to make a time-convertion to UTC as it could be done for MySQL. Is there a way to workaround this convertion?

zero88 commented 2 years ago

Hi @nikodemusP I think something is mismatched here. SESSIONTIMEZONE returns the time zone of the current connection session. the time zone is Vienna (UTC+2) sysdate is the current date and time set for the operating system on which the database server resides. As your output "dateValue":"2022-10-17T10:06:45Z", it is UTC+0.

So the dateValue and localTime is in tz UTC+0. Then I think the output is 2022-17-10T10:06:45 is correct (although JDBCDecoderImpl.java, Line 188 is not correct 100%, should switch case between TIMESTAMP and TIMESTAMP_WITH_TIMEZONE -- I already provided a fixed patch, might be available at 4.3.5).

Another thought, when using sql client pool without any specified configuration, the JDBC driver will use the timezone of your backend server/local system, not database timezone. For example:

Back to your question, as default, the Vertx jdbc client always tries to return temporal value in ISO8601 with tz UTC+0. In case you want to customize it, just override JDBCDecoderImpl in the SPI file. Please follow document