Re: BIGINT <-> java.lang.String auto cast

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: BIGINT <-> java.lang.String auto cast
Date: 2005-05-27 01:09:42
Message-ID: 42967356.2060507@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ok,

I recall it now, this isn't sufficient for the plethora of conversions
which have to be made.

Basically what I did was create an internal type for every SQL type in
org.postgresql.types

and I do one set of instanceof as below to determine which type to
create, and then
do a convert based on the sqltype passed in.

I'll commit the patch tomorrow

Dave

Oliver Jowett wrote:

> Dave Cramer wrote:
>
>> Where do you see the driver doing such conversions.
>
>
> In AbstractJdbc2Statement.setObject(int,Object,int,int), e.g.:
>
>> // Helper method that extracts numeric values from an arbitary
>> Object.
>> private String numericValueOf(Object x)
>> {
>> if (x instanceof Boolean)
>> return ((Boolean)x).booleanValue() ? "1" : "0";
>> else if (x instanceof Integer || x instanceof Long ||
>> x instanceof Double || x instanceof Short ||
>> x instanceof Number || x instanceof Float)
>> return x.toString();
>> else
>> //ensure the value is a valid numeric value to avoid
>> //sql injection attacks
>> return new BigDecimal(x.toString()).toString();
>> }
>
>
> [...]
>
>> switch (targetSqlType)
>> {
>> case Types.INTEGER:
>> bindLiteral(parameterIndex, numericValueOf(x), Oid.INT4);
>> break;
>
>
> [...]
>
> -O
>
>

--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2005-05-27 01:13:41 Re: BIGINT <-> java.lang.String auto cast
Previous Message Oliver Jowett 2005-05-27 01:04:33 Re: BIGINT <-> java.lang.String auto cast