From: Kris Jurka <books@ejurka.com>
To: Marek Lewczuk <newsy@lewczuk.com>
Cc: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Re: AbstractJdbc2Array - another patch
Date: Thu, 18 Oct 2007 12:05:40 -0600
Message-ID: <4717A074.4000109@ejurka.com> (raw)
In-Reply-To: <47172FF2.6070203@lewczuk.com>
References: <470DE5E7.2090807@lewczuk.com>
<Pine.BSO.4.64.0710180401490.16749@leary.csoft.net>
<47172FF2.6070203@lewczuk.com>
Marek Lewczuk wrote:
>
>> 3) When determing if NULL in an array string is a null value, you need
>> to check the server version. Prior to 8.2 an unadorned NULL is the
>> text "null", not an actual null value.
> See line 106 (of the attached AbstractJdbc2Array.java) - I'm checking,
> whether Object[] should be used instead of primitive arrays. It also
> used to check, whether NULL elements can be used. Now, see line 230/231
> - at this point, I'm checking, whether element is a text "NULL" or null
> element - it works just fine.
Perhaps that's OK. If you asked for primitive types on an int[] array
with a NULL value, you could want zero instead of an error trying to
convert the String "NULL" to an int, similar to rs.getInt() on a NULL
value. Let's leave this for now and work on fixing/writing new tests
and #6 and we can revisit this later.
>> 4) Shouldn't toString(PgArrayList) be PgArrayList.toString() ?
> It could be, but see line 598 (of the attached AbstractJdbc2Array.java)
> - I'm using escapeString, that throws SQLException and I cannot declare
> PgArrayList.toString() as throwing SQLException (super class declaration
> doesn't allow for that) - I could of course catch SQLException but it
> think it is better to stay with current implementation.
You're right, it's fine.
>> 6) I was unable to recursively retrieve multidimensional arrays as
>> ResultSets as I thought I should be able to do (in the attached test).
>> Shouldn't you retain an array as the base type for the top level of a
>> multi-dimensional array and expose a dimension at a time via each
>> ResultSet?
> You have made a mistake, please try attached ArrayTest.
Doh! OK, now it mostly works, but there's still an issue with setting
the basetype on a subarray to the base element type instead of an array
type, as attached. rs.getObject() (and metadata) are confused about
what the correct type is.
Attachments:ArrayTest.java (text/java, 1.1K) download
import java.sql.*;
public class ArrayTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka","jurka","");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT '{{1,2,3},{4,5,6}}'::int[]");
rs.next();
Array arr = rs.getArray(1);
System.out.println(arr.getBaseType());
System.out.println(arr.getBaseTypeName());
ResultSet arrRS = arr.getResultSet();
arrRS.next();
System.out.println(arrRS.getString(2));
Object o1 = arrRS.getObject(2);
System.out.println(o1);
Array a1 = arrRS.getArray(2);
ResultSet rs1 = a1.getResultSet();
while (rs1.next()) {
System.out.println(rs1.getInt(1));
}
rs1.close();
arrRS.next();
System.out.println(arrRS.getString(2));
Array a2 = arrRS.getArray(2);
System.out.println(a2.getBaseTypeName());
System.out.println(a2.getBaseType());
ResultSet rs2 = a2.getResultSet();
while (rs2.next()) {
System.out.println(rs2.getInt(1));
}
rs2.close();
arrRS.close();
rs.close();
stmt.close();
conn.close();
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, newsy@lewczuk.com
Subject: Re: AbstractJdbc2Array - another patch
In-Reply-To: <4717A074.4000109@ejurka.com>
References: <470DE5E7.2090807@lewczuk.com> <Pine.BSO.4.64.0710180401490.16749@leary.csoft.net> <47172FF2.6070203@lewczuk.com> <4717A074.4000109@ejurka.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox