(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: (Update) Implicit smallint to boolean conversion?
Date: 2001-02-12 19:37:10
Message-ID: 3A883B65.2140F39C@webprojkt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

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/

Responses

Browse pgsql-general by date

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

Browse pgsql-jdbc by date

  From Date Subject
Next Message Brice Ruth 2001-02-12 19:57:43 Re: (Update) Implicit smallint to boolean conversion?
Previous Message Bruce Momjian 2001-02-12 17:25:37 Re: Re: PostgreSQL and PHP persistent connections