Re: [cx-oracle-users] unicode characters and cx_Oracle.
Brought to you by:
atuining
From: Marcos P. <ma...@bu...> - 2005-08-22 08:25:39
|
This is an incomplete chunk of one of my programs: codPythonOracle=3D{ 'WE8ISO8859P1':'iso-8859-1', 'WE8ISO8859P15':'iso-8859-15', 'WE8MSWIN1252':'cp1252', } class LectorEsquema(fis.LectorEsquemaFisico): def lookupDesc(self,sql): if isinstance(sql, unicode): sql=3Dsql.encode(self.codificacion) return fis.LectorEsquemaFisico.lookupDesc(self,sql) def login(self): self.con=3Ddbapi.connect(self.usuario, self.clave, self.dsn, ) sqlCodOracle=3D'''select value=20 from v$nls_parameters=20 where parameter =3D 'NLS_CHARACTERSET' ''' codOracle=3Dself.lookup(sqlCodOracle)[0][0] self.codificacion=3DcodPythonOracle[codOracle] I don't have the time to prepare an example, but you can extract the information, I hope. * The first time you login, you get the default db encoding. * Then you translate what you get into Python (fill in what you get if it is not in the dict). * Whenever you receive an unicode string, translate into the needed encoding (both the sql and the parameters) before sending it to Oracle. * Whenever you receive a string, decode it using the same encoding, to work internally in Unicode. I hope it helps. This should be done by the cx libs, I guess. El lun, 22-08-2005 a las 13:40 +1000, Garrick Welsh escribi=C3=B3: > I have the following problem. I have a utf-8 encoded string, that is > to be inserted into an Oracle DB using cx_Oracle. >=20 > Now cx_Oracle appears to be configured to do a character translation > of some description on this string. Is there anyway I could insert the > unicode equivalent string? (i.e. udata =3D unicode(data, "utf-8")) > instead of a regular character string into the database? If not is > there a way to configure the encoding type that cx_Oracle expects... >=20 > Garrick >=20 > --=20 > Garrick Welsh >=20 > The human race is a race of cowards; and I am not only marching in > that > procession but carrying a banner. > -- Mark Twain --=20 Marcos S=C3=A1nchez Provencio <ma...@bu...> |