This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_0_320 in repository libpostgresql-jdbc-java.
commit 7fc23060ec715a364062baa96d220ea9be943cf5 Author: Kris Jurka <[email protected]> Date: Fri Jul 27 22:34:21 2007 +0000 Updatable ResultSets did not work when updating bytea data and then retrieving it because we send the data to the server in binary format, but the ResultSet was expecting to read it in text format. So we need to convert the data from binary to text format before stuffing it into the ResultSet. Mikko Tiihonen --- org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 16 +++++++++- .../test/jdbc2/UpdateableResultTest.java | 36 +++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index 2ba74d7..aac6a2d 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.71.2.8 2006/08/06 18:11:52 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v 1.71.2.9 2007/04/16 16:37:04 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -1730,6 +1730,20 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg // Should never happen? break; + case Types.BINARY: + case Types.LONGVARBINARY: + case Types.VARBINARY: + if (fields[columnIndex].getFormat() == Field.BINARY_FORMAT) { + rowBuffer[columnIndex] = (byte[]) valueObject; + } else { + try { + rowBuffer[columnIndex] = PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "ISO-8859-1"), PSQLState.UNEXPECTED_ERROR, e); + } + } + break; + default: rowBuffer[columnIndex] = (byte[]) valueObject; } diff --git a/org/postgresql/test/jdbc2/UpdateableResultTest.java b/org/postgresql/test/jdbc2/UpdateableResultTest.java index 33d18a4..57de710 100644 --- a/org/postgresql/test/jdbc2/UpdateableResultTest.java +++ b/org/postgresql/test/jdbc2/UpdateableResultTest.java @@ -3,13 +3,15 @@ * Copyright (c) 2001-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.19.2.3 2007/01/05 00:34:28 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v 1.19.2.4 2007/04/16 16:37:04 jurka Exp $ * *------------------------------------------------------------------------- */ package org.postgresql.test.jdbc2; import java.sql.*; +import java.util.Arrays; + import junit.framework.TestCase; import java.io.InputStream; @@ -211,6 +213,9 @@ public class UpdateableResultTest extends TestCase public void testUpdateStreams() throws SQLException, UnsupportedEncodingException { + String string = "Hello"; + byte[] bytes = new byte[]{0,'\\',(byte) 128,(byte) 255}; + Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT id, asi, chr, bin FROM stream"); @@ -221,6 +226,13 @@ public class UpdateableResultTest extends TestCase rs.updateBinaryStream("bin", null, 0); rs.insertRow(); + rs.moveToInsertRow(); + rs.updateInt(1, 3); + rs.updateAsciiStream("asi", new ByteArrayInputStream(string.getBytes("US-ASCII")), 5); + rs.updateCharacterStream("chr", new StringReader(string), 5); + rs.updateBinaryStream("bin", new ByteArrayInputStream(bytes), bytes.length); + rs.insertRow(); + rs.beforeFirst(); rs.next(); @@ -229,29 +241,31 @@ public class UpdateableResultTest extends TestCase assertNull(rs.getString(3)); assertNull(rs.getBytes(4)); - String string = "Hello"; - InputStream asi = new ByteArrayInputStream(string.getBytes("US-ASCII")); - Reader chr = new StringReader(string); - InputStream bin = new ByteArrayInputStream(string.getBytes("US-ASCII")); - rs.updateInt("id", 2); - rs.updateAsciiStream("asi", asi, 5); - rs.updateCharacterStream("chr", chr, 5); - rs.updateBinaryStream("bin", bin, 5); + rs.updateAsciiStream("asi", new ByteArrayInputStream(string.getBytes("US-ASCII")), 5); + rs.updateCharacterStream("chr", new StringReader(string), 5); + rs.updateBinaryStream("bin", new ByteArrayInputStream(bytes), bytes.length); rs.updateRow(); assertEquals(2, rs.getInt(1)); assertEquals(string, rs.getString(2)); assertEquals(string, rs.getString(3)); - assertEquals(string, rs.getString(4)); + assertEquals(Arrays.toString(bytes), Arrays.toString(rs.getBytes(4))); rs.refreshRow(); assertEquals(2, rs.getInt(1)); assertEquals(string, rs.getString(2)); assertEquals(string, rs.getString(3)); - assertEquals(string, rs.getString(4)); + assertEquals(Arrays.toString(bytes), Arrays.toString(rs.getBytes(4))); + + rs.next(); + assertEquals(3, rs.getInt(1)); + assertEquals(string, rs.getString(2)); + assertEquals(string, rs.getString(3)); + assertEquals(Arrays.toString(bytes), Arrays.toString(rs.getBytes(4))); + rs.close(); stmt.close(); } -- 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

