Modified:
branches/branch_5_1/CHANGES
branches/branch_5_1/src/com/mysql/jdbc/BufferRow.java
branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
branches/branch_5_1/src/com/mysql/jdbc/ResultSetImpl.java
branches/branch_5_1/src/testsuite/regression/MetaDataRegressionTest.java
Log:
Fixed Bug#33594 - When cursor fetch is enabled, wrong metadata is returned from
DatabaseMetaData calls.
The fix is two parts.
First, when asking for the first column value
twice from a cursor-fetched row, the driver didn't re-position,
and thus the "next" column was returned.
Second, metadata statements and internal statements the driver
uses shouldn't use cursor-based fetching at all, so we've
ensured that internal statements have their fetch size set to "0".
Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES 2008-01-03 09:40:44 UTC (rev 6704)
+++ branches/branch_5_1/CHANGES 2008-01-03 15:30:42 UTC (rev 6705)
@@ -100,6 +100,19 @@
trace as a string into the message, set the underlying Throwable as the cause for
the SQLException, making it accessible via getCause().
+ - Fixed Bug#33594 - When cursor fetch is enabled, wrong metadata is returned from
+ DatabaseMetaData calls.
+
+ The fix is two parts.
+
+ First, when asking for the first column value
+ twice from a cursor-fetched row, the driver didn't re-position,
+ and thus the "next" column was returned.
+
+ Second, metadata statements and internal statements the driver
+ uses shouldn't use cursor-based fetching at all, so we've
+ ensured that internal statements have their fetch size set to "0".
+
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/BufferRow.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/BufferRow.java 2008-01-03 09:40:44 UTC (rev 6704)
+++ branches/branch_5_1/src/com/mysql/jdbc/BufferRow.java 2008-01-03 15:30:42 UTC (rev 6705)
@@ -180,7 +180,8 @@
if (index == 0) {
this.lastRequestedIndex = 0;
this.lastRequestedPos = this.homePosition;
-
+ this.rowFromServer.setPosition(this.homePosition);
+
return 0;
}
Modified: branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java 2008-01-03 09:40:44 UTC (rev 6704)
+++ branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java 2008-01-03 15:30:42 UTC (rev 6705)
@@ -830,12 +830,8 @@
if (sortedCollationMap == null) {
sortedCollationMap = new TreeMap();
- stmt = createStatement();
+ stmt = getMetadataSafeStatement();
- if (stmt.getMaxRows() != 0) {
- stmt.setMaxRows(0);
- }
-
results = stmt
.executeQuery("SHOW COLLATION");
@@ -3002,6 +2998,10 @@
}
stmt.setEscapeProcessing(false);
+
+ if (stmt.getFetchSize() != 0) {
+ stmt.setFetchSize(0);
+ }
return stmt;
}
@@ -3725,8 +3725,7 @@
java.sql.ResultSet results = null;
try {
- stmt = createStatement();
- stmt.setEscapeProcessing(false);
+ stmt = getMetadataSafeStatement();
String version = this.dbmd.getDriverVersion();
@@ -4649,7 +4648,7 @@
java.sql.Statement stmt = null;
try {
- stmt = createStatement();
+ stmt = getMetadataSafeStatement();
stmt.executeUpdate(rollbackQuery.toString());
} catch (SQLException sqlEx) {
@@ -5068,7 +5067,7 @@
java.sql.Statement stmt = null;
try {
- stmt = createStatement();
+ stmt = getMetadataSafeStatement();
stmt.executeUpdate(savePointQuery.toString());
} finally {
Modified: branches/branch_5_1/src/com/mysql/jdbc/ResultSetImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ResultSetImpl.java 2008-01-03 09:40:44 UTC (rev 6704)
+++ branches/branch_5_1/src/com/mysql/jdbc/ResultSetImpl.java 2008-01-03 15:30:42 UTC (rev 6705)
@@ -3441,6 +3441,13 @@
case MysqlDefs.FIELD_TYPE_BIT:
return (byte[]) value;
+ case MysqlDefs.FIELD_TYPE_STRING:
+ case MysqlDefs.FIELD_TYPE_VARCHAR:
+ case MysqlDefs.FIELD_TYPE_VAR_STRING:
+ if (value instanceof byte[]) {
+ return (byte[]) value;
+ }
+ // fallthrough
default:
int sqlType = field.getSQLType();
Modified: branches/branch_5_1/src/testsuite/regression/MetaDataRegressionTest.java
===================================================================
--- branches/branch_5_1/src/testsuite/regression/MetaDataRegressionTest.java 2008-01-03 09:40:44 UTC (rev 6704)
+++ branches/branch_5_1/src/testsuite/regression/MetaDataRegressionTest.java 2008-01-03 15:30:42 UTC (rev 6705)
@@ -2116,4 +2116,82 @@
closeMemberJDBCResources();
}
}
+
+ /**
+ * Tests fix for Bug#33594 - When cursor fetch is enabled,
+ * wrong metadata is returned from DBMD.
+ *
+ * The fix is two parts.
+ *
+ * First, when asking for the first column value
+ * twice from a cursor-fetched row, the driver didn't re-position,
+ * and thus the "next" column was returned.
+ *
+ * Second, metadata statements and internal statements the driver
+ * uses shouldn't use cursor-based fetching at all, so we've
+ * ensured that internal statements have their fetch size set to "0".
+ */
+ public void testBug33594() throws Exception {
+ if (!versionMeetsMinimum(5, 0, 7)) {
+ return;
+ }
+
+ try {
+ createTable(
+ "bug33594",
+ "(fid varchar(255) not null primary key, id INT, geom linestring, name varchar(255))");
+
+ Properties props = new Properties();
+ props.put("useInformationSchema", "false");
+ props.put("useCursorFetch", "false");
+ props.put("defaultFetchSize", "100");
+ Connection conn1 = null;
+ try {
+ conn1 = getConnectionWithProps(props);
+ DatabaseMetaData metaData = conn1.getMetaData();
+ this.rs = metaData.getColumns(null, null, "bug33594", null);
+ this.rs.next();
+ assertEquals("bug33594", this.rs.getString("TABLE_NAME"));
+ assertEquals("fid", this.rs.getString("COLUMN_NAME"));
+ assertEquals("VARCHAR", this.rs.getString("TYPE_NAME"));
+ assertEquals("255", this.rs.getString("COLUMN_SIZE"));
+
+ Properties props2 = new Properties();
+ props2.put("useInformationSchema", "false");
+ props2.put("useCursorFetch", "true");
+ props2.put("defaultFetchSize", "100");
+
+ Connection conn2 = null;
+
+ try {
+ conn2 = getConnectionWithProps(props2);
+ DatabaseMetaData metaData2 = conn2.getMetaData();
+ this.rs = metaData2
+ .getColumns(null, null, "bug33594", null);
+ this.rs.next();
+ assertEquals("bug33594", this.rs.getString("TABLE_NAME"));
+ assertEquals("fid", this.rs.getString("COLUMN_NAME"));
+ assertEquals("VARCHAR", this.rs.getString("TYPE_NAME"));
+ assertEquals("255", this.rs.getString("COLUMN_SIZE"));
+
+ // we should only see one server-side prepared statement, and that's
+ // caused by us going off to ask about the count!
+ assertEquals("1", getSingleIndexedValueWithQuery(conn2, 2,
+ "SHOW SESSION STATUS LIKE 'Com_stmt_prepare'")
+ .toString());
+ } finally {
+ if (conn2 != null) {
+ conn2.close();
+ }
+ }
+ } finally {
+ if (conn1 != null) {
+ conn1.close();
+ }
+ }
+
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r6705 - in branches/branch_5_1: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 3 Jan |