[cx-oracle-users] Re: [DB-SIG] cx_Oracle and Unicode ???
Brought to you by:
atuining
|
From: Marcos P. <ma...@bu...> - 2005-05-05 16:28:53
|
This is what I do (not tested, I had to trim out a lot of uninteresting
code):
import cx_Oracle as dbapi
codPythonOracle=3D{
'WE8ISO8859P1':'iso-8859-1',
'WE8ISO8859P15':'iso-8859-15',
'WE8MSWIN1252':'cp1252',
}
con=3Ddbapi.connect(usuario, clave, dsn)
sqlCodOracle=3D'''select value=20
from v$nls_parameters=20
where parameter =3D 'NLS_CHARACTERSET' '''
cur=3Dcon.cursor()
cur.execute(sqlCodOracle)
codOracle=3Dcur.fetchone()[0]
codificacion=3DcodPythonOracle[codOracle]
#Then, encode the sql accordingly
if isinstance(sql, unicode):
sql=3Dsql.encode(self.codificacion)
=20
I hope it helps. This should be handled by cx_Oracle, I suppose...
El jue, 05-05-2005 a las 08:43 -0700, Guido van Rossum escribi=C3=B3:
> Maybe this is more an issue for the cx-oracle mailing list? (Google for=
it.)
>=20
> I'd be interested in hearing the answer too.
>=20
> On 5/5/05, Mark Bennett <mbe...@id...> wrote:
> > =20
> > Good morning Folks,=20
> > =20
> > I've looked around on Google for this a few times and really haven't =
come up
> > with anything definitive.=20
> > =20
> > I'm trying to update values in Oracle with the .execute() method from
> > cx_Oracle.=20
> > =20
> > If I create a Python unicode string object and try to pass it in, Pyt=
hon
> > complains that .execute() expects a None or string.=20
> > =20
> > If I convert the unicode string to a regular "byte" string beforehand=
with
> > .encode() and utf-8, Python accepts it but when we pull the data back=
from
> > Oracle we get garbage characters.=20
> > =20
> > Some details:=20
> > =20
> > Python 2.4 with a recent version of cx_Oracle (don't have the exact v=
ersion
> > here) Running on Solaris.=20
> > =20
> > And from our DBA:
> > =20
> > Oracle 9 on Solaris. The database was told to support Unicode.=20
> > =20
> > The character fields are currently VARCHAR2; he believes he's seen
> > conflicting evidence online about whether or not that is supposed to =
work.=20
> > We've also talked about using NVARCHAR2 and NCLOB.=20
> > =20
> > We have not set any environment variables on Solaris.=20
> > =20
> > Thanks in advance,=20
> > Mark=20
> > =20
> > _______________________________________________
> > DB-SIG maillist - DB...@py...
> > http://mail.python.org/mailman/listinfo/db-sig
> >=20
> >=20
> >=20
>=20
>=20
|