From 4083018e380a5c8a08323a43dc49fa8dda3635e0 Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Wed, 26 Aug 2009 16:10:55 +0000 Subject: [PATCH] OPENJPA-1266: no need to cast for JDBC escape syntax for date, time, timestamp in DB2 git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@808086 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/jdbc/sql/DB2Dictionary.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java index 2956dc063..547fd1f86 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java @@ -44,6 +44,7 @@ import org.apache.openjpa.jdbc.schema.Sequence; import org.apache.openjpa.jdbc.schema.Table; import org.apache.openjpa.kernel.Filters; import org.apache.openjpa.kernel.MixedLockLevels; +import org.apache.openjpa.kernel.exps.Literal; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.util.OpenJPAException; @@ -195,14 +196,19 @@ public class DB2Dictionary int idx) { // if this is a literal value, add a cast... Object val = sel.getSelects().get(idx); - if (val instanceof Lit) + boolean toCast = (val instanceof Lit) && + ((Lit)val).getParseType() != Literal.TYPE_DATE && + ((Lit)val).getParseType() != Literal.TYPE_TIME && + ((Lit)val).getParseType() != Literal.TYPE_TIMESTAMP; + + if (toCast) selectSQL.append("CAST("); // ... and add the select per super's behavior... super.appendSelect(selectSQL, alias, sel, idx); // ... and finish the cast - if (val instanceof Lit) { + if (toCast) { Class c = ((Lit) val).getType(); int javaTypeCode = JavaTypes.getTypeCode(c); int jdbcTypeCode = getJDBCType(javaTypeCode, false);