Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for Bug#91112 (28125069), AGAIN WRONG JAVA.SQL.DATE.
- Loading branch information
Showing
17 changed files
with
230 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, version 2.0, as published by the | ||
|
@@ -33,6 +33,9 @@ | |
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
import com.mysql.cj.conf.PropertyKey; | ||
import com.mysql.cj.conf.PropertySet; | ||
import com.mysql.cj.conf.RuntimeProperty; | ||
import com.mysql.cj.exceptions.CJException; | ||
import com.mysql.cj.exceptions.ExceptionFactory; | ||
import com.mysql.cj.exceptions.ExceptionInterceptor; | ||
|
@@ -53,11 +56,15 @@ public class ServerPreparedQueryBindValue extends ClientPreparedQueryBindValue i | |
public Calendar calendar; | ||
|
||
private TimeZone defaultTimeZone; | ||
private TimeZone serverTimeZone; | ||
private RuntimeProperty<Boolean> cacheDefaultTimezone = null; | ||
|
||
protected String charEncoding = null; | ||
|
||
public ServerPreparedQueryBindValue(TimeZone defaultTZ) { | ||
public ServerPreparedQueryBindValue(TimeZone defaultTZ, TimeZone serverTZ, PropertySet pset) { | ||
this.defaultTimeZone = defaultTZ; | ||
this.serverTimeZone = serverTZ; | ||
this.cacheDefaultTimezone = pset.getBooleanProperty(PropertyKey.cacheDefaultTimezone); | ||
} | ||
|
||
@Override | ||
|
@@ -68,7 +75,7 @@ public ServerPreparedQueryBindValue clone() { | |
private ServerPreparedQueryBindValue(ServerPreparedQueryBindValue copyMe) { | ||
super(copyMe); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
soklakov
Author
Contributor
|
||
|
||
this.defaultTimeZone = copyMe.defaultTimeZone; | ||
this.serverTimeZone = copyMe.serverTimeZone; | ||
this.bufferType = copyMe.bufferType; | ||
this.calendar = copyMe.calendar; | ||
this.charEncoding = copyMe.charEncoding; | ||
|
@@ -229,6 +236,8 @@ public void storeBinding(NativePacketPayload intoPacket, boolean isLoadDataQuery | |
storeTime(intoPacket); | ||
return; | ||
case MysqlType.FIELD_TYPE_DATE: | ||
storeDate(intoPacket); | ||
return; | ||
case MysqlType.FIELD_TYPE_DATETIME: | ||
case MysqlType.FIELD_TYPE_TIMESTAMP: | ||
storeDateTime(intoPacket); | ||
|
@@ -263,7 +272,7 @@ private void storeTime(NativePacketPayload intoPacket) { | |
intoPacket.writeInteger(IntegerDataType.INT4, 0); // tm->day, not used | ||
|
||
if (this.calendar == null) { | ||
this.calendar = Calendar.getInstance(this.defaultTimeZone, Locale.US); | ||
this.calendar = Calendar.getInstance(this.serverTimeZone, Locale.US); | ||
} | ||
|
||
this.calendar.setTime((java.util.Date) this.value); | ||
|
@@ -272,14 +281,46 @@ private void storeTime(NativePacketPayload intoPacket) { | |
intoPacket.writeInteger(IntegerDataType.INT1, this.calendar.get(Calendar.SECOND)); | ||
} | ||
|
||
private void storeDate(NativePacketPayload intoPacket) { | ||
synchronized (this) { | ||
if (this.calendar == null) { | ||
this.calendar = Calendar.getInstance(this.cacheDefaultTimezone.getValue() ? this.defaultTimeZone : TimeZone.getDefault(), Locale.US); | ||
} | ||
|
||
this.calendar.setTime((java.util.Date) this.value); | ||
|
||
this.calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
this.calendar.set(Calendar.MINUTE, 0); | ||
this.calendar.set(Calendar.SECOND, 0); | ||
|
||
byte length = (byte) 7; | ||
|
||
intoPacket.ensureCapacity(length); | ||
|
||
intoPacket.writeInteger(IntegerDataType.INT1, length); // length | ||
|
||
int year = this.calendar.get(Calendar.YEAR); | ||
int month = this.calendar.get(Calendar.MONTH) + 1; | ||
int date = this.calendar.get(Calendar.DAY_OF_MONTH); | ||
|
||
intoPacket.writeInteger(IntegerDataType.INT2, year); | ||
intoPacket.writeInteger(IntegerDataType.INT1, month); | ||
intoPacket.writeInteger(IntegerDataType.INT1, date); | ||
|
||
intoPacket.writeInteger(IntegerDataType.INT1, 0); | ||
intoPacket.writeInteger(IntegerDataType.INT1, 0); | ||
intoPacket.writeInteger(IntegerDataType.INT1, 0); | ||
} | ||
} | ||
|
||
/** | ||
* @param intoPacket | ||
* packet to write into | ||
*/ | ||
private void storeDateTime(NativePacketPayload intoPacket) { | ||
synchronized (this) { | ||
if (this.calendar == null) { | ||
this.calendar = Calendar.getInstance(this.defaultTimeZone, Locale.US); | ||
this.calendar = Calendar.getInstance(this.serverTimeZone, Locale.US); | ||
} | ||
|
||
this.calendar.setTime((java.util.Date) this.value); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@soklakov
Here, when copyMe has cacheDefaultTimezone defined, this value is not set to the creation of the current ServerPreparedQueryBindValue object, and leads to a NPE at line 287.
I have this NPE but I'm not totally sure about the source. May it be this constructor missing cacheDefaultTimezone assignment.
I can raise an issue but I don't know where yet. Thanks !