Modified:
branches/branch_3_1/connector-j/CHANGES
branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java
branches/branch_3_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java
Log:
Fixed BUG#13277 - ResultSetMetaData from
Statement.getGeneratedKeys() caused NullPointerExceptions to be
thrown whenever a method that required a connection reference
was called.
Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES 2005-09-16 00:06:41 UTC (rev 4264)
+++ branches/branch_3_1/connector-j/CHANGES 2005-09-16 20:00:17 UTC (rev 4265)
@@ -137,6 +137,11 @@
is closed before attempting to reference the list of parameter
bindings, to avoid throwing a NullPointerException.
+ - Fixed BUG#13277 - ResultSetMetaData from
+ Statement.getGeneratedKeys() caused NullPointerExceptions to be
+ thrown whenever a method that required a connection reference
+ was called.
+
06-23-05 - Version 3.1.10-stable
- Fixed connecting without a database specified raised an exception
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2005-09-16 00:06:41 UTC (rev 4264)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2005-09-16 20:00:17 UTC (rev 4265)
@@ -1488,7 +1488,8 @@
Field[] fields = new Field[1];
fields[0] = new Field("", "GENERATED_KEY", Types.BIGINT, 17); //$NON-NLS-1$ //$NON-NLS-2$
-
+ fields[0].setConnection(this.connection);
+
return new com.mysql.jdbc.ResultSet(this.currentCatalog, fields,
new RowDataStatic(this.batchedGeneratedKeys), this.connection,
this);
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java 2005-09-16 00:06:41 UTC (rev 4264)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java 2005-09-16 20:00:17 UTC (rev 4265)
@@ -1129,7 +1129,8 @@
throws SQLException {
Field[] fields = new Field[1];
fields[0] = new Field("", "GENERATED_KEY", Types.BIGINT, 17); //$NON-NLS-1$ //$NON-NLS-2$
-
+ fields[0].setConnection(this.connection);
+
ArrayList rowSet = new ArrayList();
long beginAt = getLastInsertID();
Modified: branches/branch_3_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java
===================================================================
--- branches/branch_3_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2005-09-16 00:06:41 UTC (rev 4264)
+++ branches/branch_3_1/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2005-09-16 20:00:17 UTC (rev 4265)
@@ -1250,6 +1250,79 @@
}
}
+ /**
+ * Tests fix for BUG#13277 - RSMD for generated keys
+ * has NPEs when a connection is referenced.
+ *
+ * @throws Exception
+ */
+ public void testBug13277() throws Exception {
+ createTable("testBug13277", "(field1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT, field2 VARCHAR(32))");
+
+ try {
+ this.stmt.executeUpdate("INSERT INTO testBug13277 (field2) VALUES ('abcdefg')",
+ Statement.RETURN_GENERATED_KEYS);
+
+ this.rs = this.stmt.getGeneratedKeys();
+
+ ResultSetMetaData rsmd = this.rs.getMetaData();
+ checkRsmdForBug13277(rsmd);
+ this.rs.close();
+
+ for (int i = 0; i < 5; i++) {
+ this.stmt.addBatch("INSERT INTO testBug13277 (field2) VALUES ('abcdefg')");
+ }
+
+ this.stmt.executeBatch();
+
+ this.rs = this.stmt.getGeneratedKeys();
+
+ rsmd = this.rs.getMetaData();
+ checkRsmdForBug13277(rsmd);
+ this.rs.close();
+
+ this.pstmt = this.conn.prepareStatement(
+ "INSERT INTO testBug13277 (field2) VALUES ('abcdefg')",
+ Statement.RETURN_GENERATED_KEYS);
+ this.pstmt.executeUpdate();
+
+ this.rs = this.pstmt.getGeneratedKeys();
+
+ rsmd = this.rs.getMetaData();
+ checkRsmdForBug13277(rsmd);
+ this.rs.close();
+
+ this.pstmt.addBatch();
+ this.pstmt.addBatch();
+
+ this.pstmt.executeUpdate();
+
+ this.rs = this.pstmt.getGeneratedKeys();
+
+ rsmd = this.rs.getMetaData();
+ checkRsmdForBug13277(rsmd);
+ this.rs.close();
+
+ } finally {
+ if (this.pstmt != null) {
+ this.pstmt.close();
+ this.pstmt = null;
+ }
+
+ if (this.rs != null) {
+ this.rs.close();
+ this.rs = null;
+ }
+ }
+ }
+
+ private void checkRsmdForBug13277(ResultSetMetaData rsmd) throws SQLException {
+ assertEquals(17, rsmd.getColumnDisplaySize(1));
+ assertEquals(false, rsmd.isDefinitelyWritable(1));
+ assertEquals(true, rsmd.isReadOnly(1));
+ assertEquals(false, rsmd.isWritable(1));
+ }
+
public void testSupportsCorrelatedSubqueries() throws Exception {
DatabaseMetaData dbmd = this.conn.getMetaData();
| Thread |
|---|
| • Connector/J commit: r4265 - in branches/branch_3_1/connector-j: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 16 Sep |