Re: [PATCHES] patch for ResultSet.java

From: Barry Lind <barry(at)xythos(dot)com>
To: Alexander Litvinov <lan(at)ac-sw(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [PATCHES] patch for ResultSet.java
Date: 2002-04-19 16:43:44
Message-ID: 3CC04940.9090209@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-patches

Alexander,

Can you describe the problem you are having a little better. I don't
understand why you are getting "1903-12-29 18:00:12.68", you should be
getting something like "1903-12-29 18:00:12.68+05" (i.e. the timezone
offset should be returned by the server. What is the datatype of the
column you are selecting from?

I need to better understand the cause of the problem so I can understand
the correctness of your patch.

thanks,
--Barry

Alexander Litvinov wrote:
> If I try to fetch timestamp using rs,getTimestamp("name") I got:
>
> java.lang.StringIndexOutOfBoundsException: String index out of range: 22
> at java.lang.String.charAt(String.java(Compiled Code))
> at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653)
> at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java:398)
> at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java:617)
>
> Later I tried to do rs.getString("name") I got: "1903-12-29 18:00:12.68"
>
> Using PostgreSQL v7.1.3 (JDBC from 7.2.1)
>
> I have added some bounds check to ResultSet.java. See attached patch.
>
>
> ------------------------------------------------------------------------
>
> --- src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java.original Thu Apr 18 22:48:40 2002
> +++ src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java Thu Apr 18 22:57:44 2002
> @@ -1641,17 +1641,22 @@
> int i = 19;
> resultSet.sbuf.setLength(i);
>
> - char c = s.charAt(i++);
> + char c = s.charAt(i);
> if (c == '.')
> {
> // Found a fractional value. Append up to 3 digits including
> // the leading '.'
> - do
> - {
> - if (i < 24)
> + resultSet.sbuf.append(c);
> + i++;
> + while (i < s.length() && i < 24) {
> + c = s.charAt(i);
> + if (Character.isDigit(c)) {
> resultSet.sbuf.append(c);
> - c = s.charAt(i++);
> - } while (Character.isDigit(c));
> + i++;
> + }
> + else
> + break;
> + }
>
> // If there wasn't at least 3 digits we should add some zeros
> // to make up the 3 digits we tell java to expect.
> @@ -1667,7 +1672,7 @@
> // prepend the GMT part and then add the remaining bit of
> // the string.
> resultSet.sbuf.append(" GMT");
> - resultSet.sbuf.append(c);
> +// resultSet.sbuf.append(c);
> resultSet.sbuf.append(s.substring(i, s.length()));
>
> // Lastly, if the tz part doesn't specify the :MM part then
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Anders Bengtsson 2002-04-19 16:49:05 Re: BLOB performance test FYI
Previous Message Tim Pizey 2002-04-19 16:31:12 Melati 0.6.0 Released

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2002-04-19 16:57:49 Re: Odd(?) RI-trigger behavior
Previous Message Nigel J. Andrews 2002-04-19 12:14:13 Re: Alter/update large tables - VERRRY annoying behaviour!