X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9854C3A1991 for ; Mon, 17 Jan 2005 15:23:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12664-05 for ; Mon, 17 Jan 2005 15:23:20 +0000 (GMT) Received: from mallaury.noc.nerim.net (smtp-101-monday.noc.nerim.net [62.4.17.101]) by svr1.postgresql.org (Postfix) with ESMTP id E09C43A2CB2 for ; Mon, 17 Jan 2005 15:23:20 +0000 (GMT) Received: from [192.168.0.185] (secure.openpricer.com [80.65.224.34]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 016BB62E41 for ; Mon, 17 Jan 2005 16:23:18 +0100 (CET) Message-ID: <41EBD865.20507@free.fr> Date: Mon, 17 Jan 2005 16:23:17 +0100 From: "Xavier Poinsard" User-Agent: Mozilla Thunderbird 0.9 (X11/20041124) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc Subject: Two bugs found (and patch included) Content-Type: multipart/mixed; boundary="------------040806040802060107030101" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.088 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/169 X-Sequence-Number: 12049 This is a multi-part message in MIME format. --------------040806040802060107030101 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I just discovered two bugs and attached a patch to correct them : - the jdbc escaped scalar function dayofweek should return values between 1 and 7 (1 for sunday) unlike the backend "extract dow" function - the literal escaped values for date/time/timestamp were not explicitly casted and causing some problems : for example extract( dow from '2005-01-17 12:00:00') generate an error, but the following is accepted extract( dow from TIMESTAMP '2005-01-17 12:00:00') Xavier Poinsard. --------------040806040802060107030101 Content-Type: text/plain; name="patchDOWandTSbugs.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patchDOWandTSbugs.txt" Index: jdbc2/AbstractJdbc2Statement.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v retrieving revision 1.63 diff -u -r1.63 AbstractJdbc2Statement.java --- jdbc2/AbstractJdbc2Statement.java 15 Jan 2005 07:53:02 -0000 1.63 +++ jdbc2/AbstractJdbc2Statement.java 17 Jan 2005 15:12:04 -0000 @@ -756,12 +756,21 @@ { state = ESC_TIMEDATE; i++; + newsql.append("DATE "); break; } else if (next == 't' || next == 'T') { state = ESC_TIMEDATE; - i += (nextnext == 's' || nextnext == 'S') ? 2 : 1; + if (nextnext == 's' || nextnext == 'S'){ + // timestamp constant + i+=2; + newsql.append("TIMESTAMP "); + }else{ + // time constant + i++; + newsql.append("TIME "); + } break; } else if ( next == 'f' || next == 'F' ) Index: jdbc2/EscapedFunctions.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v retrieving revision 1.3 diff -u -r1.3 EscapedFunctions.java --- jdbc2/EscapedFunctions.java 14 Jan 2005 01:20:20 -0000 1.3 +++ jdbc2/EscapedFunctions.java 17 Jan 2005 15:12:06 -0000 @@ -399,13 +399,14 @@ return "extract(day from "+parsedArgs.get(0)+")"; } - /** dayofweek translation */ + /** dayofweek translation + * adding 1 to postgresql function since we expect values from 1 to 7 */ public static String sqldayofweek(List parsedArgs) throws SQLException{ if (parsedArgs.size()!=1){ throw new PSQLException(GT.tr("{0} function takes one and only one argument.","dayofweek"), PSQLState.SYNTAX_ERROR); } - return "extract(dow from "+parsedArgs.get(0)+")"; + return "extract(dow from "+parsedArgs.get(0)+")+1"; } /** dayofyear translation */ Index: test/jdbc2/StatementTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v retrieving revision 1.13 diff -u -r1.13 StatementTest.java --- test/jdbc2/StatementTest.java 11 Jan 2005 08:25:48 -0000 1.13 +++ test/jdbc2/StatementTest.java 17 Jan 2005 15:12:07 -0000 @@ -267,13 +267,15 @@ Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select {fn curdate()},{fn curtime()}" + ",{fn dayname({fn now()})}, {fn dayofmonth({fn now()})}" + - ",{fn dayofweek({fn now()})},{fn dayofyear({fn now()})}" + + ",{fn dayofweek({ts '2005-01-17 12:00:00'})},{fn dayofyear({fn now()})}" + ",{fn hour({fn now()})},{fn minute({fn now()})}" + ",{fn month({fn now()})}" + ",{fn monthname({fn now()})},{fn quarter({fn now()})}" + ",{fn second({fn now()})},{fn week({fn now()})}" + ",{fn year({fn now()})} "); assertTrue(rs.next()); + // ensure sunday =>1 and monday =>2 + assertEquals(2,rs.getInt(5)); } public void testSystemFunctions() throws SQLException --------------040806040802060107030101--