Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
trunk/connector-j/src/testsuite/regression/StatementRegressionTest.java
Log:
Fixed BUG#21438 - Driver sending nanoseconds to server for timestamps when
using server-side prepared statements, when server expects microseconds.
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-01-09
01:02:59 UTC (rev 6276)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-01-09
22:47:30 UTC (rev 6277)
@@ -2247,7 +2247,8 @@
}
if (length == 11) {
- intoBuf.writeLong(((java.sql.Timestamp) dt).getNanos());
+ // MySQL expects microseconds, not nanos
+ intoBuf.writeLong(((java.sql.Timestamp) dt).getNanos() / 1000);
}
} finally {
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-01-09
01:02:59 UTC (rev 6276)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-01-09
22:47:30 UTC (rev 6277)
@@ -3399,7 +3399,42 @@
closeMemberJDBCResources();
}
}
+
+ /**
+ * Tests BUG#21438, server-side PS fails when using jdbcCompliantTruncation.
+ * If either is set to FALSE (&useServerPrepStmts=false or
+ * &jdbcCompliantTruncation=false) test succedes.
+ *
+ * @throws Exception
+ * if the test fails.
+ */
+
+ public void testBug21438() throws Exception {
+ createTable("testBug21438","(t_id int(10), test_date timestamp(30) NOT NULL,primary key
t_pk (t_id));");
+
+ assertEquals(1, this.stmt.executeUpdate("insert into testBug21438 values (1,NOW());"));
+
+ if (this.versionMeetsMinimum(4, 1)) {
+ this.pstmt = ((com.mysql.jdbc.Connection)this.conn)
+ .serverPrepare("UPDATE testBug21438 SET test_date=ADDDATE(?,INTERVAL 1 YEAR) WHERE
t_id=1;");
+
+ try {
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+ ts.setNanos(999999999);
+
+ this.pstmt.setTimestamp(1, ts);
+
+ assertEquals(1, this.pstmt.executeUpdate());
+
+ Timestamp future = (Timestamp)getSingleIndexedValueWithQuery(1, "SELECT test_date
FROM testBug21438");
+ assertEquals(future.getYear() - ts.getYear(), 1);
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+ }
+
/**
* Tests fix for BUG#22359 - Driver was using millis for
* Statement.setQueryTimeout() when spec says argument is
Modified: trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-01-09 01:02:59
UTC (rev 6276)
+++ trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-01-09 22:47:30
UTC (rev 6277)
@@ -2267,7 +2267,8 @@
}
if (length == 11) {
- intoBuf.writeLong(((java.sql.Timestamp) dt).getNanos());
+ // MySQL expects microseconds, not nanos
+ intoBuf.writeLong(((java.sql.Timestamp) dt).getNanos() / 1000);
}
} finally {
Modified: trunk/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- trunk/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-01-09
01:02:59 UTC (rev 6276)
+++ trunk/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-01-09
22:47:30 UTC (rev 6277)
@@ -3400,7 +3400,41 @@
closeMemberJDBCResources();
}
}
+ /**
+ * Tests BUG#21438, server-side PS fails when using jdbcCompliantTruncation.
+ * If either is set to FALSE (&useServerPrepStmts=false or
+ * &jdbcCompliantTruncation=false) test succedes.
+ *
+ * @throws Exception
+ * if the test fails.
+ */
+ public void testBug21438() throws Exception {
+ createTable("testBug21438","(t_id int(10), test_date timestamp(30) NOT NULL,primary key
t_pk (t_id));");
+
+ assertEquals(1, this.stmt.executeUpdate("insert into testBug21438 values (1,NOW());"));
+
+ if (this.versionMeetsMinimum(4, 1)) {
+ this.pstmt = ((com.mysql.jdbc.Connection)this.conn)
+ .serverPrepare("UPDATE testBug21438 SET test_date=ADDDATE(?,INTERVAL 1 YEAR) WHERE
t_id=1;");
+
+ try {
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+ ts.setNanos(999999999);
+
+ this.pstmt.setTimestamp(1, ts);
+
+ assertEquals(1, this.pstmt.executeUpdate());
+
+ Timestamp future = (Timestamp)getSingleIndexedValueWithQuery(1, "SELECT test_date
FROM testBug21438");
+ assertEquals(future.getYear() - ts.getYear(), 1);
+
+ } finally {
+ closeMemberJDBCResources();
+ }
+ }
+ }
+
/**
* Tests fix for BUG#22359 - Driver was using millis for
* Statement.setQueryTimeout() when spec says argument is
| Thread |
|---|
| • Connector/J commit: r6277 - branches/branch_5_0/connector-j/src/com/mysql/jdbc branches/branch_5_0/connector-j/src/testsuite/regression trunk/connecto... | mmatthews | 9 Jan |