METAMODEL-1169 closes apache/metamodel#167
authorJakub Neubauer <jakub.neubauer@gmail.com>
Thu, 23 Nov 2017 06:14:53 +0000 (07:14 +0100)
committerDennis Du Krøger <losd@apache.org>
Thu, 23 Nov 2017 06:14:53 +0000 (07:14 +0100)
CHANGES.md
jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/SQLServerQueryRewriter.java
jdbc/src/test/java/org/apache/metamodel/dialects/SQLServerQueryRewriterTest.java

index ddd3c9a..cbf22b9 100644 (file)
@@ -1,3 +1,5 @@
+ * [METAMODEL-1169] - Fixed issue with SQL Server milliseconds precision in WHERE
+
 ### Apache MetaModel 5.0
 
  * [METAMODEL-1161] - Fixed issue with maxRows being ignored on Oracle 
index 4c7e588..3fdcf0e 100644 (file)
@@ -114,7 +114,7 @@ public class SQLServerQueryRewriter extends OffsetFetchQueryRewriter {
 
                 final Date date = (Date) operand;
 
-                final DateFormat format = DateUtils.createDateFormat("yyyyMMdd HH:mm:ss");
+                final DateFormat format = DateUtils.createDateFormat("yyyyMMdd HH:mm:ss.SSS");
                 final String dateTimeValue = "CAST('" + format.format(date) + "' AS DATETIME)";
 
                 sb.append(dateTimeValue);
index f160036..ca07d13 100644 (file)
@@ -122,10 +122,10 @@ public class SQLServerQueryRewriterTest extends TestCase {
                 .select(column)
                 .select(timestampColumn)
                 .where(new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, TimeComparator
-                        .toDate("2014-06-28 14:06:00")));
+                        .toDate("2014-06-28 14:06:00.123")));
 
         assertEquals(
-                "SELECT MY_SCHEMA.\"foo\".\"bar\", timestamp FROM MY_SCHEMA.\"foo\" WHERE timestamp < CAST('20140628 14:06:00' AS DATETIME)",
+                "SELECT MY_SCHEMA.\"foo\".\"bar\", timestamp FROM MY_SCHEMA.\"foo\" WHERE timestamp < CAST('20140628 14:06:00.123' AS DATETIME)",
                 qr.rewriteQuery(q));
     }