RE: [cx-oracle-users] strange character encoding problems
Brought to you by:
atuining
From: Amaury F. <Ama...@gl...> - 2006-01-30 08:32:01
|
Hello, Marcus Eggenberger wrote: > I am not able to store characters of the latin-1 charset in my=20 > oracle-database. I've encoded them according to NLS_CHARACTERSET but=20 > that doesn't help. > I'm running Oracle 10g XE, Python 2.4.1 and cx_Oracle 4.1 >=20 > Here is some sample code which shows the very strange results: >=20 >=20 > #!/usr/bin/python=20 >=20 > # -*- coding: iso-8859-1 -*-=20 >=20 > import cx_Oracle >=20 > db =3D cx_Oracle.connect('TESTUSER/TESTPASSWORD@localhost') > c =3D db.cursor() >=20 > query =3D unicode("SELECT '=E4=F6=FC' FROM dual", 'iso-8859-1') > charsets =3D ['iso-8859-1', 'cp1252', 'utf-8', 'utf-16'] >=20 > c.execute('SELECT * FROM V$NLS_PARAMETERS') > for row in c: > print row >=20 > for charset in charsets: > try: > c.execute(query.encode(charset)) > except cx_Oracle.Error, err: > print err > else: > print charset, c.fetchone()[0] >=20 > c.close() > db.close() I tried the same script, and I get correct results on my database for the first two charsets, as expected. Did you check that your database can handle latin-1 characters? Take a look at NLS_CHARACTERSET in the NLS_DATABASE_PARAMETERS view. Another thing: the -*- coding -*- line is not correctly placed. It must be the first or second line of the script. I don't know if this makes the difference. --=20 Amaury Forgeot d'Arc Ubix Development www.ubitrade.com |