Convertion of Unicode to ASCII NIGHTMARE
Fredrik Lundh
fredrik at pythonware.com
Wed Apr 5 01:37:55 EDT 2006
Roger Binns wrote:
> SQLite only accepts Unicode so a Unicode string has to be supplied.
fact or FUD? let's see:
import pysqlite2.dbapi2 as DB
db = DB.connect("test.db")
cur = db.cursor()
cur.execute("create table if not exists test (col text)")
cur.execute("insert into test values (?)", ["this is an ascii string"])
cur.execute("insert into test values (?)", [u"this is a unicode string"])
cur.execute("insert into test values (?)", [u"thïs ïs ö unicöde strïng"])
cur.execute("select * from test")
for row in cur.fetchall():
print row
prints
(u'this is an ascii string',)
(u'this is a unicode string',)
(u'th\xefs \xefs \xf6 unic\xf6de str\xefng',)
which is correct behaviour under Python's Unicode model.
</F>
More information about the Python-list
mailing list