You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Bill Schneider <bs...@vecna.com> on 2002/02/26 17:44:33 UTC
[PATCH] Torque: date handling in DBPostgres adapter
The postgres adapter doesn't define getDateString() method, and the
default method in DB.java returns "{ts 'yyyy-mm-dd'}" that causes a
parse error in Postgres. This pops up when you have dates in Criteria like
c.add(START_DATE, new Date(), LESS_EQUAL);
This patch takes the same approach as the Oracle adapter's method.
-- Bill
Index: src/java/org/apache/torque/adapter/DBPostgres.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/adapter/DBPostgres.java,v
retrieving revision 1.5
diff -u -r1.5 DBPostgres.java
--- src/java/org/apache/torque/adapter/DBPostgres.java 21 Feb 2002 16:55:19 -0000 1.5
+++ src/java/org/apache/torque/adapter/DBPostgres.java 26 Feb 2002 16:38:58 -0000
@@ -56,6 +56,8 @@
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.Date;
+import java.text.SimpleDateFormat;
/**
* This is used to connect to PostgresQL databases.
@@ -68,6 +70,9 @@
public class DBPostgres
extends DB
{
+ private static final SimpleDateFormat DATE_FORMATTER =
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
/**
* Empty constructor.
*/
@@ -202,5 +207,17 @@
public int getLimitStyle()
{
return DB.LIMIT_STYLE_POSTGRES;
+ }
+
+ /**
+ * This method is used to format any date string.
+ * Database can use different default date formats.
+ *
+ * @return The proper date formatted String.
+ */
+ public String getDateString(Date date)
+ {
+ return "TO_TIMESTAMP('" + DATE_FORMATTER.format(date) +
+ "', 'yyyy-mm-dd hh24:mi:ss' )";
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>