[libpostgresql-jdbc-java] 03/11: Make updatable ResultSets work with SQLXML data. Avoid making the update code know about target types unless it needs to do some special processing for it.

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


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

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

commit 6c1c7e7747c536caa9b32032d13e794cf7c538c7
Author: Kris Jurka <books at ejurka.com>
Date:   Sat Oct 23 06:18:13 2010 +0000

    Make updatable ResultSets work with SQLXML data.  Avoid making the
    update code know about target types unless it needs to do some
    special processing for it.
    
    Reported by Michael Musset
---
 org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 22 +++-------------
 org/postgresql/test/jdbc4/XmlTest.java           | 33 +++++++++++++++++-------
 2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 9d11982..15eadda 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.107 2009/04/19 16:11:48 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.108 2009/11/19 00:51:26 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -1670,23 +1670,6 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
                 switch ( getSQLType(columnIndex + 1) )
                 {
 
-                case Types.DECIMAL:
-                case Types.BIGINT:
-                case Types.DOUBLE:
-                case Types.BIT:
-                case Types.VARCHAR:
-                case Types.SMALLINT:
-                case Types.FLOAT:
-                case Types.INTEGER:
-                case Types.CHAR:
-                case Types.NUMERIC:
-                case Types.REAL:
-                case Types.TINYINT:
-                case Types.ARRAY:
-                case Types.OTHER:
-                    rowBuffer[columnIndex] = connection.encodeString(String.valueOf( valueObject));
-                    break;
-
                 //
                 // toString() isn't enough for date and time types; we must format it correctly
                 // or we won't be able to re-parse it.
@@ -1726,7 +1709,8 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
                     break;
  
                 default:
-                    rowBuffer[columnIndex] = (byte[]) valueObject;
+                    rowBuffer[columnIndex] = connection.encodeString(String.valueOf( valueObject));
+                    break;
                 }
 
             }
diff --git a/org/postgresql/test/jdbc4/XmlTest.java b/org/postgresql/test/jdbc4/XmlTest.java
index ee52429..fcef311 100644
--- a/org/postgresql/test/jdbc4/XmlTest.java
+++ b/org/postgresql/test/jdbc4/XmlTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL$
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc4/XmlTest.java,v 1.1 2008/10/08 18:24:05 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -62,9 +62,9 @@ public class XmlTest extends TestCase {
     protected void setUp() throws Exception {
         _conn = TestUtil.openDB();
         Statement stmt = _conn.createStatement();
-        stmt.execute("CREATE TEMP TABLE xmltest(val xml)");
-        stmt.execute("INSERT INTO xmltest VALUES ('" + _xmlDocument + "')");
-        stmt.execute("INSERT INTO xmltest VALUES ('" + _xmlFragment + "')");
+        stmt.execute("CREATE TEMP TABLE xmltest(id int primary key, val xml)");
+        stmt.execute("INSERT INTO xmltest VALUES (1, '" + _xmlDocument + "')");
+        stmt.execute("INSERT INTO xmltest VALUES (2, '" + _xmlFragment + "')");
         stmt.close();
     }
 
@@ -80,6 +80,15 @@ public class XmlTest extends TestCase {
         return stmt.executeQuery("SELECT val FROM xmltest");
     }
 
+    public void testUpdateRS() throws SQLException {
+        Statement stmt = _conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = stmt.executeQuery("SELECT id, val FROM xmltest");
+        assertTrue(rs.next());
+        SQLXML xml = rs.getSQLXML(2);
+        rs.updateSQLXML(2, xml);
+        rs.updateRow();
+    }
+
     public void testDOMParse() throws SQLException {
         ResultSet rs = getRS();
 
@@ -156,14 +165,15 @@ public class XmlTest extends TestCase {
         stmt.execute("DELETE FROM xmltest");
         stmt.close();
 
-        PreparedStatement ps = _conn.prepareStatement("INSERT INTO xmltest VALUES (?)");
+        PreparedStatement ps = _conn.prepareStatement("INSERT INTO xmltest VALUES (?,?)");
         SQLXML xml = _conn.createSQLXML();
         Result result = xml.setResult(resultClass);
 
         Source source = new StreamSource(new StringReader(_xmlDocument));
         _identityTransformer.transform(source, result);
 
-        ps.setSQLXML(1, xml);
+	ps.setInt(1, 1);
+        ps.setSQLXML(2, xml);
         ps.executeUpdate();
         ps.close();
 
@@ -230,14 +240,17 @@ public class XmlTest extends TestCase {
         stmt.execute("DELETE FROM xmltest");
         stmt.close();
 
-        PreparedStatement ps = _conn.prepareStatement("INSERT INTO xmltest VALUES (?)");
-        ps.setNull(1, Types.SQLXML);
+        PreparedStatement ps = _conn.prepareStatement("INSERT INTO xmltest VALUES (?,?)");
+	ps.setInt(1, 1);
+        ps.setNull(2, Types.SQLXML);
         ps.executeUpdate();
-        ps.setObject(1, null, Types.SQLXML);
+	ps.setInt(1, 2);
+        ps.setObject(2, null, Types.SQLXML);
         ps.executeUpdate();
         SQLXML xml = _conn.createSQLXML();
         xml.setString(null);
-        ps.setObject(1, xml);
+	ps.setInt(1, 3);
+        ps.setObject(2, xml);
         ps.executeUpdate();
         ps.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