Patch to add bytea support to JDBC

From: Barry Lind <barry(at)xythos(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Cc: pgsql-jdbc(at)postgresql(dot)org, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Subject: Patch to add bytea support to JDBC
Date: 2001-09-09 07:59:56
Message-ID: 3B9B217C.9070904@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-patches

Attached is a patch to add bytea support to JDBC.

This patch does the following:

- Adds binary datatype support (bytea)
- Changes getXXXStream()/setXXXStream() methods to be spec compliant
- Adds ability to revert to old behavior

Details:

Adds support for the binary type bytea. The ResultSet.getBytes() and
PreparedStatement.setBytes() methods now work against columns of bytea
type. This is a change in behavior from the previous code which assumed
the column type was OID and thus a LargeObject. The new behavior is
more complient with the JDBC spec as BLOB/CLOB are to be used for
LargeObjects and the getBytes()/setBytes() methods are for the databases
binary datatype (which is bytea in postgres).

Changes the behavior of the getBinaryStream(), getAsciiStream(),
getCharacterStream(), getUnicodeStream() and their setXXXStream()
counterparts. These methos now work against either the bytea type
(BinaryStream) or the text types (AsciiStream, CharacterStream,
UnicodeStream). The previous behavior was that these all assumed the
underlying column was of type OID and thus a LargeObject. The
spec/javadoc for these methods indicate that they are for LONGVARCHAR
and LONGVARBINARY datatypes, which are distinct from the BLOB/CLOB
datatypes. Given that the bytea and text types support upto 1G, they
are the LONGVARBINARY and LONGVARCHAR datatypes in postgres.

Added support for turning off the above new functionality. Given that
the changes above are not backwardly compatible (however they are more
spec complient), I added the ability to revert back to the old behavior.
The Connection now takes an optional parameter named 'compatible'. If
the value of '7.1' is passed, the driver reverts to the 7.1 behavior.
If the parameter is not passed or the value '7.2' is passed the behavior
is the new behavior. The mechanism put in place can be used in the
future when/if similar needs arise to change behavior. This is
patterned after how Oracle does this (i.e. Oracle has a 'compatible'
parameter that behaves in a similar manner).

Misc fixes. Cleaned up a few things I encountered along the way.

Note that in testing the patch I needed to ignore whitespace differences
in order to get it to apply cleanly (i.e. patch -l -i byteapatch.diff).

Also this patch introduces a new file
(src/interfaces/jdbc/org/postgresql/util/PGbytea.java).

thanks,
--Barry

PS. In case this patch gets caught in the email list approvals because
it is greater than 40K in size, I have CCed Bruce so that he knows this
is coming before he does the beta builds.

Attachment Content-Type Size
byteapatch.diff text/plain 44.3 KB
PGbytea.java text/plain 2.9 KB

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-09-09 08:10:03 Re: [PATCHES] Fix JDBC test suite, set/get transaction isolation level test in ConnectionTest
Previous Message Rene Pijlman 2001-09-09 07:38:53 Re: getBlob problems with bytea type columns

Browse pgsql-patches by date

  From Date Subject
Next Message Barry Lind 2001-09-09 08:10:03 Re: [PATCHES] Fix JDBC test suite, set/get transaction isolation level test in ConnectionTest
Previous Message Robert B. Easter 2001-09-09 07:21:17 Re: [PATCHES] JDBC patch (attempt#2) for util.Serialize and jdbc2.PreparedStatement