Skip to content

Commit

Permalink
[CONJ-810] normalization of resultset getDate/getTime of timestamp fi…
Browse files Browse the repository at this point in the history
…eld.

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance is now 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated (current client timezone or if option `useLegacyDatetimeCode` is disabled to server timezone).

Same for java.sql.Time: The date components is set to the "zero epoch" value of January 1, 1970.

example: getTime() on value '2015-03-29T01:45:00.012' return a java.sql.Time  with value '01:45:00', submethod getTime return time in millisecond that did correspond to '2015-03-29T01:45:00.012'. Now correspond to '1970-01-01T01:45:00.012'
  • Loading branch information
rusher committed Sep 24, 2020
1 parent 8e82bc5 commit 143e8c9
Show file tree
Hide file tree
Showing 19 changed files with 642 additions and 324 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,22 @@
# Change Log

## [2.7.0](https://github.com/mariadb-corporation/mariadb-connector-j/tree/2.7.0) (24 Sep. 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/2.6.2...2.7.0)

* CONJ-805 maxFieldSize string truncation occurs on bytes length, not character length
* CONJ-807 Correcting possible Get Access Denied error if using multiple classloader
* CONJ-810 normalization of resultset getDate/getTime of timestamp field.
* CONJ-812 DatabaseMetadata.getBestRowIdentifier and getMaxProcedureNameLength correction
* CONJ-813 setConfiguration not being called on classes that extend ConfigurableSocketFactory
* CONJ-816 Table with primary key with DEFAULT function can be inserted for 10.5 servers
* CONJ-817 Switched position of REMARKS and PROCEDURE_TYPE in the getProcedures result
* CONJ-820 MySQLPreparedStatement.setObject can now handle java.lang.Character type
* CONJ-828 new option `ensureSocketState` to ensure protocol state
* CONJ-829 Option to cache callablestatement is now disabled by default
* CONJ-830 connector now throw a better error if SSL is mandatory and server doesn't support SSL
* CONJ-814 Small possible improvement of getCrossReference, getExportedKeys and getImportedKey
* CONJ-825 XAResource.isSameRM implementation

## [2.6.2](https://github.com/mariadb-corporation/mariadb-connector-j/tree/2.6.2) (23 Jul. 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/2.6.1...2.6.2)

Expand Down
25 changes: 8 additions & 17 deletions src/main/java/org/mariadb/jdbc/BasePrepareStatement.java
Expand Up @@ -911,22 +911,19 @@ public void setObject(final int parameterIndex, final Object obj) throws SQLExce
parameterIndex,
new ZonedDateTimeParameter(
((OffsetDateTime) obj).toZonedDateTime(),
protocol.getTimeZone().toZoneId(),
protocol.getTimeZone(),
useFractionalSeconds,
options));
} else if (obj instanceof OffsetTime) {
setParameter(
parameterIndex,
new OffsetTimeParameter(
(OffsetTime) obj, protocol.getTimeZone().toZoneId(), useFractionalSeconds, options));
(OffsetTime) obj, protocol.getTimeZone(), useFractionalSeconds, options));
} else if (obj instanceof ZonedDateTime) {
setParameter(
parameterIndex,
new ZonedDateTimeParameter(
(ZonedDateTime) obj,
protocol.getTimeZone().toZoneId(),
useFractionalSeconds,
options));
(ZonedDateTime) obj, protocol.getTimeZone(), useFractionalSeconds, options));
} else if (obj instanceof LocalTime) {
setParameter(parameterIndex, new LocalTimeParameter((LocalTime) obj, useFractionalSeconds));
} else {
Expand Down Expand Up @@ -1025,17 +1022,14 @@ private void setInternalObject(
setParameter(
parameterIndex,
new OffsetTimeParameter(
OffsetTime.parse(str),
protocol.getTimeZone().toZoneId(),
useFractionalSeconds,
options));
OffsetTime.parse(str), protocol.getTimeZone(), useFractionalSeconds, options));
break;
case Types.TIMESTAMP_WITH_TIMEZONE:
setParameter(
parameterIndex,
new ZonedDateTimeParameter(
ZonedDateTime.parse(str, SPEC_ISO_ZONED_DATE_TIME),
protocol.getTimeZone().toZoneId(),
protocol.getTimeZone(),
useFractionalSeconds,
options));
break;
Expand Down Expand Up @@ -1136,22 +1130,19 @@ private void setInternalObject(
parameterIndex,
new ZonedDateTimeParameter(
((OffsetDateTime) obj).toZonedDateTime(),
protocol.getTimeZone().toZoneId(),
protocol.getTimeZone(),
useFractionalSeconds,
options));
} else if (obj instanceof OffsetTime) {
setParameter(
parameterIndex,
new OffsetTimeParameter(
(OffsetTime) obj, protocol.getTimeZone().toZoneId(), useFractionalSeconds, options));
(OffsetTime) obj, protocol.getTimeZone(), useFractionalSeconds, options));
} else if (obj instanceof ZonedDateTime) {
setParameter(
parameterIndex,
new ZonedDateTimeParameter(
(ZonedDateTime) obj,
protocol.getTimeZone().toZoneId(),
useFractionalSeconds,
options));
(ZonedDateTime) obj, protocol.getTimeZone(), useFractionalSeconds, options));
} else if (obj instanceof LocalTime) {
setParameter(parameterIndex, new LocalTimeParameter((LocalTime) obj, useFractionalSeconds));
} else {
Expand Down
Expand Up @@ -1214,7 +1214,7 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
System.arraycopy(row.buf, row.pos, data, 0, row.getLengthMaxFieldSize());
return (T) data;

} else if (type.equals(Date.class)) {
} else if (type.equals(Date.class) || type.equals(java.util.Date.class)) {
return (T) row.getInternalDate(col, null, timeZone);

} else if (type.equals(Time.class)) {
Expand All @@ -1227,7 +1227,8 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
return (T) (Boolean) row.getInternalBoolean(col);

} else if (type.equals(Calendar.class)) {
Calendar calendar = Calendar.getInstance(timeZone);
Calendar calendar =
timeZone == null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
Timestamp timestamp = row.getInternalTimestamp(col, null, timeZone);
if (timestamp == null) {
return null;
Expand Down
Expand Up @@ -688,16 +688,13 @@ private void updateInternalObject(
case Types.TIME_WITH_TIMEZONE:
parameterHolders[parameterIndex - 1] =
new OffsetTimeParameter(
OffsetTime.parse(str),
timeZone.toZoneId(),
options.useFractionalSeconds,
options);
OffsetTime.parse(str), timeZone, options.useFractionalSeconds, options);
break;
case Types.TIMESTAMP_WITH_TIMEZONE:
parameterHolders[parameterIndex - 1] =
new ZonedDateTimeParameter(
ZonedDateTime.parse(str, BasePrepareStatement.SPEC_ISO_ZONED_DATE_TIME),
timeZone.toZoneId(),
timeZone,
options.useFractionalSeconds,
options);
break;
Expand Down Expand Up @@ -797,17 +794,17 @@ private void updateInternalObject(
parameterHolders[parameterIndex - 1] =
new ZonedDateTimeParameter(
((OffsetDateTime) obj).toZonedDateTime(),
timeZone.toZoneId(),
timeZone,
options.useFractionalSeconds,
options);
} else if (obj instanceof OffsetTime) {
parameterHolders[parameterIndex - 1] =
new OffsetTimeParameter(
(OffsetTime) obj, timeZone.toZoneId(), options.useFractionalSeconds, options);
(OffsetTime) obj, timeZone, options.useFractionalSeconds, options);
} else if (obj instanceof ZonedDateTime) {
parameterHolders[parameterIndex - 1] =
new ZonedDateTimeParameter(
(ZonedDateTime) obj, timeZone.toZoneId(), options.useFractionalSeconds, options);
(ZonedDateTime) obj, timeZone, options.useFractionalSeconds, options);
} else if (obj instanceof LocalTime) {
updateTime(parameterIndex, Time.valueOf((LocalTime) obj));
} else {
Expand Down

0 comments on commit 143e8c9

Please sign in to comment.