Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 97D799FB3D5 for ; Thu, 18 Oct 2007 15:24:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 20094-08 for ; Thu, 18 Oct 2007 15:24:46 -0300 (ADT) X-Greylist: delayed 00:18:52.043031 by SQLgrey-1.7.5 Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with ESMTP id 968C49FB2DB for ; Thu, 18 Oct 2007 15:24:47 -0300 (ADT) Received: from [192.168.7.181] (71-208-189-82.hlrn.qwest.net [71.208.189.82]) (using SSLv3 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail63.csoft.net (Postfix) with ESMTP id 1486729F12; Thu, 18 Oct 2007 14:05:40 -0400 (EDT) Message-ID: <4717A074.4000109@ejurka.com> Date: Thu, 18 Oct 2007 12:05:40 -0600 From: Kris Jurka User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Marek Lewczuk CC: pgsql-jdbc Subject: Re: AbstractJdbc2Array - another patch References: <470DE5E7.2090807@lewczuk.com> <47172FF2.6070203@lewczuk.com> In-Reply-To: <47172FF2.6070203@lewczuk.com> Content-Type: multipart/mixed; boundary="------------010501080405050200060400" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/102 X-Sequence-Number: 17674 This is a multi-part message in MIME format. --------------010501080405050200060400 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------010501080405050200060400 Content-Type: text/java; name="ArrayTest.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ArrayTest.java" 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(); } } --------------010501080405050200060400--