I'm using SQLite with SQLObject 0.6, and I need to store and retrieve
unicode values. From my testing, I can get PySQLite to do unicode like
so:
def test_unicodeGoesInUnicodeComesOut(self):
cx = sqlite.connect(":memory:", encoding="utf-8")
cu = cx.cursor()
cu.execute("create table test(myfield unicode)")
cu.execute(u"insert into test values (%s)", (u"\x99sterreich",))
cu.execute("select * from test")
value = cu.fetchone()[0]
assert type(value) == unicode
(This is almost straight out of the PySQLite doc... I wanted to get it
confirmed in a test in my code).
The first problem is the SQLiteConnection does not provide a way for
me to set the encoding for the connection. I've tested this, and it is
required in order to successfully do unicode in both directions.
The second problem is that the column type needs to be unicode. If
it's just "text", PySQLite returns standard strings.
SQLiteConnection can be patched to add an optional encoding parameter.
Does that seem like something folks would want? If not, maybe I could
subclass SQLiteConnection and redo __init__ to open a unicode
connection.
For the second problem, I spotted a fairly recent thread
(http://sourceforge.net/mailarchive/forum.php?thread_id=6060501&forum_id=30269)
even with code (http://sourceforge.net/mailarchive/message.php?msg_id=10177526)
about making a unicode column. It also appears that there will be a
unicode column in 0.6.1. It seems like the main thing I need is to set
the column type.
My app is not going to be in production for a couple of months, so I
don't mind using alpha or beta code. I'm just looking for the "right"
way to do this in the context of SQLObject.
Thanks,
Kevin
|