Thread: [Modeling-users] SQLite, problemas with Floats
Status: Abandoned
Brought to you by:
sbigaret
From: Ernesto R. <er...@si...> - 2003-09-16 23:26:14
|
Hi again (sorry for the attack), I'm using Modeling 0.9-pre15 and sqlite 2.8.6 When I do a fetch for objects with float attributes, these are string = and not float. Say: .... >>> accounts=3Dec.fetch('Account') >>> accounts[0].getAmount() '0.0' I know that sqlite stores everything as strings, but it should be = converted to float in Python, and I don't know where to do this. The = problem is (suppose account has a name): >>> accounts[0].setName('sales') >>> ec.saveChanges() .... Modeling.Validation.ValidationException: Validation for key saldo = failed: - Wrong type Validation for key OBJECT_WIDE_VALIDATION failed: - Validation of object <Conta.Cuenta.Cuenta instance at 0x00DC4FE8> as a = whole failed because although it has been initialised with 0.0 now it is '0.0' (type = string). Thanx in advance, Erny |
From: Ernesto R. <er...@si...> - 2003-09-17 04:33:58
|
Ok, I've tracked down this and see the following issue: In DatabaseContext.py, near line 1540, the following two lines appear: if value and attr.type() =3D=3D 'DateTime': value=3Dattr.convertStringToAttributeType(value) So we only do type conversion if attr.type() =3D=3D 'DateTime' and value = is not empty ??? Is this an optimization? Shouldn't we force a conversion to Python types whenver possible? Should = this work be done by the database layer (perhaps we need custom = conversions depending on the database)? Erny ----- Original Message -----=20 From: "Ernesto Revilla" <er...@si...> To: "modeling-users" <mod...@li...> Sent: Wednesday, September 17, 2003 1:31 AM Subject: [Modeling-users] SQLite, problemas with Floats Hi again (sorry for the attack), I'm using Modeling 0.9-pre15 and sqlite 2.8.6 When I do a fetch for objects with float attributes, these are string = and not float. Say: .... >>> accounts=3Dec.fetch('Account') >>> accounts[0].getAmount() '0.0' I know that sqlite stores everything as strings, but it should be = converted to float in Python, and I don't know where to do this. The = problem is (suppose account has a name): >>> accounts[0].setName('sales') >>> ec.saveChanges() .... Modeling.Validation.ValidationException: Validation for key saldo = failed: - Wrong type Validation for key OBJECT_WIDE_VALIDATION failed: - Validation of object <Conta.Cuenta.Cuenta instance at 0x00DC4FE8> as a = whole failed because although it has been initialised with 0.0 now it is '0.0' (type = string). Thanx in advance, Erny ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Modeling-users mailing list Mod...@li... https://lists.sourceforge.net/lists/listinfo/modeling-users |
From: Sebastien B. <sbi...@us...> - 2003-09-17 11:38:36
|
"Ernesto Revilla" <er...@si...> wrote: > Ok, I've tracked down this and see the following issue: >=20 > In DatabaseContext.py, near line 1540, the following two lines appear: >=20 > if value and attr.type() =3D=3D 'DateTime': > value=3Dattr.convertStringToAttributeType(value) >=20 > So we only do type conversion if attr.type() =3D=3D 'DateTime' and value = is not empty ??? > Is this an optimization? >=20 > Shouldn't we force a conversion to Python types whenver possible? Should = this work be done by the database layer (perhaps we need custom conversions= depending on the database)? Usually these type conversions are done by the python adaptors --but right, everything in sqlite is string, but I can't remeber how pysqlite handles this, and I can't test this here. I've got to check this, especially why this is not catched by the unittests; I'll have a look at it this evening and will report with further details then. -- S=E9bastien. > ----- Original Message -----=20 > From: "Ernesto Revilla" <er...@si...> > To: "modeling-users" <mod...@li...> > Sent: Wednesday, September 17, 2003 1:31 AM > Subject: [Modeling-users] SQLite, problemas with Floats >=20 >=20 > Hi again (sorry for the attack), >=20 > I'm using Modeling 0.9-pre15 and sqlite 2.8.6 >=20 > When I do a fetch for objects with float attributes, these are string and= not float. Say: > .... > >>> accounts=3Dec.fetch('Account') > >>> accounts[0].getAmount() > '0.0' >=20 > I know that sqlite stores everything as strings, but it should be convert= ed to float in Python, and I don't know where to do this. The problem is (s= uppose account has a name): > >>> accounts[0].setName('sales') > >>> ec.saveChanges() > .... > Modeling.Validation.ValidationException: Validation for key saldo failed: > - Wrong type > Validation for key OBJECT_WIDE_VALIDATION failed: > - Validation of object <Conta.Cuenta.Cuenta instance at 0x00DC4FE8> as a = whole failed >=20 > because although it has been initialised with 0.0 now it is '0.0' (type s= tring). >=20 > Thanx in advance, > Erny |
From: Sebastien B. <sbi...@us...> - 2003-09-17 19:13:07
|
Hi, "Ernesto Revilla" <er...@si...> wrote: > Hi again (sorry for the attack), >=20 > I'm using Modeling 0.9-pre15 and sqlite 2.8.6 >=20 > When I do a fetch for objects with float attributes, these are string and= not float. Say: > .... > >>> accounts=3Dec.fetch('Account') > >>> accounts[0].getAmount() > '0.0' Which version of pysqlite are you currently using? I just checked the recommended version (cf. http://modeling.sf.net/installation.html) i.e. pysqlite v0.4.3, and this version does cast the types as expected: >>> import sqlite >>> sqlite.version '0.4.3' >>> cnx=3Dsqlite.connect('db_AuthorBooks.db') >>> cur=3Dcnx.cursor() >>> cur.execute("SELECT t0.ID, t0.LAST_NAME, t0.FIRST_NAME, t0.AGE, t0.BIRT= HDAY, t0.FK_WRITER_ID FROM WRITER t0 WHERE t0.id=3D1") >>> cur.fetchall() [(1, 'Cleese', 'John', 24, <DateTime object for '1939-10-27 08:31:15.00' at= 81d7ea8>, None)] I couldn't find any clue on when this was introduced, however. Could you check your own version and report? Thanks. -- S=E9bastien. |