X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4FBDA52859 for ; Thu, 26 May 2005 22:09:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48380-07 for ; Fri, 27 May 2005 01:09:48 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id AA7E95284B for ; Thu, 26 May 2005 22:09:44 -0300 (ADT) Received: (qmail 21914 invoked from network); 27 May 2005 01:08:08 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 27 May 2005 01:08:08 -0000 Message-ID: <42967356.2060507@fastcrypt.com> Date: Thu, 26 May 2005 21:09:42 -0400 From: Dave Cramer Reply-To: pg@fastcrypt.com Organization: PostgreSQL International User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Oliver Jowett Cc: pgsql-jdbc@postgresql.org Subject: Re: BIGINT <-> java.lang.String auto cast References: <4294BAAE.4080106@fastcrypt.com> <42955CC9.6040306@opencloud.com> <4295B69E.1070308@fastcrypt.com> <42965917.7090206@opencloud.com> <4296675D.6060505@fastcrypt.com> <42966881.2000609@opencloud.com> <42966D6E.1080007@fastcrypt.com> <42967221.20505@opencloud.com> In-Reply-To: <42967221.20505@opencloud.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.025 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/122 X-Sequence-Number: 12953 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