This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_0_312 in repository libpostgresql-jdbc-java.
commit 001c78f6a112289f5eca4edbe9072efeb28956f8 Author: Kris Jurka <[email protected]> Date: Thu Apr 28 14:18:09 2005 +0000 Improve null handling. Allow setNull(1, Types.XXX) for ARRAY, NULL, DISTINCT, and STRUCT by mapping them to the unknown oid. Make setArray, setBlob, setClob, and setCharacterStream accept null parameters. --- org/postgresql/jdbc2/AbstractJdbc2Statement.java | 44 +++++++++++++++++++++--- org/postgresql/test/jdbc2/ArrayTest.java | 23 ++++++++++++- org/postgresql/test/jdbc2/BlobTest.java | 25 +++++++++++++- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java index af0c648..50a3a33 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.3 2005/02/15 09:09:31 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.4 2005/02/16 18:30:27 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -996,10 +996,14 @@ public abstract class AbstractJdbc2Statement implements BaseStatement oid = Oid.OID; } break; - case Types.BLOB: - case Types.CLOB: - oid = Oid.OID; - break; + case Types.BLOB: + case Types.CLOB: + oid = Oid.OID; + break; + case Types.ARRAY: + case Types.DISTINCT: + case Types.STRUCT: + case Types.NULL: case Types.OTHER: oid = Oid.INVALID; break; @@ -2558,6 +2562,12 @@ public abstract class AbstractJdbc2Statement implements BaseStatement { checkClosed(); + if (null == x) + { + setNull(i, Types.ARRAY); + return; + } + // This only works for Array implementations that return a valid array // literal from Array.toString(), such as the implementation we return // from ResultSet.getArray(). Eventually we need a proper implementation @@ -2576,6 +2586,13 @@ public abstract class AbstractJdbc2Statement implements BaseStatement public void setBlob(int i, Blob x) throws SQLException { checkClosed(); + + if (x == null) + { + setNull(i, Types.BLOB); + return; + } + InputStream l_inStream = x.getBinaryStream(); LargeObjectManager lom = connection.getLargeObjectAPI(); int oid = lom.create(); @@ -2620,6 +2637,16 @@ public abstract class AbstractJdbc2Statement implements BaseStatement public void setCharacterStream(int i, java.io.Reader x, int length) throws SQLException { checkClosed(); + + if (x == null) { + if (connection.haveMinimumServerVersion("7.2")) { + setNull(i, Types.VARCHAR); + } else { + setNull(i, Types.CLOB); + } + return; + } + if (length < 0) throw new PSQLException(GT.tr("Invalid stream length {0}.", new Integer(length)), PSQLState.INVALID_PARAMETER_VALUE); @@ -2690,6 +2717,13 @@ public abstract class AbstractJdbc2Statement implements BaseStatement public void setClob(int i, Clob x) throws SQLException { checkClosed(); + + if (x == null) + { + setNull(i, Types.CLOB); + return; + } + InputStream l_inStream = x.getAsciiStream(); int l_length = (int) x.length(); LargeObjectManager lom = connection.getLargeObjectAPI(); diff --git a/org/postgresql/test/jdbc2/ArrayTest.java b/org/postgresql/test/jdbc2/ArrayTest.java index 1346dfb..14d8455 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.7 2004/11/09 08:54:00 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ArrayTest.java,v 1.8 2005/01/11 08:25:48 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -37,6 +37,27 @@ public class ArrayTest extends TestCase TestUtil.closeDB(conn); } + public void testSetNull() throws SQLException { + PreparedStatement pstmt = conn.prepareStatement("INSERT INTO arrtest VALUES (?,?,?)"); + pstmt.setNull(1, Types.ARRAY); + pstmt.setNull(2, Types.ARRAY); + pstmt.setNull(3, Types.ARRAY); + pstmt.executeUpdate(); + + pstmt.setObject(1, null, Types.ARRAY); + pstmt.setObject(2, null); + pstmt.setObject(3, null); + pstmt.executeUpdate(); + + pstmt.setArray(1, null); + pstmt.setArray(2, null); + pstmt.setArray(3, null); + pstmt.executeUpdate(); + + pstmt.close(); + } + + public void testRetrieveArrays() throws SQLException { Statement stmt = conn.createStatement(); diff --git a/org/postgresql/test/jdbc2/BlobTest.java b/org/postgresql/test/jdbc2/BlobTest.java index 23df1b1..cc9ab4c 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.13 2004/11/09 08:54:01 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/BlobTest.java,v 1.14 2005/01/11 08:25:48 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -47,6 +47,29 @@ public class BlobTest extends TestCase TestUtil.closeDB(con); } + public void testSetNull() throws Exception + { + PreparedStatement pstmt = con.prepareStatement("INSERT INTO testblob(lo) VALUES (?)"); + + pstmt.setBlob(1, null); + pstmt.executeUpdate(); + + pstmt.setNull(1, Types.BLOB); + pstmt.executeUpdate(); + + pstmt.setObject(1, null, Types.BLOB); + pstmt.executeUpdate(); + + pstmt.setClob(1, null); + pstmt.executeUpdate(); + + pstmt.setNull(1, Types.CLOB); + pstmt.executeUpdate(); + + pstmt.setObject(1, null, Types.CLOB); + 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 _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

