This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_2_509 in repository libpostgresql-jdbc-java.
commit e280999e8391be2fea7aa106148ffd275ec49e73 Author: Kris Jurka <[email protected]> Date: Sun Nov 16 12:14:28 2008 +0000 Support a parameter (?) for the amount part of the timestampadd function. Previously we only supported literals. Christophe Janton --- org/postgresql/jdbc2/EscapedFunctions.java | 95 ++++++++++++++-------------- org/postgresql/test/jdbc2/StatementTest.java | 20 +++++- 2 files changed, 66 insertions(+), 49 deletions(-) diff --git a/org/postgresql/jdbc2/EscapedFunctions.java b/org/postgresql/jdbc2/EscapedFunctions.java index 5a81ec0..4152e9f 100644 --- a/org/postgresql/jdbc2/EscapedFunctions.java +++ b/org/postgresql/jdbc2/EscapedFunctions.java @@ -3,7 +3,7 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v 1.8 2006/04/04 22:52:42 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v 1.8.2.1 2008/02/19 06:12:41 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -504,36 +504,36 @@ public class EscapedFunctions { } String interval = EscapedFunctions.constantToInterval(parsedArgs.get(0).toString(),parsedArgs.get(1).toString()); StringBuffer buf = new StringBuffer(); - buf.append("(interval ").append(interval) - .append("+").append(parsedArgs.get(2)).append(")"); + buf.append("(").append(interval).append("+"); + buf.append(parsedArgs.get(2)).append(")"); return buf.toString(); } private final static String constantToInterval(String type,String value)throws SQLException{ - if (!type.startsWith(SQL_TSI_ROOT)) - throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), + if (!type.startsWith(SQL_TSI_ROOT)) + throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), PSQLState.SYNTAX_ERROR); - String shortType = type.substring(SQL_TSI_ROOT.length()); - if (SQL_TSI_DAY.equalsIgnoreCase(shortType)) - return "'"+value+" day'"; - else if (SQL_TSI_SECOND.equalsIgnoreCase(shortType)) - return "'"+value+" second'"; - else if (SQL_TSI_HOUR.equalsIgnoreCase(shortType)) - return "'"+value+" hour'"; - else if (SQL_TSI_MINUTE.equalsIgnoreCase(shortType)) - return "'"+value+" minute'"; - else if (SQL_TSI_MONTH.equalsIgnoreCase(shortType)) - return "'"+value+" month'"; - else if (SQL_TSI_QUARTER.equalsIgnoreCase(shortType)) - return "'"+ Integer.valueOf(value).intValue()*3+" month'"; - else if (SQL_TSI_WEEK.equalsIgnoreCase(shortType)) - return "'"+value+" week'"; - else if (SQL_TSI_YEAR.equalsIgnoreCase(shortType)) - return "'"+value+" year'"; - else if (SQL_TSI_FRAC_SECOND.equalsIgnoreCase(shortType)) - throw new PSQLException(GT.tr("Interval {0} not yet implemented","SQL_TSI_FRAC_SECOND"), + String shortType = type.substring(SQL_TSI_ROOT.length()); + if (SQL_TSI_DAY.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' day' as interval)"; + else if (SQL_TSI_SECOND.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' second' as interval)"; + else if (SQL_TSI_HOUR.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' hour' as interval)"; + else if (SQL_TSI_MINUTE.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' minute' as interval)"; + else if (SQL_TSI_MONTH.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' month' as interval)"; + else if (SQL_TSI_QUARTER.equalsIgnoreCase(shortType)) + return "CAST((" + value + "::int * 3) || ' month' as interval)"; + else if (SQL_TSI_WEEK.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' week' as interval)"; + else if (SQL_TSI_YEAR.equalsIgnoreCase(shortType)) + return "CAST(" + value + " || ' year' as interval)"; + else if (SQL_TSI_FRAC_SECOND.equalsIgnoreCase(shortType)) + throw new PSQLException(GT.tr("Interval {0} not yet implemented","SQL_TSI_FRAC_SECOND"), PSQLState.SYNTAX_ERROR); - else throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), + else throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), PSQLState.SYNTAX_ERROR); } @@ -552,30 +552,31 @@ public class EscapedFunctions { } private final static String constantToDatePart(String type)throws SQLException{ - if (!type.startsWith(SQL_TSI_ROOT)) - throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), + if (!type.startsWith(SQL_TSI_ROOT)) + throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), PSQLState.SYNTAX_ERROR); - String shortType = type.substring(SQL_TSI_ROOT.length()); - if (SQL_TSI_DAY.equalsIgnoreCase(shortType)) - return "day"; - else if (SQL_TSI_SECOND.equalsIgnoreCase(shortType)) - return "second"; - else if (SQL_TSI_HOUR.equalsIgnoreCase(shortType)) - return "hour"; - else if (SQL_TSI_MINUTE.equalsIgnoreCase(shortType)) - return "minute"; - /*else if (SQL_TSI_MONTH.equalsIgnoreCase(shortType)) - return "month"; - else if (SQL_TSI_QUARTER.equalsIgnoreCase(shortType)) - return "quarter"; - else if (SQL_TSI_WEEK.equalsIgnoreCase(shortType)) - return "week"; - else if (SQL_TSI_YEAR.equalsIgnoreCase(shortType)) - return "year";*/ - else if (SQL_TSI_FRAC_SECOND.equalsIgnoreCase(shortType)) - throw new PSQLException(GT.tr("Interval {0} not yet implemented","SQL_TSI_FRAC_SECOND"), + String shortType = type.substring(SQL_TSI_ROOT.length()); + if (SQL_TSI_DAY.equalsIgnoreCase(shortType)) + return "day"; + else if (SQL_TSI_SECOND.equalsIgnoreCase(shortType)) + return "second"; + else if (SQL_TSI_HOUR.equalsIgnoreCase(shortType)) + return "hour"; + else if (SQL_TSI_MINUTE.equalsIgnoreCase(shortType)) + return "minute"; + // See http://archives.postgresql.org/pgsql-jdbc/2006-03/msg00096.php + /*else if (SQL_TSI_MONTH.equalsIgnoreCase(shortType)) + return "month"; + else if (SQL_TSI_QUARTER.equalsIgnoreCase(shortType)) + return "quarter"; + else if (SQL_TSI_WEEK.equalsIgnoreCase(shortType)) + return "week"; + else if (SQL_TSI_YEAR.equalsIgnoreCase(shortType)) + return "year";*/ + else if (SQL_TSI_FRAC_SECOND.equalsIgnoreCase(shortType)) + throw new PSQLException(GT.tr("Interval {0} not yet implemented","SQL_TSI_FRAC_SECOND"), PSQLState.SYNTAX_ERROR); - else throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), + else throw new PSQLException(GT.tr("Interval {0} not yet implemented",type), PSQLState.SYNTAX_ERROR); } diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java index 0cea184..205ebc0 100644 --- a/org/postgresql/test/jdbc2/StatementTest.java +++ b/org/postgresql/test/jdbc2/StatementTest.java @@ -3,7 +3,7 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.23 2006/11/02 15:31:14 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.24 2006/12/01 08:53:46 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -288,6 +288,22 @@ public class StatementTest extends TestCase assertEquals("bc",rs.getString(6)); assertEquals("ABCD",rs.getString(7)); } + + public void testDateFuncWithParam() throws SQLException + { + // Prior to 8.0 there is not an interval + timestamp operator, + // so timestampadd does not work. + // + if (!TestUtil.haveMinimumServerVersion(con, "8.0")) + return; + + PreparedStatement ps = con.prepareStatement("SELECT {fn timestampadd(SQL_TSI_QUARTER, ? ,{fn now()})}, {fn timestampadd(SQL_TSI_MONTH, ?, {fn now()})} "); + ps.setInt(1, 4); + ps.setInt(2, 12); + ResultSet rs = ps.executeQuery(); + assertTrue(rs.next()); + assertEquals(rs.getTimestamp(1), rs.getTimestamp(2)); + } public void testDateFunctions() throws SQLException { @@ -304,7 +320,7 @@ public class StatementTest extends TestCase // ensure sunday =>1 and monday =>2 assertEquals(2,rs.getInt(5)); - // Prior to 8.0 there is not an interval + timestamp operator, + // Prior to 8.0 there is not an interval + timestamp operator, // so timestampadd does not work. // if (!TestUtil.haveMinimumServerVersion(con, "8.0")) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

