Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008, 01:00 AM
Andrea Aime
 
Posts: n/a
Default Bug while retrieving money data type from db

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.toDoub le(AbstractJdbc2ResultSet.java:2645)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getDou ble(AbstractJdbc2ResultSet.java:2032)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.intern alGetObject(AbstractJdbc2ResultSet.java:134)
at
org.postgresql.jdbc3.AbstractJdbc3ResultSet.intern alGetObject(AbstractJdbc3ResultSet.java:39)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getObj ect(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


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("jdbcostgresql://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!
}
}
}


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 01:00 AM
Kris Jurka
 
Posts: n/a
Default Re: Bug while retrieving money data type from db



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


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 01:00 AM
Daniel Migowski
 
Posts: n/a
Default Re: Bug while retrieving money data type from db

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).


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 01:00 AM
Kris Jurka
 
Posts: n/a
Default Re: Bug while retrieving money data type from db



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.p...224 &atid=854

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145