| Reply | « Previous Thread | Next Thread » |
|
While starting to explore the DBMS features of PyS60 I ran into a problem I can't solve. When I write and then read float values to a database the decimal places seem to be truncated and only the integer places plus '.0' are shown. E.g. '123.0' appears instead of the stored '123.123'.
The code below creates a database and fills it with some float values and there string representations. Then the stored values are printed out. In the printout the problem, hopefully, becomes visible. Any help is appreciated Thanks Martin Code:
import e32db db_name = u"c:\\test.db" #create/open database try: db = e32db.Dbms() db.open(db_name) except: db.create(db_name) db.open(db_name) sql_create = u"CREATE TABLE test (value FLOAT, string VARCHAR)" db.execute(sql_create) #delete all data in table test sql_del = u"DELETE FROM test" db.execute(sql_del) #write data to database for x in range(10): value = x * 123.123 string = unicode(x * 123.123) sql_add = "INSERT INTO test (value, string) VALUES (%d,'%s')"%(value, string) db.execute(sql_add) #read and print out data dbv = e32db.Db_view() dbv.prepare(db, u"SELECT * from test") dbv.first_line() print "float", "string" for i in range(dbv.count_line()): dbv.get_line() print dbv.col(1), dbv.col(2) dbv.next_line() db.compact() db.close() |
|
I'd say your problem is you use python string format %d for the float value. Try %f instead.
|
|
Quote:
I also tried to specify the field which should store the float as DOUBLE or DOUBLE PRECISION in the CREATE statement (referring to table 7.1 of the PyS60 docu). This also doesn't solve the problem. Anyone with more ideas? |
|
Try %e. It works, although it's pita when you have to provide literals.
whatever happens happens |
|
Thanks for the solution janekw_!
I tried to figure out how it might work by examening the Nokia 'sports diary' example code and google e.g. http://snippets.dzone.com/posts/show/1616. Both were misleading in this case ;-). Where can i find a documentation for such problems? Is it Python or SQL specific? |
|
You can find many useful info in Symbian SDK docs in DBMS section. PyS60 e32db is a very thin wrapper over native API. But in this case I just guessed right
You can't give up precision (which you do with %d), you can't use decimal representation (%f) so the only option left was expotential representation.whatever happens happens |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Read and write permissions | jennie | Mobile Java General | 6 | 2009-01-23 17:48 |
| RFile Read Write Asynchronous KErrCorrupt | muntain | General Symbian C++ | 20 | 2007-08-26 21:46 |
| How to read or write contact groups to/from PIM? | giridharg | Mobile Java General | 3 | 2006-08-26 02:16 |
| write and read a TInt data from the file | billqu | General Symbian C++ | 2 | 2004-12-27 16:10 |
| read and write Chinese menu in J2ME | walterzcm | Mobile Java General | 0 | 2002-11-13 07:22 |