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

commit    18bab6a44e5ca2d1673a67bcb066e867fe8bceaf
Author:   Dave Cramer <dave.cramer@credativ.ca>
Date:     Thu Sep 13 11:43:40 2012 +0000

    added explicit test case for array handling from Craig Ringer


org/postgresql/test/jdbc2/ArrayTest.java | 31 ++++++++++++++++++++++ .../test/jdbc3/SendRecvBufferSizeTest.java | 3 +++ 2 files changed, 34 insertions(+) diff --git a/org/postgresql/test/jdbc2/ArrayTest.java b/org/postgresql/test/jdbc2/ArrayTest.java index 16b08230..7b796be6 100644 --- a/org/postgresql/test/jdbc2/ArrayTest.java +++ b/org/postgresql/test/jdbc2/ArrayTest.java @@ -186,6 +186,37 @@ public class ArrayTest extends TestCase assertEquals(3, resultCount); } + public void testSetObjectFromJavaArray() throws SQLException { + String[] strArray = new String[]{"a","b","c"}; + + PreparedStatement pstmt = conn.prepareStatement("INSERT INTO arrtest(strarr) VALUES (?)"); + + // Incorrect, but commonly attempted by many ORMs: + try { + pstmt.setObject(1, strArray, Types.ARRAY); + pstmt.executeUpdate(); + fail("setObject() with a Java array parameter and Types.ARRAY shouldn't succeed"); + } catch (org.postgresql.util.PSQLException ex) { + // Expected failure. + } + + // Also incorrect, but commonly attempted by many ORMs: + try { + pstmt.setObject(1, strArray); + pstmt.executeUpdate(); + fail("setObject() with a Java array parameter and no Types argument shouldn't succeed"); + } catch (org.postgresql.util.PSQLException ex) { + // Expected failure. + } + + // Correct way, though the use of "text" as a type is non-portable. + Array sqlArray = conn.createArrayOf("text", strArray); + pstmt.setArray(1, sqlArray); + pstmt.executeUpdate(); + + pstmt.close(); + } + /** * Starting with 8.0 non-standard (beginning index isn't 1) bounds * the dimensions are returned in the data. The following should diff --git a/org/postgresql/test/jdbc3/SendRecvBufferSizeTest.java b/org/postgresql/test/jdbc3/SendRecvBufferSizeTest.java index 54c51a5a..80d49ac4 100644 --- a/org/postgresql/test/jdbc3/SendRecvBufferSizeTest.java +++ b/org/postgresql/test/jdbc3/SendRecvBufferSizeTest.java @@ -9,6 +9,8 @@ package org.postgresql.test.jdbc3; import java.sql.*; import junit.framework.TestCase; + +import org.postgresql.jdbc2.AbstractJdbc2Connection; import org.postgresql.test.TestUtil; public class SendRecvBufferSizeTest extends TestCase { @@ -38,6 +40,7 @@ public class SendRecvBufferSizeTest extends TestCase { TestUtil.closeDB(_conn); } + // dummy test public void testSelect() throws SQLException { Statement stmt = _conn.createStatement(); [parent: b61e845a3bbc]