pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Xavier Poinsard <xpoinsard@free.fr>
To: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Two bugs found (and patch included)
Date: Mon, 17 Jan 2005 16:23:17 +0100
Message-ID: <41EBD865.20507@free.fr> (raw)

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.

Attachments:

patchDOWandTSbugs.txt (text/plain, 3.7K) download 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

view thread (4+ messages)  latest in thread

Message-ID: <41EBD865.20507@free.fr>
Permalink:  ../41EBD865.20507@free.fr/
Also on:    postgresql.org/message-id/41EBD865.20507@free.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: xpoinsard@free.fr
  Subject: Re: Two bugs found (and patch included)
  In-Reply-To: <41EBD865.20507@free.fr>
  References: <41EBD865.20507@free.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox