[egenix-users] UTF-8 problem

M.-A. Lemburg mal at egenix.com
Tue Jun 21 20:16:25 CEST 2005


Martin Winkler wrote:
> On Wed, 2005-06-08 at 19:31 +0200, Charlie Clark wrote:
> 
>>But that isn't quite the same thing which is why I suggest you try the 
>>statements at the Python level.
> 
> 
> Ok, just did that:
> 
> import mx.ODBC.iODBC
> db = mx.ODBC.iODBC.DriverConnect('DSN=User;UID=;PWD=')
> c = db.cursor()
> 
> c.execute("select name1 from persons where id = 33")
> res = c.fetchall()
> print r[0][0]
> 
> brings the umlauts as usual.
> 
> but:
> 
> c.execute("update projects set title='täst 80a' where id = 80")
> c.execute("select title from projects where id = 80")
> print r[0][0]
> 
> gives me the double-encoded utf-8 characters. ("täst 80a")

Note that the statement string you pass to the .execute()
does not gets passed to the ODBC as-is without any conversion
in mxODBC, so you'd have to consult the ODBC driver documentation
on how it treats non-ASCII characters in SQL statements.

ODBC drivers often use two encodings: one for the interfacing
with the application (mxODBC in this case) and one for talking
to the database. Where they get the encoding definitions from and
which defaults they use can depend on a lot of driver and database
client lib specific settings.

It is usually safer to pass in non-ASCII data via bound
parameters:

c.execute("update projects set title=? where id = ?",
           ("täst", 80))

If "täst" doesn't work, try the equivalent Unicode string u"täst".

> The environment of the server is:
> LANG=en_US.UTF-8
> SUPPORTED=en_US.UTF-8:en_US:en:de_DE.UTF-8:de_DE:de
> 
> Zope really is not the problem here...
> 
> 
>>.encoding 
>>Read/write attribute which defines the encoding to use for converting 
>>Unicode to 8-bit strings and vice-versa. If set to None (default), Python's 
>>default encoding will be used, otherwise it has to be a string providing a 
>>valid encoding name, e.g. 'latin-1' or 'utf-8'.  
> 
> 
> I also tried 
> db.encoding='utf-8'
> and
> db.encoding='latin-1'
> 
> directly after the db=... statement, but that changed nothing :-(
> 
> 
> Help....? :,-(
> 
> br,
> Martin
> 
> 
> 
> _______________________________________________________________________
> eGenix.com User Mailing List                     http://www.egenix.com/
> https://www.egenix.com/mailman/listinfo/egenix-users

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 21 2005)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the egenix-users mailing list