Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CD27DB5DBD1 for ; Fri, 23 Sep 2011 14:01:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 63803-03-2 for ; Fri, 23 Sep 2011 17:01:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from auth-smtp.nebula.fi (auth-smtp.nebula.fi [217.30.180.105]) by mail.postgresql.org (Postfix) with ESMTP id B9DD9B5DC5D for ; Fri, 23 Sep 2011 14:01:29 -0300 (ADT) Received: from quadvadis.localdomain (gw.nitor.fi [83.145.228.24]) (authenticated bits=0) by auth-smtp.nebula.fi (8.13.4/8.13.4) with ESMTP id p8NH1KI4024668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 23 Sep 2011 20:01:21 +0300 Message-ID: <4E7CBB62.3020909@nitorcreations.com> Date: Fri, 23 Sep 2011 20:01:22 +0300 From: Mikko Tiihonen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: Dave Cramer CC: pgsql-jdbc@postgresql.org Subject: Re: Binary transfer patches v15 - sending part was missing References: <4E7A63BA.1020505@nitorcreations.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------090704010106060401090901" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/98 X-Sequence-Number: 22216 This is a multi-part message in MIME format. --------------090704010106060401090901 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090704010106060401090901 Content-Type: text/plain; name="binary-send.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="binary-send.patch" --- 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; --------------090704010106060401090901--