cx_Oracle and unicode data
looping
kadeko at gmail.com
Thu Mar 15 08:05:37 EDT 2007
Hi,
I need to get data from an Oracle DB that contains unicode data
(chinese text).
But the chinese data that I receive is wrong (only ¿).
After a look at the Oracle documentation I've found an environment
variable called NLS_LANG that you could set to define what charset the
DB client use and it work fine.
But it's not what I call a 'clean' solution and I suppose that it must
exist another way to force the client DB to use UTF8, or another
solution to get my data.
Could someone help me ?
Thanks.
Example:
# -*- coding: latin1 -*-
import os
import cx_Oracle
os.environ["NLS_LANG"] = ".UTF8"
con = cx_Oracle.connect("demo/demo at DEMOUTF8A")
cur = con.cursor()
cur.execute("select DESCRIPTION from DEC_DESCRIPTION where
DEC_DESCRIPTION_ID = 1792528")
val1 = cur.fetchone()[6]
val2 = cur.fetchone()[6]
print con.encoding, con.nencoding, con.maxBytesPerCharacter
cur.close()
print val1.decode(con.encoding)
print val2.decode(con.encoding)
del os.environ["NLS_LANG"]
>>>
UTF-8 UTF-8 3
珀マザーボードのテスト作業 颇マザーボードのテスト作業マザーボードのテスト作業,
without NLS_LANG setting I get:
>>>
WINDOWS-1252 WINDOWS-1252 1
¿¿¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿,
More information about the Python-list
mailing list