Bug #107222 ClientPreparedStatement.toString() no longer interpolates byte arrays
Submitted: 5 May 2022 14:34 Modified: 27 Sep 2022 21:58
Reporter: Shaun Brockhoff Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.29 OS:Any
Assigned to: CPU Architecture:Any

[5 May 2022 14:34] Shaun Brockhoff
Description:
Prior to Connector/J 8.0.29, our app would use ClientPreparedStatement.asSql() to log the full query string for local debugging. For example:

private void debugLog(PreparedStatement pstmt) {
  ClientPreparedStatement clientPstmt = pstmt.unwrap(ClientPreparedStatement.class);
  LOGGER.debug("Query: {}", clientPstmt.asSql());
}

8.0.29 removes ClientPreparedStatement.asSql(), and using ClientPreparedStatement.toString() mostly works as a replacement, except that byte arrays are no longer interpolated. We use binary columns heavily for uuids, so a query that previously printed as:

...where `report`.`uuid` = x'3043FC54205E4BF5ABAE543F9AA8850F00000000'

now prints as:

...where `report`.`uuid` = ** BYTE ARRAY DATA **

How to repeat:
Use ClientPreparedStatement.toString() for a query against a binary column, e.g. binary(16) column for uuids.
[9 May 2022 10:15] Filipe Silva
Thank you for your interest in MySQL Connector/J and for this bug report.

It was verified as described.
[27 Jul 2022 2:48] ChangXu Si
The null value in 8.0.28 will be displayed "null" but in 8.0.29 whil be displayed ** BYTE ARRAY DATA **
In version 8.0.30, this bug still exists.
[27 Sep 2022 21:58] Daniel So
Posted by developer:
 
Added the following entry to the C/N 8.0.31 changelog: 

" Before release 8.0.29, Connector/J always interpolated byte arrays as hexadecimal literals when obtaining a prepared statement's string representation by the toString() method. Since 8.0.29, all byte array values were displayed as byte array data when converted to strings. The same is also true for null values, which were also displayed as byte values instead of NULL.

To allow different ways to display byte array data and null values, a new connection property, maxByteArrayAsHex, has been introduced: byte arrays shorter than the value of maxByteArrayAsHex are now shown as hexadecimal literals like before release 8.0.29. Any byte arrays longer than this value are interpolated generically as byte array data."
[6 Oct 2022 22:21] Daniel So
Posted by developer:
 
Updated the changelog entry to the following: 

"Before release 8.0.29, Connector/J always interpolated byte arrays as hexadecimal literals when obtaining a prepared statement's string representation by the toString() method. Since 8.0.29, all byte array values were displayed as ** BYTE ARRAY DATA ** when converted to strings. The same is also true for null values.

To allow different ways to display byte array data and null values, a new connection property, maxByteArrayAsHex, has been introduced: byte arrays shorter than the value of maxByteArrayAsHex are now shown as hexadecimal literals like before release 8.0.29. Any byte arrays longer than this value are interpolated generically as ** BYTE ARRAY DATA **."