From: | Noel Rappin <nrappin(at)sockeye(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Issues with Array Interface |
Date: | 2002-05-30 18:58:07 |
Message-ID: | 3CF6763F.3010205@sockeye.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I think I may have found the timestamp bug -- this code is from
org.postgresql.jdbc2.Array.java:
This is lines 160- 170 in the getArray() function:
case Types.TIME:
retVal = new java.sql.Time[ count ];
for ( ; count > 0; count-- )
((java.sql.Time[])retVal)[i++] = ResultSet.toTime(
arrayContents[(int)index++] );
break;
case Types.TIMESTAMP:
retVal = new Timestamp[ count ];
StringBuffer sbuf = null;
for ( ; count > 0; count-- )
((java.sql.Timestamp[])retVal)[i++] = ResultSet.toTimestamp(
arrayContents[(int)index], rs );
break;
Shouldn't the arrayContents[(int)index] in the TIMESTAMP clause also be
arrayContents[(int)index++]?
getResultSet() is dependent on getArray(), so that would show the same
behavior.
Will try to test this...
Noel
Noel Rappin wrote:
> Okay, let's try this...
>
> The table def is roughly this... It's archiving an entire days worth of
> data into one row. There are some other columns that are unimportant to
> the current problem.
>
> day timestamp without time
> time timestamp with time zone []
> value real[]
>
> I've tried a couple of things with the code, here's what I have now. As
> this works, the data result set generates correct values as it walks
> throgh the set, but the times result set always gives the same value.
>
> public void addOneHistoryRow(ResultSet rs) throws SQLException {
> Array timeArray = rs.getArray("time");
> ResultSet times = timeArray.getResultSet();
> Array dataArray = rs.getArray("value");
> ResultSet data = dataArray.getResultSet();
> while (times.next()) {
> data.next();
> Number value = (Number) data.getObject(2);
> String timeString = times.getString(2);
> try {
> Timestamp time = new Timestamp(
> inputFormat.parse(timeString).getTime());
> this.addOneDataPoint(time, value);
> } catch (ParseException e) {
> System.out.println(e);
> }
> }
> }
>
> There's actually another issue here, which is that I had to parse the
> Timestamp by hand -- I was getting an error on plain getObject() for the
> time column, but that's also minor.
>
> I've tried it a few different ways -- I tried having times be generated
> with
> Timestamp[] times = (Timestamp[]) timeArray.getArray();
>
> Which had the same issue -- every enery in the array had the same value.
>
> Thanks,
>
> Noel
>
>
> Dave Cramer wrote:
>
> >Noel,
> >
> >It would be helpful if you could provide sample code, and table
> >definitions (just enough to reproduce the problem) .
> >
> >Dave
> >On Thu, 2002-05-30 at 11:10, Noel Rappin wrote:
> >
> >
> >>I'm having some problems with the Array interface in 7.2, and I'm
> >>wondering if somebody can point me to a workaround.
> >>
> >>Issue 1:
> >>
> >>The array in the database is of type real[]. The code:
> >>
> >>Array dataArray = rs.getArray("value");
> >>Float[] data = (Float[]) dataArray.getArray();
> >>
> >>gives me a class cast exception. This seems to be true no matter
> what I
> >>try to cast the array to (even Object[]), When I work around by using
> >>dataArray.getResultSet(), it correctly casts the individual elements of
> >>the result to Float. I have an analagous problem when the array is of
> >>type smallint. Since I can work around this with the result set, it's
> >>less of a problem, but it is strange.
> >>
> >>Issue 2:
> >>
> >>The array in the database is of type timestamp with time zone [].
> >>
> >>Array timeArray = rs.getArray("time");
> >>Timestamp[] times = (Timestamp[]) timeArray.getArray();
> >>
> >>runs without a class cast exception, however every element in the array
> >>is set to the same value -- the value that would be at times[0]. This
> >>problem persists even if I use getResultSet() -- even when I next()
> >>through the array, the data value does not change. I can't seem to
> >>access the later values in the array at all.
> >>
> >>Has anybody else seen this problem? Any suggestions for workarounds?
> >> The data can be accessed correctly through psql, so I believe the
> >>problem must be in the driver.
> >>
> >>Thanks,
> >>
> >>Noel Rappin
> >>
> >>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
From | Date | Subject | |
---|---|---|---|
Next Message | d a | 2002-05-30 19:00:31 | Issues with Array interface (String parsing) |
Previous Message | Barry Lind | 2002-05-30 18:03:51 | Re: Doubt more info |