cx_Oracle and unicode data
haraldarminmassa at gmail.com
Thu Mar 15 13:48:20 CET 2007
> 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.
I share your feeling. I asked a similiar question ~1 year ago; and:
your solution is the only one.
The oracle-libs get their encoding from the environment. I also
learned that it often is helpfull to first set the environment and
THEN import cx_Oracle (which loads the oci.dll)
> import os
> os.environ["NLS_LANG"] = ".UTF8"
> import cx_Oracle
> cur.execute("select DESCRIPTION from DEC_DESCRIPTION where
> DEC_DESCRIPTION_ID = 1792528")
Additionally: UTF8 has different numbers of bytes per character. Your
select will only succeed for the time that DESCRIPTION encoded in UTF8
is shorter or equal to length(DESCRIPTION)
I got into the habbit to cast those fields to
NVARCHAR2(as big as I think it may get)
More information about the Python-list