Modified:
branches/branch_3_1/connector-j/CHANGES
branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java
branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
Log:
Fixed BUG#17099 - Statement.getGeneratedKeys() throws NullPointerException
when no query has been processed.
Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES 2006-02-07 01:01:24 UTC (rev 4905)
+++ branches/branch_3_1/connector-j/CHANGES 2006-02-07 22:26:08 UTC (rev 4906)
@@ -34,6 +34,9 @@
driver was checking for the existence of single-column primary keys and
an autoincrement value > 0 instead of a straightforward isAutoIncrement()
check).
+
+ - Fixed BUG#17099 - Statement.getGeneratedKeys() throws NullPointerException
+ when no query has been processed.
11-30-05 - Version 3.1.12
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 2006-02-07 01:01:24
UTC (rev 4905)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java 2006-02-07 22:26:08
UTC (rev 4906)
@@ -1141,23 +1141,25 @@
long beginAt = getLastInsertID();
int numKeys = getUpdateCount();
- String serverInfo = this.results.getServerInfo();
-
- //
- // Only parse server info messages for 'REPLACE'
- // queries
- //
- if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R')
- && (serverInfo != null) && (serverInfo.length() > 0)) {
- numKeys = getRecordCountFromInfo(serverInfo);
- }
-
- if ((beginAt > 0) && (numKeys > 0)) {
- for (int i = 0; i < numKeys; i++) {
- byte[][] row = new byte[1][];
- row[0] = Long.toString(beginAt++).getBytes();
- rowSet.add(row);
+ if (this.results != null) {
+ String serverInfo = this.results.getServerInfo();
+
+ //
+ // Only parse server info messages for 'REPLACE'
+ // queries
+ //
+ if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R')
+ && (serverInfo != null) && (serverInfo.length() > 0)) {
+ numKeys = getRecordCountFromInfo(serverInfo);
}
+
+ if ((beginAt > 0) && (numKeys > 0)) {
+ for (int i = 0; i < numKeys; i++) {
+ byte[][] row = new byte[1][];
+ row[0] = Long.toString(beginAt++).getBytes();
+ rowSet.add(row);
+ }
+ }
}
return new com.mysql.jdbc.ResultSet(this.currentCatalog, fields,
Modified:
branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
---
branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-02-07
01:01:24 UTC (rev 4905)
+++
branches/branch_3_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-02-07
22:26:08 UTC (rev 4906)
@@ -2990,5 +2990,23 @@
}
}
}
-
+
+ /**
+ * Tests fix for BUG#17099 - Statement.getGeneratedKeys()
+ * throws NPE when no query has been processed.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug17099() throws Exception {
+ Statement newStmt = this.conn.createStatement();
+ assertNotNull(newStmt.getGeneratedKeys());
+
+ PreparedStatement pStmt = this.conn.prepareStatement("SELECT 1");
+ assertNotNull(pStmt.getGeneratedKeys());
+
+ if (versionMeetsMinimum(4, 1)) {
+ pStmt = ((com.mysql.jdbc.Connection)this.conn).clientPrepareStatement("SELECT 1");
+ assertNotNull(pStmt.getGeneratedKeys());
+ }
+ }
}
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2006-02-07 01:01:24 UTC (rev 4905)
+++ branches/branch_5_0/connector-j/CHANGES 2006-02-07 22:26:08 UTC (rev 4906)
@@ -123,6 +123,9 @@
driver was checking for the existence of single-column primary keys and
an autoincrement value > 0 instead of a straightforward isAutoIncrement()
check).
+
+ - Fixed BUG#17099 - Statement.getGeneratedKeys() throws NullPointerException
+ when no query has been processed.
11-30-05 - Version 3.1.12
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 2006-02-07 01:01:24
UTC (rev 4905)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2006-02-07 22:26:08
UTC (rev 4906)
@@ -650,7 +650,7 @@
null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false,
+ false,
this.currentCatalog, true); //$NON-NLS-1$
} else {
this.connection
@@ -661,7 +661,7 @@
null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false,
+ false,
this.currentCatalog, true); //$NON-NLS-1$
}
}
@@ -672,19 +672,19 @@
"SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, //$NON-NLS-1$
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.currentCatalog,
+ false, this.currentCatalog,
true); //$NON-NLS-1$
}
// Finally, execute the query
rs = this.connection.execSQL(this, sql, rowLimit, null,
this.resultSetType, this.resultSetConcurrency,
- createStreamingResultSet(), isSelect,
+ createStreamingResultSet(),
this.currentCatalog, (cachedMetaData == null));
} else {
rs = this.connection.execSQL(this, sql, -1, null,
this.resultSetType, this.resultSetConcurrency,
- createStreamingResultSet(), isSelect,
+ createStreamingResultSet(),
this.currentCatalog, (cachedMetaData == null));
}
@@ -975,7 +975,7 @@
this.results = this.connection.execSQL(this, sql,
this.maxRows, null, this.resultSetType,
this.resultSetConcurrency,
- createStreamingResultSet(), true,
+ createStreamingResultSet(),
this.currentCatalog, (cachedMetaData == null));
} else {
if (this.maxRows <= 0) {
@@ -985,7 +985,7 @@
"SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, //$NON-NLS-1$
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.currentCatalog,
+ false, this.currentCatalog,
true); //$NON-NLS-1$
} else {
this.connection
@@ -995,14 +995,14 @@
null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.currentCatalog,
+ false, this.currentCatalog,
true); //$NON-NLS-1$
}
this.results = this.connection.execSQL(this, sql, -1,
null, this.resultSetType,
this.resultSetConcurrency,
- createStreamingResultSet(), true,
+ createStreamingResultSet(),
this.currentCatalog, (cachedMetaData == null));
if (oldCatalog != null) {
@@ -1012,7 +1012,7 @@
} else {
this.results = this.connection.execSQL(this, sql, -1, null,
this.resultSetType, this.resultSetConcurrency,
- createStreamingResultSet(), true,
+ createStreamingResultSet(),
this.currentCatalog, (cachedMetaData == null));
}
@@ -1144,16 +1144,16 @@
this,
"SET OPTION SQL_SELECT_LIMIT=DEFAULT", //$NON-NLS-1$
-1, null, java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
this.currentCatalog, true);
}
rs = this.connection.execSQL(this, sql, -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
this.currentCatalog,
true /* force read of field info on DML */,
- USES_VARIABLES_FALSE, isBatch);
+ isBatch);
if (oldCatalog != null) {
this.connection.setCatalog(oldCatalog);
@@ -1376,23 +1376,25 @@
long beginAt = getLastInsertID();
int numKeys = getUpdateCount();
- String serverInfo = this.results.getServerInfo();
-
- //
- // Only parse server info messages for 'REPLACE'
- // queries
- //
- if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R')
- && (serverInfo != null) && (serverInfo.length() > 0)) {
- numKeys = getRecordCountFromInfo(serverInfo);
- }
-
- if ((beginAt > 0) && (numKeys > 0)) {
- for (int i = 0; i < numKeys; i++) {
- byte[][] row = new byte[1][];
- row[0] = Long.toString(beginAt++).getBytes();
- rowSet.add(row);
+ if (this.results != null) {
+ String serverInfo = this.results.getServerInfo();
+
+ //
+ // Only parse server info messages for 'REPLACE'
+ // queries
+ //
+ if ((numKeys > 0) && (this.results.getFirstCharOfQuery() == 'R')
+ && (serverInfo != null) && (serverInfo.length() > 0)) {
+ numKeys = getRecordCountFromInfo(serverInfo);
}
+
+ if ((beginAt > 0) && (numKeys > 0)) {
+ for (int i = 0; i < numKeys; i++) {
+ byte[][] row = new byte[1][];
+ row[0] = Long.toString(beginAt++).getBytes();
+ rowSet.add(row);
+ }
+ }
}
return new com.mysql.jdbc.ResultSet(this.currentCatalog, fields,
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-02-07
01:01:24 UTC (rev 4905)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-02-07
22:26:08 UTC (rev 4906)
@@ -3019,4 +3019,23 @@
}
}
+ /**
+ * Tests fix for BUG#17099 - Statement.getGeneratedKeys()
+ * throws NPE when no query has been processed.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug17099() throws Exception {
+ Statement newStmt = this.conn.createStatement();
+ assertNotNull(newStmt.getGeneratedKeys());
+
+ PreparedStatement pStmt = this.conn.prepareStatement("SELECT 1");
+ assertNotNull(pStmt.getGeneratedKeys());
+
+ if (versionMeetsMinimum(4, 1)) {
+ pStmt = ((com.mysql.jdbc.Connection)this.conn).clientPrepareStatement("SELECT 1");
+ assertNotNull(pStmt.getGeneratedKeys());
+ }
+ }
+
}
| Thread |
|---|
| • Connector/J commit: r4906 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc branch_3_1/connector-j/src/testsuite/regress... | mmatthews | 7 Feb |