From cea06d511e6de39a7f9b2aa60b26262e8a15cd4c Mon Sep 17 00:00:00 2001 From: "Z.H" <29370032+onlyacat@users.noreply.github.com> Date: Thu, 17 Feb 2022 17:33:19 +0800 Subject: [PATCH] add a test `testEOFPacketForPrepareStmt` to help locate the bug#106252 --- .../java/testsuite/simple/StatementsTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/java/testsuite/simple/StatementsTest.java b/src/test/java/testsuite/simple/StatementsTest.java index 04aa54846..311b06ff5 100644 --- a/src/test/java/testsuite/simple/StatementsTest.java +++ b/src/test/java/testsuite/simple/StatementsTest.java @@ -1858,6 +1858,44 @@ public void testParameterBindings() throws Exception { } } + @Test + public void testEOFPacketForPrepareStmt() throws Exception { + Properties props = new Properties(); + props.setProperty("useServerPrepStmts", "true"); + + Connection testConn = getConnectionWithProps(props); + + Session session = ((JdbcConnection) (testConn)).getSession(); + + boolean checkEOF = !session.getServerSession().isEOFDeprecated(); + + try { + ServerPreparedQuery query = ServerPreparedQuery.getInstance((NativeSession) session); + + // two placeholders (?) and one column (col1) + query.serverPrepare("SELECT CONCAT(?, ?) as col1;"); + + if (checkEOF) { + // check the Parameter Definition Block and make sure both of the fields are not null + assertEquals(query.getParameterFields().length, 2); + assertNotNull(query.getParameterFields()[0]); + assertNotNull(query.getParameterFields()[1]); + + // check the Column Definition Block and make sure the field is not null + assertEquals(query.getResultFields().getFields().length, 1); + assertNotNull(query.getResultFields().getFields()[0]); + + // Should be 6 packets in total: + // one description packet + // Parameter Definition Block: two Parameter definition packets and one EOF packet + // Column Definition Block: one Column definition packets and one EOF packet + assertEquals(query.session.getProtocol().getPacketReader().getMessageSequence(), 6); + } + } finally { + testConn.close(); + } + } + @Test public void testLocalInfileHooked() throws Exception { this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'local_infile'");