Thread: Issues with Array interface?
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
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 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html > >
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 >> >>
Hi, I am using ResultSet.getArray() to retrieve a string array from the db. And I am getting incorrect values for cases where the array elements contain quote or backslash characters. Looked at the source code for Array and it doesn't seem to account for escaped quote and backslash characters. Is there a known patch or a workaround for this particular problem? Thanks in advance, Anshul __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com
Anshul, There isn't any known patch or workaround that I am aware of. You are the first person to report this problem. A patch would be gladly accepted. thanks, --Barry d a wrote: > Hi, > > I am using ResultSet.getArray() to retrieve a string > array from the db. And I am getting incorrect values > for cases where the array elements contain quote or > backslash characters. > > Looked at the source code for Array and it doesn't > seem to account for escaped quote and backslash > characters. > > Is there a known patch or a workaround for this > particular problem? > > Thanks in advance, > Anshul > > __________________________________________________ > Do You Yahoo!? > Yahoo! - Official partner of 2002 FIFA World Cup > http://fifaworldcup.yahoo.com > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >
This is now fixed in current sources. --Barry d a wrote: >Hi, > >I am using ResultSet.getArray() to retrieve a string >array from the db. And I am getting incorrect values >for cases where the array elements contain quote or >backslash characters. > >Looked at the source code for Array and it doesn't >seem to account for escaped quote and backslash >characters. > >Is there a known patch or a workaround for this >particular problem? > >Thanks in advance, >Anshul > >__________________________________________________ >Do You Yahoo!? >Yahoo! - Official partner of 2002 FIFA World Cup >http://fifaworldcup.yahoo.com > >---------------------------(end of broadcast)--------------------------- >TIP 3: if posting/reading through Usenet, please send an appropriate >subscribe-nomail command to majordomo@postgresql.org so that your >message can get through to the mailing list cleanly > > >