From: | Barry Lind <barry(at)xythos(dot)com> |
---|---|
To: | Noel Rappin <nrappin(at)sockeye(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Issues with Array Interface |
Date: | 2002-05-31 15:48:51 |
Message-ID: | 3CF79B63.1050704@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Noel,
Yes that certainly looks like the problem. If you can confirm that this
fixes the issue I will commit this fix to CVS.
thanks,
--Barry
Noel Rappin wrote:
> 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
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
From | Date | Subject | |
---|---|---|---|
Next Message | Barry Lind | 2002-05-31 15:50:46 | Re: Issues with Array interface (String parsing) |
Previous Message | Noel Rappin | 2002-05-31 15:07:49 | Re: Issues with Array Interface |