postgresql-jdbc.git / summary / log / commit / refs

commit    a655e0ffa23495fa7ddefdea065b75d0fba2b98d
Author:   Kris Jurka <books@ejurka.com>
Date:     Wed Jan 05 00:54:48 2005 +0000

    Implement CallableStatement.getArray.


org/postgresql/jdbc2/AbstractJdbc2Statement.java | 6 ++++-- org/postgresql/test/jdbc2/CallableStmtTest.java | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java index f8823535..fc2a4574 100644 --- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java +++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java @@ -3,7 +3,7 @@ * Copyright (c) 2004, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.57 2004/12/22 23:34:15 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.58 2004/12/22 23:55:51 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -2720,7 +2720,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement public java.sql.Array getArray(int i) throws SQLException { - throw Driver.notImplemented(); + checkClosed(); + checkIndex(i, Types.ARRAY, "Array"); + return (Array)callResult; } public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException diff --git a/org/postgresql/test/jdbc2/CallableStmtTest.java b/org/postgresql/test/jdbc2/CallableStmtTest.java index e979cf92..2cb87d80 100644 --- a/org/postgresql/test/jdbc2/CallableStmtTest.java +++ b/org/postgresql/test/jdbc2/CallableStmtTest.java @@ -3,18 +3,14 @@ * Copyright (c) 2004, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CallableStmtTest.java,v 1.9 2004/12/14 06:23:40 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CallableStmtTest.java,v 1.10 2004/12/14 06:28:32 jurka Exp $ * *------------------------------------------------------------------------- */ package org.postgresql.test.jdbc2; import org.postgresql.test.TestUtil; -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; +import java.sql.*; import junit.framework.TestCase; @@ -50,6 +46,7 @@ public class CallableStmtTest extends TestCase stmt.execute ("CREATE OR REPLACE FUNCTION testspg__getNumericWithoutArg() " + "RETURNS numeric AS ' " + "begin return 42; end; ' LANGUAGE 'plpgsql';"); + stmt.execute("CREATE OR REPLACE FUNCTION getarray() RETURNS int[] as 'SELECT ''{1,2}''::int[];' LANGUAGE 'sql'"); stmt.close (); } @@ -61,6 +58,7 @@ public class CallableStmtTest extends TestCase stmt.execute ("drop FUNCTION testspg__getInt (int);"); stmt.execute ("drop FUNCTION testspg__getNumeric (numeric);"); stmt.execute ("drop FUNCTION testspg__getNumericWithoutArg ();"); + stmt.execute ("DROP FUNCTION getarray();"); TestUtil.closeDB(con); } @@ -116,6 +114,20 @@ public class CallableStmtTest extends TestCase } + public void testGetArray() throws SQLException + { + CallableStatement call = con.prepareCall("{ ? = call getarray()}"); + call.registerOutParameter(1, Types.ARRAY); + call.execute(); + Array arr = call.getArray(1); + ResultSet rs = arr.getResultSet(); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(2, rs.getInt(1)); + assertTrue(!rs.next()); + } + public void testBadStmt () throws Throwable { tryOneBadStmt ("{ ?= " + pkgName + "getString (?) }"); [parent: 5f544d49d3f8]