Re: (Update) Implicit smallint to boolean conversion?

From: Brice Ruth <brice(at)webprojkt(dot)com>
To: pgsql-general(at)postgresql(dot)org(dot)pgsql-jdbc(at)postgresql(dot)org
Subject: Re: (Update) Implicit smallint to boolean conversion?
Date: 2001-02-12 19:57:43
Message-ID: 3A884037.ACF133AF@webprojkt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Found the problem:

In org/postgresql/jdbc2/ResultSet.java

The following line determines true/false:

return ((c == 't') || (c == 'T'));

Changing this to:

return ((c == 't') || (c == 'T') || (c == '1'));

Fixes the problem. This could probably be improved to:

return ((c == 't') || (c == 'T') || (c != '0'));

and in that way any result is 'true' and only '0' returns false (for SMALLINT).

Regards,
Brice Ruth

Brice Ruth wrote:
>
> Here's a code snippet that shows the problem:
>
> +--+
> boolean bNeuroPsych = objResults.getBoolean("NeuroPsych");
> short sNeuroPsych = objResults.getShort("NeuroPsych");
>
> System.out.println("Neurologic/Psychiatric: "+bNeuroPsych);
> System.out.println("Neurologic/Psychiatric: "+sNeuroPsych);
> +--+
>
> The "NeuroPsych" field is defined in PostgreSQL as a SMALLINT. The
> following is printed out when the code above is run:
>
> Neurologic/Psychiatric: false
> Neurologic/Psychiatric: 1
>
> Apparently, Oracle, Sybase, SQL Server & Access treat a smallint of '1'
> as 'true' when returned from getBoolean(). Is this a bug in the driver
> for PostgreSQL? Any help would be appreciated!
>
> See original message below for background & further details of the problem.
>
> TIA & Best Regards,
> Brice Ruth
>
> (Original Message)
> Greetings.
>
> I'm working with a third party product that is essentially a Java API to
> data housed in the database of your choice. My choice is PostgreSQL in
> this case. Access to the database is through JDBC, in this case,
> jdbc7.0-1.2.jar. One of the API calls isn't returning the correct
> results to my application - so I turned to the vendor for help. They've
> tested the call through JDBC to Access, Sybase, Oracle, and SQL Server
> and received the correct results. So, the current thought is that
> something is wrong in the JDBC library provided for PostgreSQL.
>
> Here's what's happening:
>
> The table being queried has 'smallint' fields in it. Apparently these
> fields will contain either 0 or 1, depending on if a condition is 'true'
> or 'false'. So, when the API queries the database, it apparently
> expects that these smallint fields will be implicitly converted to
> boolean 'true/false' values in Java, which is what is then returned to
> the application calling into the API. I don't know what Java code
> they're using - I've requested the relevant snippets. I can provide the
> query that is being run by the API, I can provide the structure of the
> table used in the SQL CREATE statement, and I can provide an example of
> the data in a record that would be returned. I won't paste all those
> things in this e-mail since I don't know if its necessary in this case -
> just let me know if it is.
>
> Any help or guidance on this issue would be greatly appreciated, as always.
>
> Sincerest regards & TIA,
> --
> Brice Ruth
> WebProjkt, Inc.
> VP, Director of Internet Technology
> http://www.webprojkt.com/

--
Brice Ruth
WebProjkt, Inc.
VP, Director of Internet Technology
http://www.webprojkt.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-02-12 20:19:15 Re: Casting help
Previous Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2001-02-12 19:45:26 Re: 7.1 installation problem

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-02-12 21:46:55 Re: How to make PostgreSQL JDBC drive get PGTZ?
Previous Message Brice Ruth 2001-02-12 19:37:10 (Update) Implicit smallint to boolean conversion?