[EMAIL PROTECTED] schrieb am 22.02.2007
18:45:35:
> On Thu, Feb 22, 2007 at 06:42:56PM +0100, [EMAIL PROTECTED] wrote:
> > 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 the
DB: i.e. my ä, ö and ü are correctly visible in the DB, as latin-1 encoded
strings. When reading FROM the DB, I'd expect someone (mysql or sqlobject)
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 job:
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 = state.soObject._connection
soEncoding = getattr(connection, "encoding", None) or
sys.getdefaultencoding()
dbEncoding = getattr(connection, "dbEncoding", None) or 'ascii'
if soEncoding == dbEncoding:
return value
else:
return value.decode(dbEncoding).encode(soEncoding)
if isinstance(value, unicode):
connection = state.soObject._connection
encoding = 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 = 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 bestimmt.
Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird,
bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden und
anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopien
zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verboten.
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.-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss