Modified:
branches/branch_3_1/connector-j/CHANGES
branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
branches/branch_3_1/connector-j/src/com/mysql/jdbc/TimeUtil.java
branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/TimeUtil.java
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
tags/v_3_1_14/connector-j/CHANGES
tags/v_3_1_14/connector-j/src/com/mysql/jdbc/ResultSet.java
tags/v_3_1_14/connector-j/src/com/mysql/jdbc/TimeUtil.java
tags/v_3_1_14/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
trunk/connector-j/CHANGES
trunk/connector-j/src/com/mysql/jdbc/ResultSet.java
trunk/connector-j/src/com/mysql/jdbc/TimeUtil.java
trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
Log:
Fixed BUG#21814 - time values outside valid range silently wrap.
Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES 2006-10-18 20:47:34 UTC (rev 5899)
+++ branches/branch_3_1/connector-j/CHANGES 2006-10-18 21:33:06 UTC (rev 5900)
@@ -69,7 +69,9 @@
- Fixed bug when calling stored functions, where parameters weren't
numbered correctly (first parameter is now the return value, subsequent
parameters if specified start at index "2").
-
+
+ - Fixed BUG#21814 - time values outside valid range silently wrap.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 20:47:34
UTC (rev 5899)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 21:33:06
UTC (rev 5900)
@@ -875,7 +875,7 @@
}
private synchronized Time fastTimeCreate(Calendar cal, int hour,
- int minute, int second) {
+ int minute, int second) throws SQLException {
if (cal == null) {
if (this.fastDateCal == null) {
this.fastDateCal = new GregorianCalendar(Locale.US);
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/TimeUtil.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 20:47:34
UTC (rev 5899)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 21:33:06
UTC (rev 5900)
@@ -25,6 +25,7 @@
package com.mysql.jdbc;
import java.sql.Date;
+import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
@@ -923,7 +924,25 @@
}
final static Time fastTimeCreate(Calendar cal, int hour, int minute,
- int second) {
+ int second) throws SQLException {
+ if (hour < 0 || hour > 23) {
+ throw new SQLException("Illegal hour value '" + hour + "' for java.sql.Time type in
value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (minute < 0 || minute > 59) {
+ throw new SQLException("Illegal minute value '" + minute + "'" + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (second < 0 || second > 59) {
+ throw new SQLException("Illegal minute value '" + second + "'" + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
cal.clear();
// Set 'date' to epoch of Jan 1, 1970
@@ -1056,4 +1075,35 @@
return canonicalTz;
}
+
+ // we could use SimpleDateFormat, but it won't work when the time values
+ // are out-of-bounds, and we're using this for error messages for exactly
+ // that case
+ //
+
+ private static String timeFormattedString(int hours, int minutes, int seconds) {
+ StringBuffer buf = new StringBuffer(8);
+
+ if (hours < 10) {
+ buf.append("0");
+ }
+
+ buf.append(hours);
+ buf.append(":");
+
+ if (minutes < 10) {
+ buf.append("0");
+ }
+
+ buf.append(minutes);
+ buf.append(":");
+
+ if (seconds < 10) {
+ buf.append("0");
+ }
+
+ buf.append(seconds);
+
+ return buf.toString();
+ }
}
Modified:
branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
---
branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
20:47:34 UTC (rev 5899)
+++
branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
21:33:06 UTC (rev 5900)
@@ -2685,6 +2685,35 @@
}
}
+ /**
+ * Tests fix for BUG#21814 - time values outside valid range silently wrap
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21814() throws Exception {
+ try {
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '24:01'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '23:92'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+
private void traverseResultSetBug14562() throws SQLException {
assertTrue(this.rs.next());
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2006-10-18 20:47:34 UTC (rev 5899)
+++ branches/branch_5_0/connector-j/CHANGES 2006-10-18 21:33:06 UTC (rev 5900)
@@ -279,7 +279,12 @@
- Fixed BUG#18258 - DatabaseMetaData.getTables(), columns() with bad
catalog parameter threw exception rather than return empty result
set (as required by spec).
-
+
+ - Check and store value for continueBatchOnError property in constructor
+ of Statements, rather than when executing batches, so that Connections
+ closed out from underneath statements don't cause NullPointerExceptions
+ when it's required to check this property.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 20:47:34
UTC (rev 5899)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 21:33:06
UTC (rev 5900)
@@ -872,7 +872,7 @@
}
private Time fastTimeCreate(Calendar cal, int hour,
- int minute, int second) {
+ int minute, int second) throws SQLException {
if (cal == null) {
cal = this.fastDateCal;
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/TimeUtil.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 20:47:34
UTC (rev 5899)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 21:33:06
UTC (rev 5900)
@@ -25,6 +25,7 @@
package com.mysql.jdbc;
import java.sql.Date;
+import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
@@ -993,7 +994,25 @@
}
final static Time fastTimeCreate(Calendar cal, int hour, int minute,
- int second) {
+ int second) throws SQLException {
+ if (hour < 0 || hour > 23) {
+ throw SQLError.createSQLException("Illegal hour value '" + hour + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (minute < 0 || minute > 59) {
+ throw SQLError.createSQLException("Illegal minute value '" + minute + "'" + "' for
java.sql.Time type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (second < 0 || second > 59) {
+ throw SQLError.createSQLException("Illegal minute value '" + second + "'" + "' for
java.sql.Time type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
cal.clear();
// Set 'date' to epoch of Jan 1, 1970
@@ -1127,4 +1146,34 @@
return canonicalTz;
}
+ // we could use SimpleDateFormat, but it won't work when the time values
+ // are out-of-bounds, and we're using this for error messages for exactly
+ // that case
+ //
+
+ private static String timeFormattedString(int hours, int minutes, int seconds) {
+ StringBuffer buf = new StringBuffer(8);
+
+ if (hours < 10) {
+ buf.append("0");
+ }
+
+ buf.append(hours);
+ buf.append(":");
+
+ if (minutes < 10) {
+ buf.append("0");
+ }
+
+ buf.append(minutes);
+ buf.append(":");
+
+ if (seconds < 10) {
+ buf.append("0");
+ }
+
+ buf.append(seconds);
+
+ return buf.toString();
+ }
}
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
20:47:34 UTC (rev 5899)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
21:33:06 UTC (rev 5900)
@@ -3716,6 +3716,35 @@
}
}
+ /**
+ * Tests fix for BUG#21814 - time values outside valid range silently wrap
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21814() throws Exception {
+ try {
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '24:01'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '23:92'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+
public void testTruncationDisable() throws Exception {
Properties props = new Properties();
props.setProperty("jdbcCompliantTruncation", "false");
Modified: tags/v_3_1_14/connector-j/CHANGES
===================================================================
--- tags/v_3_1_14/connector-j/CHANGES 2006-10-18 20:47:34 UTC (rev 5899)
+++ tags/v_3_1_14/connector-j/CHANGES 2006-10-18 21:33:06 UTC (rev 5900)
@@ -69,7 +69,9 @@
- Fixed bug when calling stored functions, where parameters weren't
numbered correctly (first parameter is now the return value, subsequent
parameters if specified start at index "2").
-
+
+ - Fixed BUG#21814 - time values outside valid range silently wrap.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified: tags/v_3_1_14/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- tags/v_3_1_14/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 20:47:34 UTC
(rev 5899)
+++ tags/v_3_1_14/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 21:33:06 UTC
(rev 5900)
@@ -875,7 +875,7 @@
}
private synchronized Time fastTimeCreate(Calendar cal, int hour,
- int minute, int second) {
+ int minute, int second) throws SQLException {
if (cal == null) {
if (this.fastDateCal == null) {
this.fastDateCal = new GregorianCalendar(Locale.US);
Modified: tags/v_3_1_14/connector-j/src/com/mysql/jdbc/TimeUtil.java
===================================================================
--- tags/v_3_1_14/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 20:47:34 UTC
(rev 5899)
+++ tags/v_3_1_14/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 21:33:06 UTC
(rev 5900)
@@ -25,6 +25,7 @@
package com.mysql.jdbc;
import java.sql.Date;
+import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
@@ -923,7 +924,25 @@
}
final static Time fastTimeCreate(Calendar cal, int hour, int minute,
- int second) {
+ int second) throws SQLException {
+ if (hour < 0 || hour > 23) {
+ throw new SQLException("Illegal hour value '" + hour + "' for java.sql.Time type in
value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (minute < 0 || minute > 59) {
+ throw new SQLException("Illegal minute value '" + minute + "'" + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (second < 0 || second > 59) {
+ throw new SQLException("Illegal minute value '" + second + "'" + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
cal.clear();
// Set 'date' to epoch of Jan 1, 1970
@@ -1056,4 +1075,34 @@
return canonicalTz;
}
+
+ // we could use SimpleDateFormat, but it won't work when the time values
+ // are out-of-bounds, and we're using this for error messages for exactly
+ // that case
+ //
+
+ private static String timeFormattedString(int hours, int minutes, int seconds) {
+ StringBuffer buf = new StringBuffer(8);
+ if (hours < 10) {
+ buf.append("0");
+ }
+
+ buf.append(hours);
+ buf.append(":");
+
+ if (minutes < 10) {
+ buf.append("0");
+ }
+
+ buf.append(minutes);
+ buf.append(":");
+
+ if (seconds < 10) {
+ buf.append("0");
+ }
+
+ buf.append(seconds);
+
+ return buf.toString();
+ }
}
Modified: tags/v_3_1_14/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
---
tags/v_3_1_14/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
20:47:34 UTC (rev 5899)
+++
tags/v_3_1_14/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
21:33:06 UTC (rev 5900)
@@ -2685,6 +2685,35 @@
}
}
+ /**
+ * Tests fix for BUG#21814 - time values outside valid range silently wrap
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21814() throws Exception {
+ try {
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '24:01'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '23:92'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+
private void traverseResultSetBug14562() throws SQLException {
assertTrue(this.rs.next());
Modified: trunk/connector-j/CHANGES
===================================================================
--- trunk/connector-j/CHANGES 2006-10-18 20:47:34 UTC (rev 5899)
+++ trunk/connector-j/CHANGES 2006-10-18 21:33:06 UTC (rev 5900)
@@ -279,7 +279,12 @@
- Fixed BUG#18258 - DatabaseMetaData.getTables(), columns() with bad
catalog parameter threw exception rather than return empty result
set (as required by spec).
-
+
+ - Check and store value for continueBatchOnError property in constructor
+ of Statements, rather than when executing batches, so that Connections
+ closed out from underneath statements don't cause NullPointerExceptions
+ when it's required to check this property.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified: trunk/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 20:47:34 UTC (rev 5899)
+++ trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-10-18 21:33:06 UTC (rev 5900)
@@ -877,7 +877,7 @@
}
private Time fastTimeCreate(Calendar cal, int hour,
- int minute, int second) {
+ int minute, int second) throws SQLException {
if (cal == null) {
cal = this.fastDateCal;
}
Modified: trunk/connector-j/src/com/mysql/jdbc/TimeUtil.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 20:47:34 UTC (rev 5899)
+++ trunk/connector-j/src/com/mysql/jdbc/TimeUtil.java 2006-10-18 21:33:06 UTC (rev 5900)
@@ -25,6 +25,7 @@
package com.mysql.jdbc;
import java.sql.Date;
+import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
@@ -992,7 +993,25 @@
}
final static Time fastTimeCreate(Calendar cal, int hour, int minute,
- int second) {
+ int second) throws SQLException {
+ if (hour < 0 || hour > 23) {
+ throw SQLError.createSQLException("Illegal hour value '" + hour + "' for java.sql.Time
type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (minute < 0 || minute > 59) {
+ throw SQLError.createSQLException("Illegal minute value '" + minute + "'" + "' for
java.sql.Time type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ if (second < 0 || second > 59) {
+ throw SQLError.createSQLException("Illegal minute value '" + second + "'" + "' for
java.sql.Time type in value '"
+ + timeFormattedString(hour, minute, second) + ".",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
cal.clear();
// Set 'date' to epoch of Jan 1, 1970
@@ -1126,4 +1145,33 @@
return canonicalTz;
}
+ // we could use SimpleDateFormat, but it won't work when the time values
+ // are out-of-bounds, and we're using this for error messages for exactly
+ // that case
+ //
+
+ private static String timeFormattedString(int hours, int minutes, int seconds) {
+ StringBuffer buf = new StringBuffer(8);
+ if (hours < 10) {
+ buf.append("0");
+ }
+
+ buf.append(hours);
+ buf.append(":");
+
+ if (minutes < 10) {
+ buf.append("0");
+ }
+
+ buf.append(minutes);
+ buf.append(":");
+
+ if (seconds < 10) {
+ buf.append("0");
+ }
+
+ buf.append(seconds);
+
+ return buf.toString();
+ }
}
Modified: trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java
===================================================================
--- trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
20:47:34 UTC (rev 5899)
+++ trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-10-18
21:33:06 UTC (rev 5900)
@@ -3716,6 +3716,35 @@
}
}
+ /**
+ * Tests fix for BUG#21814 - time values outside valid range silently wrap
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21814() throws Exception {
+ try {
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '24:01'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+
+ try {
+ this.rs = this.stmt.executeQuery("SELECT '23:92'");
+ this.rs.next();
+ this.rs.getTime(1);
+ fail("Expected exception");
+ } catch (SQLException sqlEx) {
+ assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
+ }
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+
public void testTruncationDisable() throws Exception {
Properties props = new Properties();
props.setProperty("jdbcCompliantTruncation", "false");
| Thread |
|---|
| • Connector/J commit: r5900 - branches/branch_3_1/connector-j branches/branch_3_1/connector-j/src/com/mysql/jdbc branches/branch_3_1/connector-j/src/tes... | mmatthews | 18 Oct |