Skip to content

Commit e558e11

Browse files
author
Axyoan Marcelo
committed
Fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect.
Change-Id: Ie909ef6b2557b1525a6671ca7c1bd749f3250920
1 parent b226e34 commit e558e11

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
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.4.0
55

6+
- Fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect.
7+
68
- Fix for Bug#22931632, GETPARAMETERBINDINGS() ON A PS RETURNS NPE WHEN NOT ALL PARAMETERS ARE BOUND.
79

810
- WL#16147, Remove support for FIDO authentication.

src/main/user-impl/java/com/mysql/cj/jdbc/result/ResultSetFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -43,7 +43,6 @@
4343
import com.mysql.cj.protocol.ResultsetRows;
4444
import com.mysql.cj.protocol.a.NativePacketPayload;
4545
import com.mysql.cj.protocol.a.result.OkPacket;
46-
import com.mysql.cj.protocol.a.result.ResultsetRowsCursor;
4746

4847
public class ResultSetFactory implements ProtocolEntityFactory<ResultSetImpl, NativePacketPayload> {
4948

@@ -138,9 +137,10 @@ public ResultSetImpl createFromResultsetRows(int resultSetConcurrency, int resul
138137
rs.setResultSetType(resultSetType);
139138
rs.setResultSetConcurrency(resultSetConcurrency);
140139

141-
if (rows instanceof ResultsetRowsCursor && st != null) {
140+
if (st != null) {
142141
rs.setFetchSize(st.getFetchSize());
143142
}
143+
144144
return rs;
145145
}
146146

src/main/user-impl/java/com/mysql/cj/jdbc/result/ResultSetImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ public void setFetchDirection(int direction) throws SQLException {
19841984
@Override
19851985
public void setFetchSize(int rows) throws SQLException {
19861986
synchronized (checkClosed().getConnectionMutex()) {
1987-
if (rows < 0) { /* || rows > getMaxRows() */
1987+
if (rows < 0 && rows != Integer.MIN_VALUE) { /* || rows > getMaxRows() */
19881988
throw SQLError.createSQLException(Messages.getString("ResultSet.Value_must_be_between_0_and_getMaxRows()_66"),
19891989
MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
19901990
}

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2002, 2024, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -8200,4 +8200,51 @@ void testBug107215() throws Exception {
82008200
}
82018201
}
82028202

8203+
/**
8204+
* Tests fix for Bug#113129 (Bug#36043145), setting the FetchSize on a Statement object does not affect.
8205+
*
8206+
* @throws Exception
8207+
*/
8208+
@Test
8209+
void testBug113129() throws Exception {
8210+
Statement testStmt = this.conn.createStatement();
8211+
int fetchSizeToTest1 = 5;
8212+
int fetchSizeToTest2 = 10;
8213+
8214+
// executeQuery returns a different ResultSet when executing a ping query, need to test it too.
8215+
testStmt.setFetchSize(fetchSizeToTest1);
8216+
this.rs = testStmt.executeQuery("/* ping */");
8217+
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
8218+
this.rs.setFetchSize(fetchSizeToTest2);
8219+
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
8220+
8221+
// Static rows.
8222+
testStmt.setFetchSize(fetchSizeToTest1);
8223+
this.rs = testStmt.executeQuery("SELECT 1");
8224+
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
8225+
this.rs.setFetchSize(fetchSizeToTest2);
8226+
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
8227+
this.rs.next();
8228+
8229+
// Dynamic fetch.
8230+
testStmt.setFetchSize(Integer.MIN_VALUE);
8231+
this.rs = testStmt.executeQuery("SELECT 1");
8232+
this.rs.next();
8233+
assertEquals(Integer.MIN_VALUE, this.rs.getFetchSize());
8234+
this.rs.setFetchSize(fetchSizeToTest2);
8235+
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
8236+
8237+
// Cursor based.
8238+
Properties props = new Properties();
8239+
props.setProperty(PropertyKey.useCursorFetch.getKeyName(), "True");
8240+
Connection cursorConn = getConnectionWithProps(props);
8241+
testStmt = cursorConn.createStatement();
8242+
testStmt.setFetchSize(fetchSizeToTest1);
8243+
this.rs = testStmt.executeQuery("SELECT 1");
8244+
assertEquals(fetchSizeToTest1, this.rs.getFetchSize());
8245+
this.rs.setFetchSize(fetchSizeToTest2);
8246+
assertEquals(fetchSizeToTest2, this.rs.getFetchSize());
8247+
this.rs.next();
8248+
}
8249+
82038250
}

0 commit comments

Comments
 (0)