Wednesday, September 20, 2006

Interesting discover about pys60 v1.3.1

To store a list of names in the database against a key, I use marshal.dumps(list). I got an interesting error while doing this:

len(l)
128
>>> db['check'] = marshal.dumps(l)
Traceback (most recent call last):
File "", line 1, in ?
File "C:\system\libs\e32dbm.py", line 145, in __setitem__
self._dbset(key,value)
File "C:\system\libs\e32dbm.py", line 100, in _dbset
self._execute(u"INSERT INTO data VALUES (%d,'%s','%s')"% (hash(key),sqlquote(key),sqlquote(value)))
UnicodeError: ASCII decoding error: ordinal not in range(128)


If the length of the list is 127, it stores fine in the database. Strange, huh? No! Doing, a db['check'] = unicode(marshal.dumps()) doesn't work either.

Workaround?
db['check'] = ';'.join(list)
list = db['check'].split(';')

No comments: