Modified:
branches/branch_5_1/CHANGES
branches/branch_5_1/src/com/mysql/jdbc/StatementImpl.java
branches/branch_5_1/src/testsuite/regression/StatementRegressionTest.java
Log:
Fixed BUG#30508 - ResultSet returned by Statement.getGeneratedKeys() is not closed automatically when statement that created it is closed.
Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES 2007-12-04 16:44:56 UTC (rev 6691)
+++ branches/branch_5_1/CHANGES 2007-12-05 19:06:40 UTC (rev 6692)
@@ -69,6 +69,9 @@
"extension" interface), and tell the driver to use it by passing in the
class name via the "loadBalanceStrategy" configuration property.
+ - Fixed BUG#30508 - ResultSet returned by Statement.getGeneratedKeys() is not closed
+ automatically when statement that created it is closed.
+
10-09-07 - Version 5.1.5
- Released instead of 5.1.4 to pickup patch for BUG#31053
Modified: branches/branch_5_1/src/com/mysql/jdbc/StatementImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/StatementImpl.java 2007-12-04 16:44:56 UTC (rev 6691)
+++ branches/branch_5_1/src/com/mysql/jdbc/StatementImpl.java 2007-12-05 19:06:40 UTC (rev 6692)
@@ -483,7 +483,7 @@
* @exception SQLException
* if a database access error occurs
*/
- public void close() throws SQLException {
+ public synchronized void close() throws SQLException {
realClose(true, true);
}
@@ -1823,8 +1823,12 @@
}
}
- return com.mysql.jdbc.ResultSetImpl.getInstance(this.currentCatalog, fields,
+ com.mysql.jdbc.ResultSetImpl gkRs = com.mysql.jdbc.ResultSetImpl.getInstance(this.currentCatalog, fields,
new RowDataStatic(rowSet), this.connection, this, false);
+
+ this.openResults.add(gkRs);
+
+ return gkRs;
}
/**
@@ -2220,21 +2224,21 @@
}
}
- if (this.results != null) {
- if (closeOpenResults) {
- closeOpenResults = !this.holdResultsOpenOverClose;
- }
-
- if (closeOpenResults && this.connection != null
- && !this.connection.getHoldResultsOpenOverStatementClose()) {
+ if (closeOpenResults) {
+ closeOpenResults = !this.holdResultsOpenOverClose;
+ }
+
+ if (closeOpenResults) {
+ if (this.results != null) {
+
try {
this.results.close();
} catch (Exception ex) {
;
}
-
- this.closeAllOpenResults();
}
+
+ closeAllOpenResults();
}
if (this.connection != null) {
Modified: branches/branch_5_1/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- branches/branch_5_1/src/testsuite/regression/StatementRegressionTest.java 2007-12-04 16:44:56 UTC (rev 6691)
+++ branches/branch_5_1/src/testsuite/regression/StatementRegressionTest.java 2007-12-05 19:06:40 UTC (rev 6692)
@@ -4352,4 +4352,54 @@
}
}
}
+
+ /**
+ * Tests fix for BUG#30508 - ResultSet returned by Statement.getGeneratedKeys()
+ * is not closed automatically when statement that created it is closed.
+ *
+ * @throws Exception
+ */
+ public void testBug30508() throws Exception {
+
+ try {
+ Statement ggkStatement = this.conn.createStatement();
+ this.rs = ggkStatement.getGeneratedKeys();
+ ggkStatement.close();
+
+ this.rs.next();
+ fail("Should've had an exception here");
+ } catch (SQLException sqlEx) {
+ assertEquals("S1000", sqlEx.getSQLState());
+ } finally {
+ closeMemberJDBCResources();
+ }
+
+ try {
+ this.pstmt = this.conn.prepareStatement("SELECT 1");
+ this.rs = this.pstmt.getGeneratedKeys();
+ this.pstmt.close();
+ this.rs.next();
+ fail("Should've had an exception here");
+ } catch (SQLException sqlEx) {
+ assertEquals("S1000", sqlEx.getSQLState());
+ } finally {
+ closeMemberJDBCResources();
+ }
+
+ if (versionMeetsMinimum(5, 0)) {
+ createProcedure("testBug30508", "() BEGIN SELECT 1; END");
+
+ try {
+ this.pstmt = this.conn.prepareCall("{CALL testBug30508()}");
+ this.rs = this.pstmt.getGeneratedKeys();
+ this.pstmt.close();
+ this.rs.next();
+ fail("Should've had an exception here");
+ } catch (SQLException sqlEx) {
+ assertEquals("S1000", sqlEx.getSQLState());
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r6692 - in branches/branch_5_1: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 5 Dec |