Re: Low Priority: Harmless but useless code in

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Jeroen Habets <Jeroen(at)twofoldmedia(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Low Priority: Harmless but useless code in
Date: 2003-03-25 10:43:48
Message-ID: 1048589028.1191.43.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Jeroen,

Good eye!

Thanks,

Dave
On Tue, 2003-03-25 at 05:23, Jeroen Habets wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> While looking at the PreparedStatement functionality of the
> postgresql driver I ran in
> AbstractJdbc1Statement.setObject(int parameterIndex, Object x))
> into the following snippet of code.
>
> if (x == null)
> {
> int l_sqlType;
> if (x instanceof String)
> l_sqlType = Types.VARCHAR;
> else if (x instanceof BigDecimal)
> l_sqlType = Types.DECIMAL;
> else if (x instanceof Short)
> l_sqlType = Types.SMALLINT;
> else if (x instanceof Integer)
> l_sqlType = Types.INTEGER;
> else if (x instanceof Long)
> l_sqlType = Types.BIGINT;
> else if (x instanceof Float)
> l_sqlType = Types.FLOAT;
> else if (x instanceof Double)
> l_sqlType = Types.DOUBLE;
> else if (x instanceof byte[])
> l_sqlType = Types.BINARY;
> else if (x instanceof java.sql.Date)
> l_sqlType = Types.DATE;
> else if (x instanceof Time)
> l_sqlType = Types.TIME;
> else if (x instanceof Timestamp)
> l_sqlType = Types.TIMESTAMP;
> else if (x instanceof Boolean)
> l_sqlType = Types.OTHER;
> else
> l_sqlType = Types.OTHER;
>
> setNull(parameterIndex, l_sqlType);
> return ;
> }
>
> According to my O'Reilly Java Language Reference, x instanceof
> <Type>, where x == null will always return false...am I overlooking
> something?
>
> I tested it using the following class:
>
> /**
> * test class for 'x instanceof <Class>' where x is null
> */
> public class InstanceOf {
> public static void main(String[] args) {
>
> Object x = null;
>
> System.out.println("x instanceof Object: "+(x instanceof Object));
> System.out.println("x instanceof String: "+(x instanceof String));
> System.out.println("x instanceof Integer: "+(x instanceof
> Integer));
>
> }
> }
>
> With java version "1.4.1_01" I get:
>
> $ java InstanceOf
> x instanceof Object: false
> x instanceof String: false
> x instanceof Integer: false
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPoAgA/IWL7P9qCbyEQKevQCgwTUiGCmM8h+Bqmz7OZRlj/rAEZ4AmwY3
> fUmH1CLmMNXfmrChdFn/qtne
> =Ndff
> -----END PGP SIGNATURE-----
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Dave Cramer <Dave(at)micro-automation(dot)net>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeroen Habets 2003-03-25 10:56:37 Re: Patch AbstractJdbc1Statement.setBoolean support BIT andINTEGER columns
Previous Message Dave Cramer 2003-03-25 10:43:12 Re: Patch AbstractJdbc1Statement.setBoolean support BIT and