inserting unicode into sqlite database throws exception when using web.database
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
web.py |
Fix Released
|
Medium
|
Anand Chitipothu |
Bug Description
Here's how to reproduce:
>>> import web
>>> db = web.database(
>>> db.query("create table t(t text)")
0.0 (1): create table t(t text)
-1
>>> db.insert('t', t=u'\u20ac')
ERR: INSERT INTO t (t) VALUES (u'\u20ac')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/
self.
File "/usr/local/
for x in sql_query.
sqlite3.
using Python 2.6.2, web.py 0.31. My fix (simply remove line 951 from web/db.py):
--- db.py 2009-05-07 14:22:30.000000000 +0200
+++ db.py.orig 2009-05-07 14:21:25.000000000 +0200
@@ -948,6 +948,7 @@
"""
if val is True: return 1
elif val is False: return 0
+ elif isinstance(val, unicode): return val.encode(
else: return val
class FirebirdDB(DB):
Then:
>>> import web
>>> db = web.database(
>>> db.query("create table t(t text)")
0.0 (1): create table t(t text)
-1
>>> db.insert('t', t=u'\u20ac')
0.0 (2): INSERT INTO t (t) VALUES (u'\u20ac')
0.0 (3): SELECT last_insert_
1
Don't know if this is right, but I think it should be reported.
Changed in webpy: | |
status: | Fix Committed → Fix Released |
Which sqlite driver are you using? sqlite3 or pysqlite2?