Skip to content

Commit 5f142a6

Browse files
committed
Fix for Bug#33185116, Have method ResultSet.getBoolean() supporting
conversion of 'T' and 'F' in a VARCHAR to True/False (boolean).
1 parent 11d4f9f commit 5f142a6

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
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.27
55

6+
- Fix for Bug#33185116, Have method ResultSet.getBoolean() supporting conversion of 'T' and 'F' in a VARCHAR to True/False (boolean).
7+
68
- Fix for Bug#31117686, PROTOCOL ALLOWLIST NOT COMPATIBLE WITH IBM JAVA.
79

810
- Fix for Bug#104559 (33232419), ResultSet.getObject(i, java.util.Date.class) throws NPE when the value is null.

src/main/core-impl/java/com/mysql/cj/result/BooleanValueFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public Boolean createFromBytes(byte[] bytes, int offset, int length, Field f) {
9797
String s = StringUtils.toString(bytes, offset, length, f.getEncoding());
9898
byte[] newBytes = s.getBytes();
9999

100-
if (s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("true")) {
100+
if (s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("T") || s.equalsIgnoreCase("true")) {
101101
return createFromLong(1);
102-
} else if (s.equalsIgnoreCase("N") || s.equalsIgnoreCase("false")) {
102+
} else if (s.equalsIgnoreCase("N") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("F") || s.equalsIgnoreCase("false")) {
103103
return createFromLong(0);
104104
} else if (s.contains("e") || s.contains("E") || s.matches("-?\\d*\\.\\d*")) {
105105
// floating point

src/test/java/testsuite/regression/ResultSetRegressionTest.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,29 +6822,6 @@ public Void call() throws Exception {
68226822
} while ((sendFractionalSeconds = !sendFractionalSeconds) || (useServerPrepStmts = !useServerPrepStmts));
68236823
}
68246824

6825-
/**
6826-
* Tests for fix to BUG#92574 (28706219), WHEN CONVERTING FROM VARCHAR TO JAVA BOOLEAN, 'N' IS NOT SUPPORTED.
6827-
*
6828-
* @throws Exception
6829-
*/
6830-
@Test
6831-
public void testBug92574() throws Exception {
6832-
String[] strValues = new String[] { null, "N", "n", "Y", "y", "0", "1" };
6833-
boolean[] boolValues = new boolean[] { false, false, false, true, true, false, true };
6834-
6835-
createTable("testBug92574", "(id int not null, f varchar(1), key(id))");
6836-
for (int i = 0; i < strValues.length; i++) {
6837-
String val = strValues[i] == null ? null : "'" + strValues[i] + "'";
6838-
this.stmt.executeUpdate("insert into testBug92574 values(" + i + "," + val + ")");
6839-
}
6840-
this.rs = this.stmt.executeQuery("SELECT * from testBug92574");
6841-
while (this.rs.next()) {
6842-
int i = this.rs.getInt(1);
6843-
assertEquals(strValues[i], this.rs.getString(2));
6844-
assertEquals(boolValues[i], this.rs.getBoolean(2));
6845-
}
6846-
}
6847-
68486825
/**
68496826
* Tests fix for Bug#91065 (28101003), ZERODATETIMEBEHAVIOR=CONVERT_TO_NULL SHOULD NOT APPLY TO 00:00:00 TIME COLUMNS.
68506827
*
@@ -8054,4 +8031,30 @@ public void testBug32954396() throws Exception {
80548031
testConn.close();
80558032
} while ((useCursorFetch = !useCursorFetch) || (setFetchSize = !setFetchSize));
80568033
}
8034+
8035+
/**
8036+
* Test fix for Bug#33185116, Have method ResultSet.getBoolean() supporting conversion of 'T' and 'F' in a VARCHAR to True/False (boolean).
8037+
* Extended the test for BUG#92574 (28706219), WHEN CONVERTING FROM VARCHAR TO JAVA BOOLEAN, 'N' IS NOT SUPPORTED.
8038+
*
8039+
* @throws Exception
8040+
*/
8041+
@Test
8042+
public void testBug33185116() throws Exception {
8043+
String[] strValues = new String[] { null, "N", "n", "Y", "y", "0", "1", "T", "t", "F", "f", "yes", "Yes", "no", "No", "true", "TrUe", "false",
8044+
"FalsE" };
8045+
boolean[] boolValues = new boolean[] { false, false, false, true, true, false, true, true, true, false, false, true, true, false, false, true, true,
8046+
false, false };
8047+
8048+
createTable("testBug33185116", "(id int not null, f varchar(5), key(id))");
8049+
for (int i = 0; i < strValues.length; i++) {
8050+
String val = strValues[i] == null ? null : "'" + strValues[i] + "'";
8051+
this.stmt.executeUpdate("insert into testBug33185116 values(" + i + "," + val + ")");
8052+
}
8053+
this.rs = this.stmt.executeQuery("SELECT * from testBug33185116");
8054+
while (this.rs.next()) {
8055+
int i = this.rs.getInt(1);
8056+
assertEquals(strValues[i], this.rs.getString(2));
8057+
assertEquals(boolValues[i], this.rs.getBoolean(2));
8058+
}
8059+
}
80578060
}

0 commit comments

Comments
 (0)