pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Binary transfer patches v15 - sending part was missing
Date: Fri, 23 Sep 2011 20:01:22 +0300
Message-ID: <4E7CBB62.3020909@nitorcreations.com> (raw)
In-Reply-To: <CADK3HHJt_q4wwgRPU-iU48Kj5+VxwPFzeKJbkND08R15ipi2HA@mail.gmail.com>
References: <4E7A63BA.1020505@nitorcreations.com>
	<CADK3HHJt_q4wwgRPU-iU48Kj5+VxwPFzeKJbkND08R15ipi2HA@mail.gmail.com>

On 09/22/2011 03:54 PM, Dave Cramer wrote:
> Mikko,
>
> As this is a development branch I have committed as is so that others
> can easily build and test it. Thanks for the great work!

Hi,

Here's one missing piece of the binary patches - the sending part was accidentally dropped during my quilt patch management exercises.
It passes all unit tests.

And while looking into it I noticed that the previous binary-send patches did not handle correctly the case of pre 8.1 server where the
parameter index needs to be adjusted before binding the prepared statement parameters.

-Mikko

Attachments:

binary-send.patch (text/plain, 3.3K) download --- pgjdbc.orig/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2011-09-23 19:16:53.808785796 +0300 +++ pgjdbc.binsend/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2011-09-23 19:39:59.246929998 +0300 @@ -25,6 +25,7 @@ import org.postgresql.largeobject.*; import org.postgresql.core.*; import org.postgresql.core.types.*; +import org.postgresql.util.ByteConverter; import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLState; import org.postgresql.util.PGobject; @@ -1238,8 +1239,7 @@ */ public void setByte(int parameterIndex, byte x) throws SQLException { - checkClosed(); - bindLiteral(parameterIndex, Integer.toString(x), Oid.INT2); + setShort(parameterIndex, x); } /* @@ -1253,6 +1253,12 @@ public void setShort(int parameterIndex, short x) throws SQLException { checkClosed(); + if (connection.binaryTransferSend(Oid.INT2)) { + byte[] val = new byte[2]; + ByteConverter.int2(val, 0, x); + bindBytes(parameterIndex, val, Oid.INT2); + return; + } bindLiteral(parameterIndex, Integer.toString(x), Oid.INT2); } @@ -1267,6 +1273,12 @@ public void setInt(int parameterIndex, int x) throws SQLException { checkClosed(); + if (connection.binaryTransferSend(Oid.INT4)) { + byte[] val = new byte[4]; + ByteConverter.int4(val, 0, x); + bindBytes(parameterIndex, val, Oid.INT4); + return; + } bindLiteral(parameterIndex, Integer.toString(x), Oid.INT4); } @@ -1281,6 +1293,12 @@ public void setLong(int parameterIndex, long x) throws SQLException { checkClosed(); + if (connection.binaryTransferSend(Oid.INT8)) { + byte[] val = new byte[8]; + ByteConverter.int8(val, 0, x); + bindBytes(parameterIndex, val, Oid.INT8); + return; + } bindLiteral(parameterIndex, Long.toString(x), Oid.INT8); } @@ -1295,6 +1313,12 @@ public void setFloat(int parameterIndex, float x) throws SQLException { checkClosed(); + if (connection.binaryTransferSend(Oid.FLOAT4)) { + byte[] val = new byte[4]; + ByteConverter.float4(val, 0, x); + bindBytes(parameterIndex, val, Oid.FLOAT4); + return; + } bindLiteral(parameterIndex, Float.toString(x), Oid.FLOAT8); } @@ -1309,6 +1333,12 @@ public void setDouble(int parameterIndex, double x) throws SQLException { checkClosed(); + if (connection.binaryTransferSend(Oid.FLOAT8)) { + byte[] val = new byte[8]; + ByteConverter.float8(val, 0, x); + bindBytes(parameterIndex, val, Oid.FLOAT8); + return; + } bindLiteral(parameterIndex, Double.toString(x), Oid.FLOAT8); } @@ -2232,6 +2262,13 @@ preparedParameters.setLiteralParameter(paramIndex, s, oid); } + protected void bindBytes(int paramIndex, byte[] b, int oid) throws SQLException + { + if(adjustIndex) + paramIndex--; + preparedParameters.setBinaryParameter(paramIndex, b, oid); + } + /* * This version is for values that should turn into strings * e.g. setString directly calls bindString with no escaping;

Message-ID: <4E7CBB62.3020909@nitorcreations.com>
Permalink:  ../4E7CBB62.3020909@nitorcreations.com/
Also on:    postgresql.org/message-id/4E7CBB62.3020909@nitorcreations.com

 ·  · 

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@nitorcreations.com, pg@fastcrypt.com
  Subject: Re: Binary transfer patches v15 - sending part was missing
  In-Reply-To: <4E7CBB62.3020909@nitorcreations.com>
  References: <4E7A63BA.1020505@nitorcreations.com> <CADK3HHJt_q4wwgRPU-iU48Kj5+VxwPFzeKJbkND08R15ipi2HA@mail.gmail.com> <4E7CBB62.3020909@nitorcreations.com>

* 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