Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-270] permit 65535 parameters to server preparedStatement
  • Loading branch information
rusher committed Apr 4, 2016
1 parent ae64162 commit 171b1ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Expand Up @@ -103,7 +103,7 @@ public void send(final OutputStream os) throws IOException {
nullBitsBuffer[i / 8] |= (1 << (i % 8));
}
}
buffer.buffer.put(nullBitsBuffer);/*Null Bit Map*/
buffer.write(nullBitsBuffer);/*Null Bit Map*/

//check if parameters type (using setXXX) have change since previous request, and resend new header type if so
boolean mustSendHeaderType = false;
Expand Down
Expand Up @@ -152,8 +152,8 @@ public PrepareResult prepare(String sql, boolean forceNew) throws QueryException
/* Prepared Statement OK */
buffer.readByte(); /* skip field count */
final int statementId = buffer.readInt();
final int numColumns = buffer.readShort();
final int numParams = buffer.readShort();
final int numColumns = buffer.readShort() & 0xffff;
final int numParams = buffer.readShort() & 0xffff;
buffer.readByte(); // reserved
this.hasWarnings = buffer.readShort() > 0;
ColumnInformation[] params = new ColumnInformation[numParams];
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Expand Up @@ -190,6 +190,7 @@ public void testCallExecuteErrorBatch() throws SQLException {
assertTrue(sqle.getMessage().contains("INSERT INTO INCORRECT_QUERY"));
}
}

@Test
public void testRewriteMultiPacket() throws SQLException {
Statement statement = sharedConnection.createStatement();
Expand Down Expand Up @@ -229,7 +230,7 @@ public void testRewriteMultiPacket() throws SQLException {

/**
* CONJ-273: permit client PrepareParameter without parameters.
* @throws Throwable
* @throws Throwable exception
*/
@Test
public void clientPrepareStatementWithoutParameter() throws Throwable {
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java
Expand Up @@ -755,4 +755,24 @@ public void testPrepareStatementCache() throws Throwable {
}
}
}

/**
* CONJ-270 : permit to have more than 32768 parameters.
* @throws SQLException exception
*/
@Test
public void testRewriteMultiPacket() throws SQLException {
createTable("PreparedStatementTest3", "id int");
String sql = "INSERT INTO PreparedStatementTest3 VALUES (?)";
for (int i = 1 ; i < 65535 ; i++) {
sql += ",(?)";
}
PreparedStatement pstmt = sharedConnection.prepareStatement(sql);
for (int i = 1; i < 65536; i++) {
pstmt.setInt(i, i);
}
pstmt.execute();
}


}

0 comments on commit 171b1ab

Please sign in to comment.