From 8ae13a6eb4d5835483e8f6629e8392e707d03846 Mon Sep 17 00:00:00 2001 From: scndry Date: Thu, 8 Sep 2022 00:05:46 +0900 Subject: [PATCH] fix. bug#108414 Malformed Packet --- .../com/mysql/cj/NativeQueryBindValue.java | 2 +- .../java/testsuite/simple/BooleanTest.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/test/java/testsuite/simple/BooleanTest.java diff --git a/src/main/core-impl/java/com/mysql/cj/NativeQueryBindValue.java b/src/main/core-impl/java/com/mysql/cj/NativeQueryBindValue.java index badc0bf07..07e685fcb 100644 --- a/src/main/core-impl/java/com/mysql/cj/NativeQueryBindValue.java +++ b/src/main/core-impl/java/com/mysql/cj/NativeQueryBindValue.java @@ -284,6 +284,7 @@ public int getFieldType() { case BIGINT: case BIGINT_UNSIGNED: return MysqlType.FIELD_TYPE_LONGLONG; + case BIT: case BOOLEAN: case TINYINT: case TINYINT_UNSIGNED: @@ -325,7 +326,6 @@ public int getFieldType() { case LONGBLOB: case LONGTEXT: return MysqlType.FIELD_TYPE_LONG_BLOB; - // case BIT: // case JSON: // case ENUM: // case SET: diff --git a/src/test/java/testsuite/simple/BooleanTest.java b/src/test/java/testsuite/simple/BooleanTest.java new file mode 100644 index 000000000..483688dd3 --- /dev/null +++ b/src/test/java/testsuite/simple/BooleanTest.java @@ -0,0 +1,49 @@ +package testsuite.simple; + +import com.mysql.cj.MysqlType; +import com.mysql.cj.conf.PropertyDefinitions; +import com.mysql.cj.conf.PropertyKey; +import org.junit.jupiter.api.Test; +import testsuite.BaseTestCase; + +import java.sql.SQLException; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BooleanTest extends BaseTestCase { + + @Test + public void testServerPrepStmtsParams() throws SQLException { + Properties props = new Properties(); + props.setProperty(PropertyKey.sslMode.getKeyName(), PropertyDefinitions.SslMode.DISABLED.name()); + props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true"); + props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "true"); + + this.conn = getConnectionWithProps(props); + this.pstmt = this.conn.prepareStatement("SELECT ?, ?, ?, ?, ?"); + + executeStatement(true); + executeStatement(false); + } + + private void executeStatement(boolean value) throws SQLException { + this.pstmt.setBoolean(1, value); + this.pstmt.setObject(2, value); + this.pstmt.setObject(3, value, MysqlType.BOOLEAN); + this.pstmt.setObject(4, value, MysqlType.TINYINT); + this.pstmt.setObject(5, value, MysqlType.BIT); + + this.rs = this.pstmt.executeQuery(); + assertTrue(this.rs.next()); + + assertEquals(value, this.rs.getBoolean(1)); + assertEquals(value, this.rs.getBoolean(2)); + assertEquals(value, this.rs.getBoolean(3)); + assertEquals(value, this.rs.getBoolean(4)); + assertEquals(value, this.rs.getBoolean(5)); + + this.rs.close(); + } +}