From bd2ec02608a9dbdf9f52be65f152813299e60da1 Mon Sep 17 00:00:00 2001 From: sychen Date: Tue, 15 Aug 2023 18:37:49 +0800 Subject: [PATCH] PreparedStatement support includeThreadNamesAsStatementComment --- .../java/com/mysql/cj/protocol/a/NativeProtocol.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java index ccb35bc89..942dbee1b 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java @@ -906,11 +906,7 @@ public void reclaimLargeReusablePacket() { */ public final T sendQueryString(Query callingQuery, String query, String characterEncoding, int maxRows, boolean streamResults, ColumnDefinition cachedMetadata, ProtocolEntityFactory resultSetFactory) throws IOException { - String statementComment = this.queryComment; - - if (this.propertySet.getBooleanProperty(PropertyKey.includeThreadNamesAsStatementComment).getValue()) { - statementComment = (statementComment != null ? statementComment + ", " : "") + "java thread: " + Thread.currentThread().getName(); - } + String statementComment = getQueryComment(); // We don't know exactly how many bytes we're going to get from the query. Since we're dealing with UTF-8, the max is 4, so pad it // (4 * query) + space for headers @@ -2017,7 +2013,11 @@ public BaseMetricsHolder getMetricsHolder() { @Override public String getQueryComment() { - return this.queryComment; + if (this.propertySet.getBooleanProperty(PropertyKey.includeThreadNamesAsStatementComment).getValue()) { + return (this.queryComment != null ? this.queryComment + ", " : "") + "java thread: " + Thread.currentThread().getName(); + } else { + return this.queryComment; + } } @Override