Skip to content

Commit

Permalink
Fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Stateme…
Browse files Browse the repository at this point in the history
…nt object does not affect.

Change-Id: Ie909ef6b2557b1525a6671ca7c1bd749f3250920
  • Loading branch information
Axyoan Marcelo committed Jan 31, 2024
1 parent b226e34 commit e558e11
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.4.0

- Fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect.

- Fix for Bug#22931632, GETPARAMETERBINDINGS() ON A PS RETURNS NPE WHEN NOT ALL PARAMETERS ARE BOUND.

- WL#16147, Remove support for FIDO authentication.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -43,7 +43,6 @@
import com.mysql.cj.protocol.ResultsetRows;
import com.mysql.cj.protocol.a.NativePacketPayload;
import com.mysql.cj.protocol.a.result.OkPacket;
import com.mysql.cj.protocol.a.result.ResultsetRowsCursor;

public class ResultSetFactory implements ProtocolEntityFactory<ResultSetImpl, NativePacketPayload> {

Expand Down Expand Up @@ -138,9 +137,10 @@ public ResultSetImpl createFromResultsetRows(int resultSetConcurrency, int resul
rs.setResultSetType(resultSetType);
rs.setResultSetConcurrency(resultSetConcurrency);

if (rows instanceof ResultsetRowsCursor && st != null) {
if (st != null) {
rs.setFetchSize(st.getFetchSize());
}

return rs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ public void setFetchDirection(int direction) throws SQLException {
@Override
public void setFetchSize(int rows) throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (rows < 0) { /* || rows > getMaxRows() */
if (rows < 0 && rows != Integer.MIN_VALUE) { /* || rows > getMaxRows() */
throw SQLError.createSQLException(Messages.getString("ResultSet.Value_must_be_between_0_and_getMaxRows()_66"),
MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
Expand Down
49 changes: 48 additions & 1 deletion src/test/java/testsuite/regression/ResultSetRegressionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates.
* Copyright (c) 2002, 2024, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -8200,4 +8200,51 @@ void testBug107215() throws Exception {
}
}

/**
* Tests fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect.
*
* @throws Exception
*/
@Test
void testBug113129() throws Exception {
Statement testStmt = this.conn.createStatement();
int fetchSizeToTest1 = 5;
int fetchSizeToTest2 = 10;

// executeQuery returns a different ResultSet when executing a ping query, need to test it too.
testStmt.setFetchSize(fetchSizeToTest1);
this.rs = testStmt.executeQuery("/* ping */");
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
this.rs.setFetchSize(fetchSizeToTest2);
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());

// Static rows.
testStmt.setFetchSize(fetchSizeToTest1);
this.rs = testStmt.executeQuery("SELECT 1");
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
this.rs.setFetchSize(fetchSizeToTest2);
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
this.rs.next();

// Dynamic fetch.
testStmt.setFetchSize(Integer.MIN_VALUE);
this.rs = testStmt.executeQuery("SELECT 1");
this.rs.next();
assertEquals(Integer.MIN_VALUE, this.rs.getFetchSize());
this.rs.setFetchSize(fetchSizeToTest2);
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());

// Cursor based.
Properties props = new Properties();
props.setProperty(PropertyKey.useCursorFetch.getKeyName(), "True");
Connection cursorConn = getConnectionWithProps(props);
testStmt = cursorConn.createStatement();
testStmt.setFetchSize(fetchSizeToTest1);
this.rs = testStmt.executeQuery("SELECT 1");
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
this.rs.setFetchSize(fetchSizeToTest2);
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
this.rs.next();
}

}

0 comments on commit e558e11

Please sign in to comment.