diff --git a/CHANGES b/CHANGES index ee4b9aa62..4cebc1cb2 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,9 @@ Version 8.4.0 + - Fix for Bug#113599 (Bug#36171571), Contribution: Replace StringBuffer with StringBuilder in ValueEncoders. + Thanks to Henning Pƶttker for his contribution. + - Fix for Bug#91550 (Bug#28297874), DatabaseMetaData specifies incorrect extra name characters. - Fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect. diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/InstantValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/InstantValueEncoder.java index 8c85a9cd8..dcc67227d 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/InstantValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/InstantValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -76,20 +76,20 @@ public String getString(BindValue binding) { .atZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()).toLocalDateTime()), binding.getField(), binding.keepOrigNanos()); - StringBuffer buf = new StringBuffer(); + sb = new StringBuilder(); - buf.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", + sb.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()) .format(x)); if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - buf.append('\''); + sb.append('\''); - return buf.toString(); + return sb.toString(); case YEAR: return String.valueOf(((Instant) binding.getValue()).atOffset(ZoneOffset.UTC) diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/OffsetDateTimeValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/OffsetDateTimeValueEncoder.java index cacf84e4c..257b0722c 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/OffsetDateTimeValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/OffsetDateTimeValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -75,20 +75,20 @@ public String getString(BindValue binding) { ((OffsetDateTime) binding.getValue()).atZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()).toLocalDateTime()), binding.getField(), binding.keepOrigNanos()); - StringBuffer buf = new StringBuffer(); + sb = new StringBuilder(); - buf.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", + sb.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()) .format(x)); if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - buf.append('\''); + sb.append('\''); - return buf.toString(); + return sb.toString(); case YEAR: return String.valueOf(odt.atZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()).getYear()); diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java index 4cd02d091..a3e1aab33 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -87,15 +87,15 @@ public String getString(BindValue binding) { ts = TimeUtil.truncateFractionalSeconds(ts); } - StringBuffer buf = new StringBuffer(); - buf.append(binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x) + StringBuilder sb = new StringBuilder(); + sb.append(binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x) : TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", this.serverSession.getDefaultTimeZone()).format(x)); if (this.serverSession.getCapabilities().serverSupportsFracSecs() && ts.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(ts.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(ts.getNanos(), 6)); } - buf.append('\''); - return buf.toString(); + sb.append('\''); + return sb.toString(); case YEAR: Calendar cal = Calendar.getInstance(); cal.setTime((java.util.Date) binding.getValue()); diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimestampValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimestampValueEncoder.java index e761bf139..8c84d84b8 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimestampValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimestampValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -75,30 +75,30 @@ public String getString(BindValue binding) { case TEXT: case MEDIUMTEXT: case LONGTEXT: - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (binding.getCalendar() != null) { - buf.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); + sb.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); } else { this.tsdf = TimeUtil.getSimpleDateFormat(this.tsdf, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()); - buf.append(this.tsdf.format(x)); + sb.append(this.tsdf.format(x)); } if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - buf.append('\''); + sb.append('\''); - return buf.toString(); + return sb.toString(); case YEAR: Calendar cal = Calendar.getInstance(); cal.setTime((java.util.Date) binding.getValue()); return String.valueOf(cal.get(Calendar.YEAR)); case TIME: - StringBuilder sb = new StringBuilder("'"); + sb = new StringBuilder("'"); sb.append(adjustLocalTime(((Timestamp) binding.getValue()).toLocalDateTime().toLocalTime(), binding.getField()) .format(TimeUtil.TIME_FORMATTER_WITH_OPTIONAL_MICROS)); sb.append("'"); @@ -157,23 +157,23 @@ public void encodeAsBinary(Message msg, BindValue binding) { case TEXT: case MEDIUMTEXT: case LONGTEXT: - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (binding.getCalendar() != null) { - buf.append(TimeUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); + sb.append(TimeUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); } else { this.tsdf = TimeUtil.getSimpleDateFormat(this.tsdf, "yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()); - buf.append(this.tsdf.format(x)); + sb.append(this.tsdf.format(x)); } if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - intoPacket.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes(buf.toString(), this.charEncoding.getValue())); + intoPacket.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes(sb.toString(), this.charEncoding.getValue())); return; default: throw ExceptionFactory.createException(WrongArgumentException.class, diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilCalendarValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilCalendarValueEncoder.java index cef61bbb5..364ec7165 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilCalendarValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilCalendarValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -65,21 +65,21 @@ public String getString(BindValue binding) { case TIMESTAMP: Timestamp ts = adjustTimestamp(new java.sql.Timestamp(((Calendar) binding.getValue()).getTimeInMillis()), binding.getField(), binding.keepOrigNanos()); - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (binding.getCalendar() != null) { - buf.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); + sb.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); } else { - buf.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", + sb.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()) .format(ts)); } if (this.serverSession.getCapabilities().serverSupportsFracSecs() && ts.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(ts.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(ts.getNanos(), 6)); } - buf.append('\''); - return buf.toString(); + sb.append('\''); + return sb.toString(); case DATETIME: case CHAR: case VARCHAR: @@ -90,7 +90,7 @@ public String getString(BindValue binding) { ZonedDateTime zdt = ZonedDateTime.ofInstant(x.toInstant(), x.getTimeZone().toZoneId()) .withZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()); - StringBuilder sb = new StringBuilder("'"); + sb = new StringBuilder("'"); sb.append(zdt.format(zdt.getNano() > 0 && this.serverSession.getCapabilities().serverSupportsFracSecs() && this.sendFractionalSeconds.getValue() ? TimeUtil.DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET : TimeUtil.DATETIME_FORMATTER_NO_FRACT_NO_OFFSET)); diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilDateValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilDateValueEncoder.java index c6f0e808c..9104af667 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilDateValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/UtilDateValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -77,30 +77,30 @@ public String getString(BindValue binding) { case TEXT: case MEDIUMTEXT: case LONGTEXT: - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (binding.getCalendar() != null) { - buf.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); + sb.append(TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); } else { this.tsdf = TimeUtil.getSimpleDateFormat(this.tsdf, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()); - buf.append(this.tsdf.format(x)); + sb.append(this.tsdf.format(x)); } if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - buf.append('\''); + sb.append('\''); - return buf.toString(); + return sb.toString(); case YEAR: Calendar cal = Calendar.getInstance(); cal.setTime((java.util.Date) binding.getValue()); return String.valueOf(cal.get(Calendar.YEAR)); case TIME: - StringBuilder sb = new StringBuilder("'"); + sb = new StringBuilder("'"); sb.append(adjustLocalTime(new Timestamp(((java.util.Date) binding.getValue()).getTime()).toLocalDateTime().toLocalTime(), binding.getField()) .format(TimeUtil.TIME_FORMATTER_WITH_OPTIONAL_MICROS)); sb.append("'"); @@ -161,23 +161,23 @@ public void encodeAsBinary(Message msg, BindValue binding) { case TEXT: case MEDIUMTEXT: case LONGTEXT: - StringBuffer buf = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (binding.getCalendar() != null) { - buf.append(TimeUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); + sb.append(TimeUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)); } else { this.tsdf = TimeUtil.getSimpleDateFormat(this.tsdf, "yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()); - buf.append(this.tsdf.format(x)); + sb.append(this.tsdf.format(x)); } if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - intoPacket.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes(buf.toString(), this.charEncoding.getValue())); + intoPacket.writeBytes(StringSelfDataType.STRING_LENENC, StringUtils.getBytes(sb.toString(), this.charEncoding.getValue())); break; default: diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/ZonedDateTimeValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/ZonedDateTimeValueEncoder.java index 20c7f54bf..2d8fdf72e 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/ZonedDateTimeValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/ZonedDateTimeValueEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. * * 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 @@ -75,20 +75,20 @@ public String getString(BindValue binding) { ((ZonedDateTime) binding.getValue()).withZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()).toLocalDateTime()), binding.getField(), binding.keepOrigNanos()); - StringBuffer buf = new StringBuffer(); + sb = new StringBuilder(); - buf.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", + sb.append(TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", binding.getMysqlType() == MysqlType.TIMESTAMP && this.preserveInstants.getValue() ? this.serverSession.getSessionTimeZone() : this.serverSession.getDefaultTimeZone()) .format(x)); if (this.serverSession.getCapabilities().serverSupportsFracSecs() && x.getNanos() > 0) { - buf.append('.'); - buf.append(TimeUtil.formatNanos(x.getNanos(), 6)); + sb.append('.'); + sb.append(TimeUtil.formatNanos(x.getNanos(), 6)); } - buf.append('\''); + sb.append('\''); - return buf.toString(); + return sb.toString(); case YEAR: return String.valueOf(((ZonedDateTime) binding.getValue()).withZoneSameInstant(this.serverSession.getDefaultTimeZone().toZoneId()).getYear());