Skip to content

Commit 95db9fc

Browse files
committed
Fix for Bug#101389 (32089018), GETWARNINGS SHOULD CHECK WARNING COUNT
BEFORE SENDING SHOW.
1 parent 2b0d441 commit 95db9fc

File tree

6 files changed

+82
-11
lines changed

6 files changed

+82
-11
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.28
55

6+
- Fix for Bug#101389 (32089018), GETWARNINGS SHOULD CHECK WARNING COUNT BEFORE SENDING SHOW.
7+
68
- Fix for Bug#33488091, Remove all references to xdevapi.useAsyncProtocol from properties and code.
79

810
- WL#14805, Remove support for TLS 1.0 and 1.1.

src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ public void unsetStreamingData(ResultsetRows streamer) {
19351935
public void scanForAndThrowDataTruncation() {
19361936
if (this.streamingData == null && this.propertySet.getBooleanProperty(PropertyKey.jdbcCompliantTruncation).getValue() && getWarningCount() > 0) {
19371937
int warningCountOld = getWarningCount();
1938-
convertShowWarningsToSQLWarnings(getWarningCount(), true);
1938+
convertShowWarningsToSQLWarnings(true);
19391939
setWarningCount(warningCountOld);
19401940
}
19411941
}
@@ -2085,14 +2085,16 @@ private StringBuilder appendResultSetSlashGStyle(StringBuilder appendTo, Results
20852085
* If 'forTruncationOnly' is true, only looks for truncation warnings, and
20862086
* actually throws DataTruncation as an exception.
20872087
*
2088-
* @param warningCountIfKnown
2089-
* the warning count (if known), otherwise set it to 0.
20902088
* @param forTruncationOnly
20912089
* if this method should only scan for data truncation warnings
20922090
*
20932091
* @return the SQLWarning chain (or null if no warnings)
20942092
*/
2095-
public SQLWarning convertShowWarningsToSQLWarnings(int warningCountIfKnown, boolean forTruncationOnly) {
2093+
public SQLWarning convertShowWarningsToSQLWarnings(boolean forTruncationOnly) {
2094+
if (this.warningCount == 0) {
2095+
return null;
2096+
}
2097+
20962098
SQLWarning currentWarning = null;
20972099
ResultsetRows rows = null;
20982100

@@ -2106,7 +2108,7 @@ public SQLWarning convertShowWarningsToSQLWarnings(int warningCountIfKnown, bool
21062108
*/
21072109
NativePacketPayload resultPacket = sendCommand(getCommandBuilder().buildComQuery(getSharedSendPacket(), "SHOW WARNINGS"), false, 0);
21082110

2109-
Resultset warnRs = readAllResults(-1, warningCountIfKnown > 99 /* stream large warning counts */, resultPacket, false, null,
2111+
Resultset warnRs = readAllResults(-1, this.warningCount > 99 /* stream large warning counts */, resultPacket, false, null,
21102112
new ResultsetFactory(Type.FORWARD_ONLY, Concurrency.READ_ONLY));
21112113

21122114
int codeFieldIndex = warnRs.getColumnDefinition().findColumn("Code", false, 1) - 1;

src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ public java.sql.SQLWarning getWarnings() throws SQLException {
17351735
return null;
17361736
}
17371737

1738-
SQLWarning pendingWarningsFromServer = this.session.getProtocol().convertShowWarningsToSQLWarnings(0, false);
1738+
SQLWarning pendingWarningsFromServer = this.session.getProtocol().convertShowWarningsToSQLWarnings(false);
17391739

17401740
if (this.warningChain != null) {
17411741
this.warningChain.setNextWarning(pendingWarningsFromServer);

src/test/java/testsuite/regression/ConnectionRegressionTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9894,25 +9894,37 @@ public void testBug88227() throws Exception {
98949894
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
98959895
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
98969896
props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug88227QueryInterceptor.class.getName());
9897+
Bug88227QueryInterceptor.enabled = false; // some warnings are expected here when running against old server versions
98979898
java.sql.Connection testConn = getConnectionWithProps(props);
9898-
Bug88227QueryInterceptor.mayHaveWarnings = false;
9899+
Bug88227QueryInterceptor.enabled = true;
98999900
testConn.getTransactionIsolation();
99009901
testConn.isReadOnly();
99019902
testConn.close();
99029903
}
99039904

99049905
public static class Bug88227QueryInterceptor extends BaseQueryInterceptor {
9905-
public static boolean mayHaveWarnings = true;
9906+
public static boolean enabled = false;
99069907

99079908
@Override
99089909
public <T extends Resultset> T preProcess(Supplier<String> sql, Query interceptedQuery) {
9909-
assertFalse(sql.get().contains("SHOW WARNINGS"), "Unexpected [SHOW WARNINGS] was issued");
9910+
if (enabled) {
9911+
assertFalse(sql.get().contains("SHOW WARNINGS"), "Unexpected [SHOW WARNINGS] was issued");
9912+
}
99109913
return super.preProcess(sql, interceptedQuery);
99119914
}
99129915

9916+
@Override
9917+
public <M extends Message> M preProcess(M queryPacket) {
9918+
if (enabled) {
9919+
String sql = StringUtils.toString(queryPacket.getByteBuffer(), 1, (queryPacket.getPosition() - 1));
9920+
assertFalse(sql.contains("SHOW WARNINGS"), "Unexpected [SHOW WARNINGS] was issued");
9921+
}
9922+
return super.preProcess(queryPacket);
9923+
}
9924+
99139925
@Override
99149926
public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) {
9915-
if (!mayHaveWarnings) {
9927+
if (enabled) {
99169928
assertEquals(0, ((NativeSession) interceptedQuery.getSession()).getProtocol().getWarningCount(), "Warnings while executing [" + sql + "]");
99179929
}
99189930
return super.postProcess(sql, interceptedQuery, originalResultSet, serverSession);

src/test/java/testsuite/regression/StatementRegressionTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@
142142
import com.mysql.cj.jdbc.result.ResultSetInternalMethods;
143143
import com.mysql.cj.log.Log;
144144
import com.mysql.cj.protocol.ColumnDefinition;
145+
import com.mysql.cj.protocol.Message;
145146
import com.mysql.cj.protocol.Resultset;
146147
import com.mysql.cj.protocol.ResultsetRows;
147148
import com.mysql.cj.protocol.ServerSession;
148149
import com.mysql.cj.protocol.a.NativeServerSession;
149150
import com.mysql.cj.util.LRUCache;
151+
import com.mysql.cj.util.StringUtils;
150152
import com.mysql.cj.util.TimeUtil;
151153

152154
import testsuite.BaseQueryInterceptor;
@@ -11675,4 +11677,58 @@ public void testBug103612() throws Exception {
1167511677
testConn.close();
1167611678
} while ((useSPS = !useSPS) || (readOnly = !readOnly));
1167711679
}
11680+
11681+
/**
11682+
* Tests fix for Bug#101389 (32089018), GETWARNINGS SHOULD CHECK WARNING COUNT BEFORE SENDING SHOW.
11683+
*
11684+
* @throws Exception
11685+
*/
11686+
@Test
11687+
public void testBug101389() throws Exception {
11688+
Properties props = new Properties();
11689+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11690+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11691+
props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug101389QueryInterceptor.class.getName());
11692+
11693+
boolean useSPS = false;
11694+
do {
11695+
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
11696+
11697+
Bug101389QueryInterceptor.enabled = false; // some warnings are expected here when running against old server versions
11698+
java.sql.Connection testConn = getConnectionWithProps(props);
11699+
11700+
Bug101389QueryInterceptor.enabled = true;
11701+
Statement st = testConn.createStatement();
11702+
st.executeQuery("SELECT 1 FROM dual;");
11703+
st.getWarnings();
11704+
11705+
PreparedStatement ps = testConn.prepareStatement("SELECT 1 FROM dual;");
11706+
ps.execute();
11707+
ps.getWarnings();
11708+
11709+
testConn.close();
11710+
} while ((useSPS = !useSPS));
11711+
11712+
}
11713+
11714+
public static class Bug101389QueryInterceptor extends BaseQueryInterceptor {
11715+
public static boolean enabled = false;
11716+
11717+
@Override
11718+
public <T extends Resultset> T preProcess(Supplier<String> sql, Query interceptedQuery) {
11719+
if (enabled) {
11720+
assertFalse(sql.get().contains("SHOW WARNINGS"), "Unexpected [SHOW WARNINGS] was issued");
11721+
}
11722+
return super.preProcess(sql, interceptedQuery);
11723+
}
11724+
11725+
@Override
11726+
public <M extends Message> M preProcess(M queryPacket) {
11727+
if (enabled) {
11728+
String sql = StringUtils.toString(queryPacket.getByteBuffer(), 1, (queryPacket.getPosition() - 1));
11729+
assertFalse(sql.contains("SHOW WARNINGS"), "Unexpected [SHOW WARNINGS] was issued");
11730+
}
11731+
return super.preProcess(queryPacket);
11732+
}
11733+
}
1167811734
}

src/test/java/testsuite/regression/SyntaxRegressionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,6 @@ public void testHints() throws Exception {
12371237
}
12381238
}
12391239

1240-
@Test
12411240
private void testHintsSyntax(String query, boolean processesHint, boolean warningExpected) throws Exception {
12421241
this.stmt.clearWarnings();
12431242
this.rs = this.stmt.executeQuery(query);

0 commit comments

Comments
 (0)