Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 80432632DDC for ; Wed, 5 Aug 2009 10:03:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77647-01 for ; Wed, 5 Aug 2009 13:03:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp21.orange.fr (smtp21.orange.fr [80.12.242.49]) by mail.postgresql.org (Postfix) with ESMTP id B690E6326E5 for ; Wed, 5 Aug 2009 10:03:38 -0300 (ADT) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2123.orange.fr (SMTP Server) with ESMTP id 276E11C00089 for ; Wed, 5 Aug 2009 15:03:36 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2123.orange.fr (SMTP Server) with ESMTP id 19CA61C0008E for ; Wed, 5 Aug 2009 15:03:36 +0200 (CEST) Received: from [10.129.36.10] (Mix-Rennes201-1-83.w193-250.abo.wanadoo.fr [193.250.26.83]) by mwinf2123.orange.fr (SMTP Server) with ESMTP id 14E111C00089 for ; Wed, 5 Aug 2009 15:03:35 +0200 (CEST) X-ME-UUID: 20090805130335856.14E111C00089@mwinf2123.orange.fr Message-ID: <4A798325.4030607@wanadoo.fr> Date: Wed, 05 Aug 2009 15:03:33 +0200 From: Sylvain Leroux Organization: http://www.chicoree.fr User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject References: <4A79587F.6010603@wanadoo.fr> <4A79694F.9060404@opencloud.com> In-Reply-To: <4A79694F.9060404@opencloud.com> Content-Type: multipart/mixed; boundary="------------040704070403040300010805" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/9 X-Sequence-Number: 19858 This is a multi-part message in MIME format. --------------040704070403040300010805 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hi, and first of all, thanks for your answer. Oliver Jowett a écrit : > Why NUMERIC instead of an integer type? > > Might as well make setBigInteger() private if you're not also going to > expose it on PGStatement (I don't think it needs to be exposed there) According to the JDK doc, java.math.BigInteger provides "arbitrary-precision integers". The closest match will be NUMERIC since it allows up to 1000 digits. As far as I know, the integer types have much narrower range. *Or* could it be required to inspect the BigInteger in order to use the most appropriate type? But, I don't see any benefits here: it appears not to be a problem to send a NUMERIC value for an INTEGER column - as far as the value is in the supported range. Concerning the visibility of setBigInteger(), you're perfectly right: it should be private [I must admit it was a (too) quick-and-dirty patch - mostly a copy of setBigDecimal - sorry ;) ] > > Incidentally, the JDBC spec does provide a standard mapping from > BigDecimal (not BigInteger) to NUMERIC. You are right here too: I've double checked the JDBC documentation. There's no mention of the BigInteger type - whereas the BigDecimal type is supported. I could have lived with that, but Jython maps values out of the Python integer range to BigInteger. Not BigDecimal. Which is perfectly legitimate. Moreover, I have done some tests with Groovy. It has somewhat the same behavior and wraps literal integers that exceed the ''long'' range in a BigInteger. So this could be definitively a concern for using prepared statements with scripting languages. As an attachment is a modified version of the patch - with setBigInteger set private. Sylvain -- Website: http://www.chicoree.fr --------------040704070403040300010805 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="AbstractJdbc2Statement.java.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="AbstractJdbc2Statement.java.diff" Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v retrieving revision 1.114 diff -u -8 -p -r1.114 AbstractJdbc2Statement.java --- org/postgresql/jdbc2/AbstractJdbc2Statement.java 27 May 2009 23:55:19 -0000 1.114 +++ org/postgresql/jdbc2/AbstractJdbc2Statement.java 5 Aug 2009 12:29:20 -0000 @@ -1224,16 +1224,36 @@ public abstract class AbstractJdbc2State */ public void setDouble(int parameterIndex, double x) throws SQLException { checkClosed(); bindLiteral(parameterIndex, Double.toString(x), Oid.FLOAT8); } /* + * Set a parameter to a java.lang.BigInteger value. The driver + * converts this to a SQL NUMERIC value when it sends it to the + * database. + * + * This is an extension to the JDBC API! + * + * @param parameterIndex the first parameter is 1... + * @param x the parameter value + * @exception SQLException if a database access error occurs + */ + private void setBigInteger(int parameterIndex, BigInteger x) throws SQLException + { + checkClosed(); + if (x == null) + setNull(parameterIndex, Types.DECIMAL); + else + bindLiteral(parameterIndex, x.toString(), Oid.NUMERIC); + } + + /* * Set a parameter to a java.lang.BigDecimal value. The driver * converts this to a SQL NUMERIC value when it sends it to the * database. * * @param parameterIndex the first parameter is 1... * @param x the parameter value * @exception SQLException if a database access error occurs */ @@ -1731,16 +1751,18 @@ public abstract class AbstractJdbc2State { checkClosed(); if (x == null) setNull(parameterIndex, Types.OTHER); else if (x instanceof String) setString(parameterIndex, (String)x); else if (x instanceof BigDecimal) setBigDecimal(parameterIndex, (BigDecimal)x); + else if (x instanceof BigInteger) + setBigInteger(parameterIndex, (BigInteger)x); else if (x instanceof Short) setShort(parameterIndex, ((Short)x).shortValue()); else if (x instanceof Integer) setInt(parameterIndex, ((Integer)x).intValue()); else if (x instanceof Long) setLong(parameterIndex, ((Long)x).longValue()); else if (x instanceof Float) setFloat(parameterIndex, ((Float)x).floatValue()); --------------040704070403040300010805--