danny0405 commented on a change in pull request #1299: [CALCITE-3100] cast(? as 
DATE) won't work with PreparedStatement
URL: https://github.com/apache/calcite/pull/1299#discussion_r300829602
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/JdbcTest.java
 ##########
 @@ -6908,6 +6910,51 @@ public void testJsonPretty() {
         .returns("A=29; B=35; C=37; D=36\n");
   }
 
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-3100";>[CALCITE-3100]
+   * cast(? as DATE) won't work with PreparedStatement
+   * error</a>.
+   */
+  @Test public void testPreparedStatementException() throws Exception {
+    Connection connection = CalciteAssert.that()
+            
.with(CalciteAssert.SchemaSpec.DATETIMEDATA).with(Lex.MYSQL).connect();
+
+    PreparedStatement dateStatement = connection.prepareStatement(
+            "select * from types where da = cast(? as DATE)");
+    dateStatement.setString(1, "1996-08-03");
+    dateStatement.execute();
+
+    PreparedStatement timeStatement = connection.prepareStatement(
+            "select * from types where ti = cast(? as TIME)");
+    timeStatement.setString(1, "10:15:00");
+    timeStatement.execute();
+
+    //From local time to UTC
+    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", 
Locale.SIMPLIFIED_CHINESE);
+    java.util.Date d1 = format.parse("10:30:00");
+    java.util.Date d2 = format.parse("12:00:00");
 
 Review comment:
   date1 and date2

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to