Re: Problem with UTF-8
"Manuel Lanctot" <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
From a previous discussion, it looks like you need to convert the data
to Unicode and also use the parameter way for execute(). I guess
something like:
for i in range(len(lines[0])-1):
cur.execute("insert into data values ?", (unicode(i),))
I guess you can't avoid converting to Unicode first...
See http://lists.initd.org/pipermail/pysqlite/2006-April/000488.html
Hope that helps.
Manuel
P.S. Small world, I'm sitting right next to the Eurocopter service desk. :-)
On 11/23/06, Brisset, Nicolas <[email protected]> wrote:
> Hi,
>
> I've discovered that it is possible to create in-memory databases with pysqlite, and I wanted to use that feature to work with tabulated files (containing accentuated characters).
> I wrote the attached test script, which almost works. The remaining problem is that I get errors like:
>
> >>> print cur.fetchall()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> pysqlite2.dbapi2.OperationalError: Could not decode to UTF-8 column 'Col1' with text ' texte où il y a des éàè '
>
> It seems that the lines table created by the csv reader contains non-unicode strings, which the executemany statement introduces into the sqlite table and that can't be extracted back. But I'm not sure that this is the real problem, nor how I can solve it properly and efficiently. Any help would be greatly appreciated.
>
> Nicolas
>
> PS: I have tried with sqlite3 bundled in python 2.5 and I get the exact same problem.