Skip site navigation (1) Skip section navigation (2)

Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject

From: Sylvain Leroux <sl20(at)wanadoo(dot)fr>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject
Date: 2009-08-06 13:49:07
Message-ID: 4A7ADF53.2070203@wanadoo.fr (view raw or flat)
Thread:
Lists: pgsql-jdbc
> So my concern with mapping Jython integer value -> BigInteger -> NUMERIC
> is that you end up with a statement parameter that's not actually an
> integer, and so "stmt.setObject(1,1234567899999)" will fail in cases
> where you would expect an integer value to work.
Ok, I understand.

> 
> Selecting a target type based on the magnitude of the parameter value
> passed may work better; then at least you get obvious behavior for cases
> where the value can fit in an integer.
That's what I have done now: setBigInteger will choose the narrowest 
integer representation. NUMERIC will still be used when no integer type 
is wide enough to hold the value.

With this, I think we have coherent behavior between Jython and psql.


As a side note, MySQL JDBC Driver accepts BigInteger in a setObject call 
too. But it takes less care of them, since they are simply mapped to 
strings:
>         public void setObject(int parameterIndex, Object parameterObj)
>                         throws SQLException {
>     ...
>     ...
>                         } else if (parameterObj instanceof BigInteger) {
>                                 setString(parameterIndex, parameterObj.toString());


Sylvain


-- 
Website: http://www.chicoree.fr

Attachment: pgjdbc-biginteger.patch
Description: text/plain (2.0 KB)

In response to

Responses

pgsql-jdbc by date

Next:From: dmpDate: 2009-08-10 15:05:05
Subject: Bytea Hex Format
Previous:From: JUNG, ChristianDate: 2009-08-05 15:53:17
Subject: PATCH: SET ROLE as connection parameter

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group