[pysqlite] Encoding for connect to SqLite3
PY-Delens <[email protected]> Sun, 28 Jun 2009 12:03:55 +0200
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
--===============0972565796==
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Arial">Bonjour,<br>
<br>
Thanks again first to Mr Haering, for his patient and complete answer
to some newbie questions.<br>
I read the uptodate doc, and tried to keep in line with advice I got.<br>
<br>
I checked my chain along, from SqLite Datas to pySqlite code.<br>
Previously I was with ... UTF-16 datas ;=). Now OK UTF-8 in Sqlite
store.<br>
The accentuated characters are displaying OK in thre DbManager Tool.<br>
<br>
However, I made these tests:<br>
<br>
1. plain connect statement:<br>
<font face="Courier New"> def connect(self):<br>
self.cx = Sqlite.connect(self.dbFile)<br>
...<br>
for row in cur1.fetchall(): </font> <br>
Error MSG:<br>
pysqlite2._sqlite.OperationalError: Could not decode to UTF-8 column
'ID' with text 'Ar00----F-_$XClipFenêtr'<br>
<br>
2. </font><font face="Arial"> plain connect statement + text_factory:<br>
<font face="Courier New"> self.cx.text_factory = str <br>
..<br>
print row</font><br>
No </font><font face="Arial">Error MSG</font><font face="Arial">,
but <br>
'Ar100810HD_$G-O_Ma\xe7onnPrmnt_HachAnsi32' <br>
'Ar15----___$Structure-indiff\xe9renci\xe9'<br>
<br>
3. u'encode' the output datas<br>
</font><font face="Arial"><br>
<font face="Courier New"> self.cx.text_factory = str <br>
..<br>
print u'%s' % row[0] <br>
<br>
</font></font><font face="Arial">Error MSG</font>: <font face="Arial"><font
face="Courier New"><font face="Arial">UnicodeDecodeError:<br>
'ascii' codec can't decode byte 0xea in position 20: ordinal not in
range(128)</font><br>
</font></font><br>
--------<br>
<br>
The first test is at least showing that at a given time, the string
was OK to me, but not to Python.<br>
The 2 next tests didn't help.<br>
<br>
I didn't find another way to work at pySqlite level.<br>
<br>
QUESTIONS:<br>
1. Is there a way after fetching, in Python?<br>
<br>
2. I got this snippet from Egenix, but I'm not sure what I can do with
this, when READINg from Db instead of writing to:<br>
<pre wrap=""> unicode_data = data.decode('cp1252')</pre>
<br>
3. Is my Python coding in file header of no importance here (cp1252
)?<br>
<br>
4. What should I do?<br>
<br>
<br>
<br>
Thank you on forward.<br>
<br>
Yours,<br>
<br>
P-Y Delens<br>
</body>
</html>
--===============0972565796==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
list-pysqlite mailing list
list-pysqlite-FR6EJeJVuqdwc357pe9rcyQmJico6nz3epZhswDD4dQ@public.gmane.org
http://itsystementwicklung.de/cgi-bin/mailman/listinfo/list-pysqlite
--===============0972565796==--