Re: Issues with Array Interface - Mailing list pgsql-jdbc
From | Dave Cramer |
---|---|
Subject | Re: Issues with Array Interface |
Date | |
Msg-id | 1022861956.1427.134.camel@inspiron.cramers Whole thread Raw |
In response to | Re: Issues with Array Interface (Noel Rappin <nrappin@sockeye.com>) |
List | pgsql-jdbc |
Noel, This is great, can you do a send a context diff into the list. You can produce this using cvs, or diff. for diff it is diff -c file1 file2 >patchfile for cvs it is cvs diff -c file >patchfile then send the patchfile Dave On Fri, 2002-05-31 at 11:07, Noel Rappin wrote: > After compiling and testing, this does appear to fix the problem. What > needs to be done to make the patch? > > Noel > > 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 > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html > >
pgsql-jdbc by date: