Re: AbstractJdbc2Array - another patch

Поиск
Список
Период
Сортировка
От Kris Jurka
Тема Re: AbstractJdbc2Array - another patch
Дата
Msg-id 4717A074.4000109@ejurka.com
обсуждение исходный текст
Ответ на AbstractJdbc2Array - another patch  (Marek Lewczuk <newsy@lewczuk.com>)
Ответы Re: AbstractJdbc2Array - another patch  (Marek Lewczuk <newsy@lewczuk.com>)
Список pgsql-jdbc
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.


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();
    }
}


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Mark Lewis
Дата:
Сообщение: Re: Fw: postgresql experts please help
Следующее
От: "Andrei Ilitchev"
Дата:
Сообщение: Re: Fw: postgresql experts please help