NUMERIC/DECIMAL handling in JDBC fixed

From: Mark Lillywhite <mark(at)plasticsoftware(dot)com(dot)au>
To: pgsql-interfaces(at)postgresql(dot)org
Cc: pmount(at)retep(dot)org(dot)uk
Subject: NUMERIC/DECIMAL handling in JDBC fixed
Date: 1999-09-19 10:04:40
Message-ID: 37E4B537.9AC66CF5@plasticsoftware.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi folks

In my continuing quest to actually contribute something to the world (not to
mention get my application running) I have found and fixed a few problems
with the JDBC driver's handing of Numeric/Decimal data types. It seems to me
that these types were never really implemented in JDBC when the types were
added to Postgresql, so I hope this small amount of work is helpful. This is
the driver shipped with 6.5.1 since I don't have the bandwidth for 6.5.2 at
this moment.

Firstly, in postgresql.Field, getSQLType() didn't recognise these types and
returned SQL_OTHER, which is wrong. I've made a very little fix to make it
return SQL_DECIMAL or SQL_NUMERIC (see questions below).

Next, in DatabaseMetaData.getColumns(), this method did not return the
DECIMAL_DIGITS column of the attribute; this is pretty important for working
out what to put into a getBigDecimal() call, so I worked out how to work it
out (hm) and I added it in. It seems to work fine.

I hope that noone (e.g. the maintainer!) minds that I did this, I was really
interested in fixing it as an excersise as much as because I needed it fixed
:) ... also, if this is generally considered useful then what do I do to
submit a patch? And, what do people here use for patches anyway? diff -Naur?

I am going to quickly look at getObject since that has some issues with
Numeric types too, it tries to set the scale but throws an exception when it
needs rounding (since it assumes the scale is zero). I'm not sure if I can do
anything about this and if not I think I will ignore it for now as my
application has to be running, more or less, this evening (sigh).

Also, can someone smarter than me tell me what difference there is (if any)
between DECIMAL and NUMERIC, either in the PG type names (does Postgres
distinguish these?) or in the SQL spec? I looked at the parser's yacc file
but I wasn't really able to see how it distinguishes between them, or if they
are just synonyms. (but it has been many years since I used yacc).

I presume that the same changes will be needed to the JDBC2 driver and I'm
happy to make them and submit them too, but at this stage I can't test them.

Kind regards
Mark

--
Mark Lillywhite - Plastic Software http://www.plasticsoftware.com.au/
-------------------------------------------------------------------------------
Plastic Software provides fully integrated, easy to use products and support
for Internet Service Providers, such as authentication and accounts receivable.

"The great thing about free mail is that you don't have to pay for it."
-- Scott McNealy

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 1999-09-19 10:30:33 Re: [INTERFACES] JDBC: BigDecimal and Money confusion
Previous Message Jens Glaser 1999-09-19 05:30:20 Re: [INTERFACES] NUMERIC/DECIMAL handling in JDBC fixed