pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Mikko Tiihonen <mikko.tiihonen@iki.fi>
To: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Fix resultset results after updateBinaryStream
Date: Sat, 21 Jul 2007 02:02:24 +0300
Message-ID: <1184972544.1632.55.camel@dual.local> (raw )
Hi,
The current UpdateableResultSet tests did not properly test more complex binary data updating.
The following patch makes the test a bit harder and fixes the driver to pass the test.
inline patch 1: org/postgresql/test/jdbc2/UpdateableResultTest.java, org/postgresql/jdbc2/AbstractJdbc2ResultSet.java (+16/-4 lines) download inline-1.patch Index: org/postgresql/test/jdbc2/UpdateableResultTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java,v
retrieving revision 1.24
diff -u -r1.24 UpdateableResultTest.java
--- org/postgresql/test/jdbc2/UpdateableResultTest.java 16 Apr 2007 16:36:41 -0000 1.24
+++ org/postgresql/test/jdbc2/UpdateableResultTest.java 20 Jul 2007 22:28:21 -0000
@@ -10,6 +10,8 @@
package org.postgresql.test.jdbc2;
import java.sql.*;
+import java.util.Arrays;
+
import junit.framework.TestCase;
import java.io.InputStream;
@@ -238,25 +240,26 @@
String string = "Hello";
InputStream asi = new ByteArrayInputStream(string.getBytes("US-ASCII"));
Reader chr = new StringReader(string);
- InputStream bin = new ByteArrayInputStream(string.getBytes("US-ASCII"));
+ byte[] bytes = new byte[]{0,'\\',(byte) 128,(byte) 255};
+ InputStream bin = new ByteArrayInputStream(bytes);
rs.updateInt("id", 2);
rs.updateAsciiStream("asi", asi, 5);
rs.updateCharacterStream("chr", chr, 5);
- rs.updateBinaryStream("bin", bin, 5);
+ rs.updateBinaryStream("bin", bin, 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("Got wrong bytes immediately after update", 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("Got wrong bytes from database", Arrays.toString(bytes), Arrays.toString(rs.getBytes(4)));
rs.close();
stmt.close();
Index: org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.94
diff -u -r1.94 AbstractJdbc2ResultSet.java
--- org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 16 Apr 2007 16:36:41 -0000 1.94
+++ org/postgresql/jdbc2/AbstractJdbc2ResultSet.java 20 Jul 2007 22:28:21 -0000
@@ -1205,6 +1205,7 @@
if ( rs.next() )
{
+ System.arraycopy(rs.fields, 0, fields, 0, numColumns);
rowBuffer = rs.rowBuffer;
}
@@ -1657,6 +1658,7 @@
{
String columnName = (String) columns.next();
int columnIndex = findColumn( columnName ) - 1;
+ fields[columnIndex].setFormat(Field.TEXT_FORMAT);
Object valueObject = updateValues.get(columnName);
if (valueObject instanceof NullObject)
@@ -1709,6 +1711,13 @@
// Should never happen?
break;
+ case Types.BINARY:
+ case Types.LONGVARBINARY:
+ case Types.VARBINARY:
+ fields[columnIndex].setFormat(Field.BINARY_FORMAT);
+ rowBuffer[columnIndex] = (byte[]) valueObject;
+ break;
+
default:
rowBuffer[columnIndex] = (byte[]) valueObject;
}
view thread (4+ messages) latest in thread
Message-ID: <1184972544.1632.55.camel@dual.local>
Permalink: ../1184972544.1632.55.camel@dual.local/
Also on: postgresql.org/message-id/1184972544.1632.55.camel@dual.local
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mikko.tiihonen@iki.fi
Subject: Re: Fix resultset results after updateBinaryStream
In-Reply-To: <1184972544.1632.55.camel@dual.local>
References: <1184972544.1632.55.camel@dual.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox