pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedBug while retrieving money data type from db
4+ messages / 3 participants
[nested] [flat]
* Bug while retrieving money data type from db
@ 2008-02-26 13:36 Andrea Aime <aaime@openplans.org>
0 siblings, 1 reply; 4+ messages in thread
From: Andrea Aime @ 2008-02-26 13:36 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
I've stumbled into a bug, it seems the driver is not able to
retrive money data type from the db properly unless a getString
is used.... unfortunately in my case the code does not know
what kind of attributes is reading, and it uses getObject instead,
getting back an exception.
Running the attached code all I get is:
Exception in thread "main" org.postgresql.util.PSQLException: Il valore
«1,000.00» non è adeguato al tipo «double».
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.toDouble(AbstractJdbc2ResultSet.java:2645)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getDouble(AbstractJdbc2ResultSet.java:2032)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.internalGetObject(AbstractJdbc2ResultSet.java:134)
at
org.postgresql.jdbc3.AbstractJdbc3ResultSet.internalGetObject(AbstractJdbc3ResultSet.java:39)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getObject(AbstractJdbc2ResultSet.java:2348)
at PgMoneyIssue.main(PgMoneyIssue.java:15)
(translated from italian, "the value 1,000.00 is not adequate for the
type double". Not sure if the problem is locale dependent, since it has
been reported as a GeoServer bug by a user living in USA, and I then
tracked it down to this issue with the driver).
I looked for a bug tracker but could not find one, so here I am, posting
the bug report to the ml.
Contact me back if you need any further information
Cheers
Andrea
Attachments:
PgMoneyIssue.java (text/plain, 995B) download
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/*
To run this example run the following sql:
CREATE TABLE testmoney (
id serial,
cost money NOT NULL
);
INSERT INTO testmoney (id, cost) VALUES (1, '$999.00');
INSERT INTO testmoney (id, cost) VALUES (2, '$1,000.00');
INSERT INTO testmoney (id, cost) VALUES (3, '$10,000.01');
and then fix the connection paramters
*/
public class PgMoneyIssue {
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/postgis", "username", "password");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from testmoney");
while(rs.next()) {
System.out.println(rs.getObject(1));
System.out.println(rs.getObject(2)); // kaboom on the second record!
}
}
}
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug while retrieving money data type from db
@ 2008-02-29 17:09 Kris Jurka <books@ejurka.com>
parent: Andrea Aime <aaime@openplans.org>
0 siblings, 1 reply; 4+ messages in thread
From: Kris Jurka @ 2008-02-29 17:09 UTC (permalink / raw)
To: Andrea Aime <aaime@openplans.org>; +Cc: pgsql-jdbc
On Tue, 26 Feb 2008, Andrea Aime wrote:
> I've stumbled into a bug, it seems the driver is not able to
> retrive money data type from the db properly unless a getString
> is used.... unfortunately in my case the code does not know
> what kind of attributes is reading, and it uses getObject instead,
> getting back an exception.
We already knew the support for money in the driver was pretty poor (it
doesn't work for locale's whose currency symbol is not $), but the fact
that it doesn't support separators makes it especially useless.
Since every getInt/Float/... call is paying a performance price for
checking for the money type and doesn't always work, I suggest we rip all
that out and return money as either a String or the PGmoney type.
That will break existing applications that want to be able to do getDouble
on money data, but I'm OK with that because they should be pretty rare.
Kris Jurka
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug while retrieving money data type from db
@ 2008-02-29 17:36 Daniel Migowski <dmigowski@ikoffice.de>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Migowski @ 2008-02-29 17:36 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
Hello Kris,
Kris Jurka schrieb:
> That will break existing applications that want to be able to do
> getDouble on money data, but I'm OK with that because they should be
> pretty rare.
If you are on breaking existing applications anyway, please reconsider
my patch given in the Thread with the name "[JDBC] TypeInfoCache" :))
>
> Kris Jurka
With best regards,
Daniel Migowski
PS: This patch even enables an application, namely Chrystal Reports JDBC
Implementation (which is not so rare).
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bug while retrieving money data type from db
@ 2008-02-29 17:57 Kris Jurka <books@ejurka.com>
parent: Daniel Migowski <dmigowski@ikoffice.de>
0 siblings, 0 replies; 4+ messages in thread
From: Kris Jurka @ 2008-02-29 17:57 UTC (permalink / raw)
To: Daniel Migowski <dmigowski@ikoffice.de>; +Cc: pgsql-jdbc
On Fri, 29 Feb 2008, Daniel Migowski wrote:
> Kris Jurka schrieb:
>> That will break existing applications that want to be able to do getDouble
>> on money data, but I'm OK with that because they should be pretty rare.
>
> If you are on breaking existing applications anyway, please reconsider my
> patch given in the Thread with the name "[JDBC] TypeInfoCache" :))
>
I still don't like your patch, but I am planning on implementing the
solution that Oliver and I liked better (making up a bogus precision for
types without lengths).
http://pgfoundry.org/tracker/index.php?func=detail&aid=1010277&group_id=1000224&atid=854
Kris Jurka
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2008-02-29 17:57 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-02-26 13:36 Bug while retrieving money data type from db Andrea Aime <aaime@openplans.org>
2008-02-29 17:09 ` Kris Jurka <books@ejurka.com>
2008-02-29 17:36 ` Daniel Migowski <dmigowski@ikoffice.de>
2008-02-29 17:57 ` Kris Jurka <books@ejurka.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox