Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## sqlobject-discuss

 [SQLObject] DecimalCol and SQLite From: Bryan Russell - 2005-11-10 19:09:27 ```Hi all, Although python has brought the fun back into programming, I'm still=20 relatively new to python. Still, having learned a few things I thought it=20 time to start exploring databases by downloading and installing SQLObject. = A=20 throughly uncomplicated and uneventful (in the sense of problems encountere= d)=20 episode. Quickly enough the experiments began. So far I've hit only one are= a=20 where I need help ... DecimalCols ... everything else just works. I'm using Python 2.4.1 and SQLOBjects 0.7rc1 and SQLite (version 3 I think)= =2E A=20 simplified example follows. Basically I created a class with a DecimalCol,= =20 added a few entries and queried the db. The record returned contains a floa= t,=20 not the anticipated Decimal.=20 from decimal import Decimal from sqlobject import * connection =3D connectionForURI( "sqlite:/:memory:" ) sqlhub.processConnection =3D connection class Diameter( SQLObject ): =A0 =A0 pid =3D StringCol() =A0 =A0 cm =3D DecimalCol( size=3D10, precision=3D4 ) =A0 =A0=20 Diameter.createTable() Diameter( pid=3D"gdt", cm=3DDecimal( "0.8684" )) print Diameter.get( 1 ).cm Results in 0.86839999999999995 a float.=20 The project I would like to start would make extensive use of DecimalCols s= o=20 any insights would be appreciated.=20 Thanks, Bryan Russell ```
 [SQLObject] Re: DecimalCol and SQLite From: Alan Franzoni - 2005-11-13 22:05:11 ```Bryan Russell on gmane.comp.python.sqlobject said: > The project I would like to start would make extensive use of DecimalCols so > any insights would be appreciated. I had a similar problem with Postgresql and psycopg. It seems that, wherever the DB interface returns a float, sqlobject can do nothing about it - it just stays a float. You should test the sqlite Python DB interface to check where it can return decimals. It may require special parametrs to do so. Otherwise, you'll have to make do by coupling integers, just like I did. -- Alan Franzoni -- Togli .xyz dalla mia email per contattarmi Remove .xyz from my email in order to contact me. ```
 Re: [SQLObject] Re: DecimalCol and SQLite From: Bryan Russell - 2005-11-15 10:09:22 ```Alan Franzoni replied: > I had a similar problem with Postgresql and psycopg. It seems that, > wherever the DB interface returns a float, sqlobject can do nothing about > it - it just stays a float. > > You should test the sqlite Python DB interface to check where it can return > decimals. It may require special parametrs to do so. It seems more of a sqlite limitation. SQLite natively supports: NULL, INTEGER, REAL, TEXT, BLOB types. The Python DB interface (pysqlite) however is extensible through object adaptors. I've even written a couple of "types" and adaptors successfully when using pysqlite directly. It's really not that difficult. But as a bunch of SQL statements are tedious and not particularly pythonic nor necessarily oo, I thought I'd try the SQLObject experience. > Otherwise, you'll have to make do by coupling integers, just like I did. For the time being I've met my Decimal need by writing a DecimalValidator and inserting it into sqlobject.col.py. There is likely a better solution, but for now Decimal values "round trip" as I would like and expect. -- Bryan Russell ```
 [SQLObject] Re: Re: DecimalCol and SQLite From: Alan Franzoni - 2005-11-15 14:32:11 ```Bryan Russell on gmane.comp.python.sqlobject said: > It seems more of a sqlite limitation. SQLite natively supports: NULL, INTEGER, > REAL, TEXT, BLOB types. The Python DB interface (pysqlite) however is > extensible through object adaptors. I've even written a couple of "types" and I supposed sqlite *did* support Decimal. My problem was kind of differnet: PGSQL does support the Decimal type indeed, and the type was correctly chosen in the DB, but it was returned wrongly in Python. > For the time being I've met my Decimal need by writing a DecimalValidator and > inserting it into sqlobject.col.py. There is likely a better solution, but > for now Decimal values "round trip" as I would like and expect. I did something similar. -- Alan Franzoni -- Togli .xyz dalla mia email per contattarmi Remove .xyz from my email in order to contact me. ```