Modified:
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/CursorRowProvider.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
trunk/connector-j/CHANGES
trunk/connector-j/src/com/mysql/jdbc/CursorRowProvider.java
trunk/connector-j/src/com/mysql/jdbc/Statement.java
trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
Log:
- Fixed BUG#25517 - Statement.setMaxRows() is not effective on result
sets materialized from cursors.
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2007-03-22 19:42:07 UTC (rev 6363)
+++ branches/branch_5_0/connector-j/CHANGES 2007-03-22 20:58:41 UTC (rev 6364)
@@ -35,7 +35,10 @@
- Fixed BUG#27317 - ResultSet.get*() with a column index < 1 returns
misleading error message.
-
+
+ - Fixed BUG#25517 - Statement.setMaxRows() is not effective on result
+ sets materialized from cursors.
+
03-01-07 - Version 5.0.5
- Fixed BUG#23645 - Some collations/character sets reported as "unknown"
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/CursorRowProvider.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/CursorRowProvider.java 2007-03-22
19:42:07 UTC (rev 6363)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/CursorRowProvider.java 2007-03-22
20:58:41 UTC (rev 6364)
@@ -291,6 +291,14 @@
return false;
}
+ if (this.owner != null && this.owner.owningStatement != null) {
+ int maxRows = this.owner.owningStatement.maxRows;
+
+ if (maxRows != -1 && this.currentPositionInEntireResult + 1 > maxRows) {
+ return false;
+ }
+ }
+
if (this.currentPositionInEntireResult != BEFORE_START_OF_ROWS) {
// Case, we've fetched some rows, but are not at end of fetched
// block
@@ -339,6 +347,7 @@
this.currentPositionInEntireResult++;
this.currentPositionInFetchedRows++;
+
// Catch the forced scroll-passed-end
if (this.fetchedRows != null && this.fetchedRows.size() == 0) {
return null;
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-22 19:42:07
UTC (rev 6363)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-22 20:58:41
UTC (rev 6364)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2007 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -509,7 +509,11 @@
sql, this.resultSetType, this.resultSetConcurrency);
pStmt.setFetchSize(this.fetchSize);
-
+
+ if (this.maxRows > -1) {
+ pStmt.setMaxRows(this.maxRows);
+ }
+
pStmt.execute();
//
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-22
19:42:07 UTC (rev 6363)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-22
20:58:41 UTC (rev 6364)
@@ -3804,6 +3804,106 @@
}
/**
+ * Tests fix for BUG#25517 - Statement.setMaxRows() is not effective
+ * on result sets materialized from cursors.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug25517() throws Exception {
+ Connection fetchConn = null;
+ Statement fetchStmt = null;
+
+ createTable("testBug25517", "(field1 int)");
+
+ StringBuffer insertBuf = new StringBuffer("INSERT INTO testBug25517 VALUES (1)");
+
+ for (int i = 0; i < 100; i++) {
+ insertBuf.append(",(" + i + ")");
+ }
+
+ this.stmt.executeUpdate(insertBuf.toString());
+
+ try {
+ Properties props = new Properties();
+ props.setProperty("useServerPrepStmts", "true");
+ props.setProperty("useCursorFetch", "true");
+
+ fetchConn = getConnectionWithProps(props);
+ fetchStmt = fetchConn.createStatement();
+
+ //int[] maxRows = new int[] {1, 4, 5, 11, 12, 13, 16, 50, 51, 52, 100};
+ int[] fetchSizes = new int[] {1, 4, 10, 25, 100};
+ List maxRows = new ArrayList();
+ maxRows.add(new Integer(1));
+
+ for (int i = 0; i < fetchSizes.length; i++) {
+ if (fetchSizes[i] != 1) {
+ maxRows.add(new Integer(fetchSizes[i] - 1));
+ }
+
+ maxRows.add(new Integer(fetchSizes[i]));
+
+ if (i != fetchSizes.length - 1) {
+ maxRows.add(new Integer(fetchSizes[i] + 1));
+ }
+ }
+
+ for (int fetchIndex = 0; fetchIndex < fetchSizes.length; fetchIndex++) {
+ fetchStmt.setFetchSize(fetchSizes[fetchIndex]);
+
+ for (int maxRowIndex = 0; maxRowIndex < maxRows.size(); maxRowIndex++) {
+
+ int maxRowsToExpect = ((Integer)maxRows.get(maxRowIndex)).intValue();
+ fetchStmt.setMaxRows(maxRowsToExpect);
+
+ int rowCount = 0;
+
+ this.rs = fetchStmt.executeQuery("SELECT * FROM testBug25517");
+
+ while (this.rs.next()) {
+ rowCount++;
+ }
+
+ assertEquals(maxRowsToExpect, rowCount);
+ }
+ }
+
+ this.pstmt = fetchConn.prepareStatement("SELECT * FROM testBug25517");
+
+ for (int fetchIndex = 0; fetchIndex < fetchSizes.length; fetchIndex++) {
+ this.pstmt.setFetchSize(fetchSizes[fetchIndex]);
+
+ for (int maxRowIndex = 0; maxRowIndex < maxRows.size(); maxRowIndex++) {
+
+ int maxRowsToExpect = ((Integer)maxRows.get(maxRowIndex)).intValue();
+ this.pstmt.setMaxRows(maxRowsToExpect);
+
+ int rowCount = 0;
+
+ this.rs = this.pstmt.executeQuery();
+
+ while (this.rs.next()) {
+ rowCount++;
+ }
+
+ assertEquals(maxRowsToExpect, rowCount);
+ }
+ }
+
+ } finally {
+ closeMemberJDBCResources();
+
+ if (fetchStmt != null) {
+ fetchStmt.close();
+ }
+
+ if (fetchConn != null) {
+ fetchConn.close();
+ }
+ }
+ }
+
+ /**
* Tests fix for BUG#25787 - java.util.Date should be serialized for
PreparedStatement.setObject().
*
* We add a new configuration option "treatUtilDateAsTimestamp", which is false by
default,
Modified: trunk/connector-j/CHANGES
===================================================================
--- trunk/connector-j/CHANGES 2007-03-22 19:42:07 UTC (rev 6363)
+++ trunk/connector-j/CHANGES 2007-03-22 20:58:41 UTC (rev 6364)
@@ -60,7 +60,10 @@
- Fixed BUG#27317 - ResultSet.get*() with a column index < 1 returns
misleading error message.
-
+
+ - Fixed BUG#25517 - Statement.setMaxRows() is not effective on result
+ sets materialized from cursors.
+
03-01-07 - Version 5.0.5
- Fixed BUG#23645 - Some collations/character sets reported as "unknown"
Modified: trunk/connector-j/src/com/mysql/jdbc/CursorRowProvider.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/CursorRowProvider.java 2007-03-22 19:42:07 UTC
(rev 6363)
+++ trunk/connector-j/src/com/mysql/jdbc/CursorRowProvider.java 2007-03-22 20:58:41 UTC
(rev 6364)
@@ -291,6 +291,14 @@
return false;
}
+ if (this.owner != null && this.owner.owningStatement != null) {
+ int maxRows = this.owner.owningStatement.maxRows;
+
+ if (maxRows != -1 && this.currentPositionInEntireResult + 1 > maxRows) {
+ return false;
+ }
+ }
+
if (this.currentPositionInEntireResult != BEFORE_START_OF_ROWS) {
// Case, we've fetched some rows, but are not at end of fetched
// block
Modified: trunk/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-22 19:42:07 UTC (rev 6363)
+++ trunk/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-22 20:58:41 UTC (rev 6364)
@@ -502,6 +502,10 @@
pStmt.setFetchSize(this.fetchSize);
+ if (this.maxRows > -1) {
+ pStmt.setMaxRows(this.maxRows);
+ }
+
pStmt.execute();
//
Modified: trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
--- trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-22
19:42:07 UTC (rev 6363)
+++ trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-22
20:58:41 UTC (rev 6364)
@@ -3804,6 +3804,106 @@
}
/**
+ * Tests fix for BUG#25517 - Statement.setMaxRows() is not effective
+ * on result sets materialized from cursors.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug25517() throws Exception {
+ Connection fetchConn = null;
+ Statement fetchStmt = null;
+
+ createTable("testBug25517", "(field1 int)");
+
+ StringBuffer insertBuf = new StringBuffer("INSERT INTO testBug25517 VALUES (1)");
+
+ for (int i = 0; i < 100; i++) {
+ insertBuf.append(",(" + i + ")");
+ }
+
+ this.stmt.executeUpdate(insertBuf.toString());
+
+ try {
+ Properties props = new Properties();
+ props.setProperty("useServerPrepStmts", "true");
+ props.setProperty("useCursorFetch", "true");
+
+ fetchConn = getConnectionWithProps(props);
+ fetchStmt = fetchConn.createStatement();
+
+ //int[] maxRows = new int[] {1, 4, 5, 11, 12, 13, 16, 50, 51, 52, 100};
+ int[] fetchSizes = new int[] {1, 4, 10, 25, 100};
+ List maxRows = new ArrayList();
+ maxRows.add(new Integer(1));
+
+ for (int i = 0; i < fetchSizes.length; i++) {
+ if (fetchSizes[i] != 1) {
+ maxRows.add(new Integer(fetchSizes[i] - 1));
+ }
+
+ maxRows.add(new Integer(fetchSizes[i]));
+
+ if (i != fetchSizes.length - 1) {
+ maxRows.add(new Integer(fetchSizes[i] + 1));
+ }
+ }
+
+ for (int fetchIndex = 0; fetchIndex < fetchSizes.length; fetchIndex++) {
+ fetchStmt.setFetchSize(fetchSizes[fetchIndex]);
+
+ for (int maxRowIndex = 0; maxRowIndex < maxRows.size(); maxRowIndex++) {
+
+ int maxRowsToExpect = ((Integer)maxRows.get(maxRowIndex)).intValue();
+ fetchStmt.setMaxRows(maxRowsToExpect);
+
+ int rowCount = 0;
+
+ this.rs = fetchStmt.executeQuery("SELECT * FROM testBug25517");
+
+ while (this.rs.next()) {
+ rowCount++;
+ }
+
+ assertEquals(maxRowsToExpect, rowCount);
+ }
+ }
+
+ this.pstmt = fetchConn.prepareStatement("SELECT * FROM testBug25517");
+
+ for (int fetchIndex = 0; fetchIndex < fetchSizes.length; fetchIndex++) {
+ this.pstmt.setFetchSize(fetchSizes[fetchIndex]);
+
+ for (int maxRowIndex = 0; maxRowIndex < maxRows.size(); maxRowIndex++) {
+
+ int maxRowsToExpect = ((Integer)maxRows.get(maxRowIndex)).intValue();
+ this.pstmt.setMaxRows(maxRowsToExpect);
+
+ int rowCount = 0;
+
+ this.rs = this.pstmt.executeQuery();
+
+ while (this.rs.next()) {
+ rowCount++;
+ }
+
+ assertEquals(maxRowsToExpect, rowCount);
+ }
+ }
+
+ } finally {
+ closeMemberJDBCResources();
+
+ if (fetchStmt != null) {
+ fetchStmt.close();
+ }
+
+ if (fetchConn != null) {
+ fetchConn.close();
+ }
+ }
+ }
+
+ /**
* Tests fix for BUG#25787 - java.util.Date should be serialized for
PreparedStatement.setObject().
*
* We add a new configuration option "treatUtilDateAsTimestamp", which is false by
default,
| Thread |
|---|
| • Connector/J commit: r6364 - branches/branch_5_0/connector-j branches/branch_5_0/connector-j/src/com/mysql/jdbc branches/branch_5_0/connector-j/src/tes... | mmatthews | 22 Mar |