[libpostgresql-jdbc-java] 03/07: Map setObject calls for Types.BLOB, CLOB, and ARRAY to call the related setXXX method if we don't need to do any conversion.

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


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

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

commit b1b9a4a74c3048cec0cdc0c2823996b60cefea6a
Author: Kris Jurka <books at ejurka.com>
Date:   Thu Sep 29 20:40:29 2005 +0000

    Map setObject calls for Types.BLOB, CLOB, and ARRAY to call the
    related setXXX method if we don't need to do any conversion.
    
    Reported by Marc Herbert.
---
 org/postgresql/jdbc2/AbstractJdbc2Statement.java | 20 ++++++++++++++-
 org/postgresql/test/jdbc2/ArrayTest.java         |  5 +++-
 org/postgresql/test/jdbc2/BlobTest.java          | 31 +++++++++++++++++++++++-
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 04847f1..66344cc 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.7 2005/06/08 16:21:01 davec Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.8 2005/08/12 18:22:30 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -1623,6 +1623,24 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         case Types.LONGVARBINARY:
             setObject(parameterIndex, x);
             break;
+        case Types.BLOB:
+            if (x instanceof Blob)
+                setBlob(parameterIndex, (Blob)x);
+            else
+                throw new PSQLException(GT.tr("Cannot cast an instance of {0} to type {1}", new Object[]{x.getClass().getName(),"Types.BLOB"}), PSQLState.INVALID_PARAMETER_TYPE);
+            break;
+        case Types.CLOB:
+            if (x instanceof Clob)
+                setClob(parameterIndex, (Clob)x);
+            else
+                throw new PSQLException(GT.tr("Cannot cast an instance of {0} to type {1}", new Object[]{x.getClass().getName(),"Types.CLOB"}), PSQLState.INVALID_PARAMETER_TYPE);
+            break;
+        case Types.ARRAY:
+            if (x instanceof Array)
+                setArray(parameterIndex, (Array)x);
+            else
+                throw new PSQLException(GT.tr("Cannot cast an instance of {0} to type {1}", new Object[]{x.getClass().getName(),"Types.ARRAY"}), PSQLState.INVALID_PARAMETER_TYPE);
+            break;
         case Types.OTHER:
             if (x instanceof PGobject)
                 setPGobject(parameterIndex, (PGobject)x);
diff --git a/org/postgresql/test/jdbc2/ArrayTest.java b/org/postgresql/test/jdbc2/ArrayTest.java
index 14d8455..9303e8b 100644
--- a/org/postgresql/test/jdbc2/ArrayTest.java
+++ b/org/postgresql/test/jdbc2/ArrayTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ArrayTest.java,v 1.8 2005/01/11 08:25:48 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ArrayTest.java,v 1.8.2.1 2005/04/28 14:18:09 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -157,6 +157,9 @@ public class ArrayTest extends TestCase
         PreparedStatement pstmt = conn.prepareStatement("INSERT INTO arrtest(intarr) VALUES (?)");
         pstmt.setArray(1, arr);
         pstmt.executeUpdate();
+
+        pstmt.setObject(1, arr, Types.ARRAY);
+        pstmt.executeUpdate();
         pstmt.close();
 
         Statement select = conn.createStatement();
diff --git a/org/postgresql/test/jdbc2/BlobTest.java b/org/postgresql/test/jdbc2/BlobTest.java
index 7cb80c2..682cb2d 100644
--- a/org/postgresql/test/jdbc2/BlobTest.java
+++ b/org/postgresql/test/jdbc2/BlobTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/BlobTest.java,v 1.14.2.1 2005/04/28 14:18:09 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/BlobTest.java,v 1.14.2.2 2005/05/08 23:17:48 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -70,6 +70,35 @@ public class BlobTest extends TestCase
         pstmt.setObject(1, null, Types.CLOB);
         pstmt.executeUpdate();
     }
+    
+    public void testSet() throws SQLException {
+        Statement stmt = con.createStatement();
+        stmt.execute("INSERT INTO testblob(id,lo) VALUES ('1', lo_creat(-1))");
+        ResultSet rs = stmt.executeQuery("SELECT lo FROM testblob");
+        assertTrue(rs.next());
+
+        PreparedStatement pstmt = con.prepareStatement("INSERT INTO testblob(id, lo) VALUES(?,?)");
+
+        Blob blob = rs.getBlob(1);
+        pstmt.setString(1,"2");
+        pstmt.setObject(2, blob, Types.BLOB);
+        assertEquals(1, pstmt.executeUpdate());
+
+        blob = rs.getBlob(1);
+        pstmt.setString(1,"3");
+        pstmt.setBlob(2, blob);
+        assertEquals(1, pstmt.executeUpdate());
+
+        Clob clob = rs.getClob(1);
+        pstmt.setString(1,"4");
+        pstmt.setObject(2, clob, Types.CLOB);
+        assertEquals(1, pstmt.executeUpdate());
+
+        clob = rs.getClob(1);
+        pstmt.setString(1,"5");
+        pstmt.setClob(2, clob);
+        assertEquals(1, pstmt.executeUpdate());
+    }
 
     /*
      * Tests one method of uploading a blob to the database

-- 
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