[libpostgresql-jdbc-java] 09/13: Allow updatable ResultSets to update arrays. While we still haven't implemented updateArray, updateObject with an Array should work. Just need to add a mapping for Types.ARRAY for converting the Array to the underlying ResultSet format.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_2_505
in repository libpostgresql-jdbc-java.

commit 500932f3d9e06128b2228fb46770e7c10c686424
Author: Kris Jurka <books at ejurka.com>
Date:   Mon Apr 16 16:36:49 2007 +0000

    Allow updatable ResultSets to update arrays.  While we still haven't
    implemented updateArray, updateObject with an Array should work.
    Just need to add a mapping for Types.ARRAY for converting the Array
    to the underlying ResultSet format.
    
    As reported by vasylenko.
---
 org/postgresql/jdbc2/AbstractJdbc2ResultSet.java   |  3 +-
 .../test/jdbc2/UpdateableResultTest.java           | 35 ++++++++++++++++++++--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 0769624..aeee1bd 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.88 2006/12/01 10:27:05 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.88.2.1 2007/02/19 06:04:48 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -1674,6 +1674,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
                 case Types.NUMERIC:
                 case Types.REAL:
                 case Types.TINYINT:
+		case Types.ARRAY:
                 case Types.OTHER:
                     rowBuffer[columnIndex] = connection.encodeString(String.valueOf( valueObject));
                     break;
diff --git a/org/postgresql/test/jdbc2/UpdateableResultTest.java b/org/postgresql/test/jdbc2/UpdateableResultTest.java
index 43c199e..2b39924 100644
--- a/org/postgresql/test/jdbc2/UpdateableResultTest.java
+++ b/org/postgresql/test/jdbc2/UpdateableResultTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2001-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.22 2005/09/29 22:13:25 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.22.4.1 2007/01/05 00:34:13 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -39,7 +39,7 @@ public class UpdateableResultTest extends TestCase
     protected void setUp() throws Exception
     {
         con = TestUtil.openDB();
-        TestUtil.createTable(con, "updateable", "id int primary key, name text, notselected text, ts timestamp with time zone", true);
+        TestUtil.createTable(con, "updateable", "id int primary key, name text, notselected text, ts timestamp with time zone, intarr int[]", true);
         TestUtil.createTable(con, "second", "id1 int primary key, name1 text");
         TestUtil.createTable(con, "stream", "id int primary key, asi text, chr text, bin bytea");
 
@@ -446,4 +446,35 @@ public class UpdateableResultTest extends TestCase
             fail("Should have thrown an exception on bad column index.");
         } catch (SQLException sqle) { }
     }
+
+    public void testArray() throws SQLException {
+        Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+        stmt.executeUpdate("INSERT INTO updateable (id, intarr) VALUES (1, '{1,2,3}'::int4[])");
+        ResultSet rs = stmt.executeQuery("SELECT id, intarr FROM updateable");
+        assertTrue(rs.next());
+        rs.updateObject(2, rs.getArray(2));
+        rs.updateRow();
+
+        Array arr = rs.getArray(2);
+        assertEquals(Types.INTEGER, arr.getBaseType());
+        int intarr[] = (int[])arr.getArray();
+        assertEquals(3, intarr.length);
+        assertEquals(1, intarr[0]);
+        assertEquals(2, intarr[1]);
+        assertEquals(3, intarr[2]);
+        rs.close();
+
+        rs = stmt.executeQuery("SELECT id,intarr FROM updateable");
+        assertTrue(rs.next());
+        arr = rs.getArray(2);
+        assertEquals(Types.INTEGER, arr.getBaseType());
+        intarr = (int[])arr.getArray();
+        assertEquals(3, intarr.length);
+        assertEquals(1, intarr[0]);
+        assertEquals(2, intarr[1]);
+        assertEquals(3, intarr[2]);
+        
+        rs.close();
+        stmt.close();
+    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list