sql...@li... schrieb am 22.02.2007
18:45:35:
> On Thu, Feb 22, 2007 at 06:42:56PM +0100, ber...@zk... wrot=
e:
> > The thing is, our mysql db has a latin-1 encoding while I'd rather =
want
our
> > program files (and ultimately the web frontend) to be in UTF-8, so =
I'd
even
> > expect the two encodings to be different.
> >
> > Does this seem reasonable?
>
> It does, indeed.
>
Now I'm still confused. This seems to work for utf-8 data written TO th=
e
DB: i.e. my =E4, =F6 and =FC are correctly visible in the DB, as latin-=
1 encoded
strings. When reading FROM the DB, I'd expect someone (mysql or sqlobje=
ct)
to convert those strings back to utf-8, which isn't happening, though.
It seems like e.g. some changes in the string validator would do the jo=
b:
class StringValidator(validators.Validator):
def to_python(self, value, state):
if value is None:
return None
if isinstance(value, str):
# Convert from connection.dbEncoding to connection.encoding=
via
unicode
connection =3D state.soObject._connection
soEncoding =3D getattr(connection, "encoding", None) or
sys.getdefaultencoding()
dbEncoding =3D getattr(connection, "dbEncoding", None) or '=
ascii'
if soEncoding =3D=3D dbEncoding:
return value
else:
return value.decode(dbEncoding).encode(soEncoding)
if isinstance(value, unicode):
connection =3D state.soObject._connection
encoding =3D getattr(connection, "encoding", None) or
sys.getdefaultencoding()
return value.encode(encoding)
return value
def from_python(self, value, state):
if value is None:
return None
if isinstance(value, str):
return value
if isinstance(value, unicode):
dbEncoding =3D getattr(connection, "dbEncoding", None) or '=
ascii'
return value.encode(dbEncoding)
return value
This works (at least for me), but doesn't seem the right place to do it=
.
What do you think?
Thanks,
Bernhard
___________________________________________________________________
Disclaimer:
Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger bestimm=
t.
Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird,
bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden un=
d
anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopi=
en
zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verbot=
en.
This message is intended only for the named recipient and may contain
confidential or privileged information.
If you have received it in error, please advise the sender by return e-=
mail
and delete this message and any attachments. Any unauthorised use or
dissemination of this information is strictly prohibited.=
|