OPENJPA-1266: JDBC escape syntax for date, time, timestamp support

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@808198 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-08-26 22:01:25 +00:00
parent f68c531a5b
commit 9177e9369a
2 changed files with 11 additions and 29 deletions

View File

@ -293,23 +293,11 @@ TOKEN : /* literals */
)
"'"
>
| < DATE_LITERAL: "{d '" (["0"-"9"])(["0"-"9"])(["0"-"9"])(["0"-"9"]) ("-")
(["0"-"1"])(["0"-"9"]) ("-")
(["0"-"3"])(["0"-"9"]) "'}"
| < DATE_LITERAL: "{d '" (["0"-"9", "-"])* "'}"
>
| < TIME_LITERAL: "{t '" (["0"-"2"])(["0"-"9"]) (":")
(["0"-"6"])(["0"-"9"]) (":")
(["0"-"6"])(["0"-"9"]) "'}"
| < TIME_LITERAL: "{t '" (["0"-"9", ":"])* "'}"
>
| < TIMESTAMP_LITERAL: "{ts '" (["0"-"9"])(["0"-"9"])(["0"-"9"])(["0"-"9"]) ("-")
(["0"-"1"])(["0"-"9"]) ("-")
(["0"-"3"])(["0"-"9"]) (" ")
(["0"-"2"])(["0"-"9"]) (":")
(["0"-"6"])(["0"-"9"]) (":")
(["0"-"6"])(["0"-"9"])
((".") (["0"-"9"]) (["0"-"9"])? (["0"-"9"])? (["0"-"9"])?
(["0"-"9"])? (["0"-"9"])? )?
"'}"
| < TIMESTAMP_LITERAL: "{ts '" (["0"-"9", "-", ":", " ", "."])* "'}"
>
}

View File

@ -55,14 +55,16 @@ public class TestJDBCEscapeDate extends SingleEMFTestCase {
String[] jpql = {
"select a from Employee a where a.hireDate >= {d '2009-08-25'}",
"select a from Employee a where a.hireDate >= {d '2009-8-5'}",
"select a from Employee a where a.hireTime >= {t '00:00:00'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.11'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.111'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1111'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.11111'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.111111'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1234'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12345'}",
"select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123456'}",
"select {t '00:00:00'}, a.empId from Employee a",
};
@ -72,16 +74,8 @@ public class TestJDBCEscapeDate extends SingleEMFTestCase {
Assert.assertEquals(1, results.size());
}
String wrongTs = "select a from Employee a where a.hireTimestamp > {ts '2009-08-25 00:00:00.1111111'}";
try {
Query q = em.createQuery(wrongTs);
List results = q.getResultList();
Assert.fail();
} catch (Exception ex) {
}
em.getTransaction().begin();
String update = "update Employee a set a.hireTimestamp = {ts '2009-08-25 00:00:00.111111'} where a.empId = 1";
String update = "update Employee a set a.hireTimestamp = {ts '2009-08-25 00:00:00.123456'} where a.empId = 1";
Query q = em.createQuery(update);
int updateCnt = q.executeUpdate();
em.getTransaction().commit();