Re: [cx-oracle-users] unicode characters and cx_Oracle.
Brought to you by:
atuining
From: Marcos P. <ma...@bu...> - 2005-08-24 08:36:38
|
I am sorry if I say obvious things, but sometimes they help (others?) :-) Your string is being encoded as unicode and then decoded as iso-8859-1 (or something similar). Are you sure you are not mixing unicode and encoded strings in your code? When you reach this statement: # a _must_ be unicode a =3D a.encode("utf-8") # now a is an encoded string I guess you must use some convention in your code to separate both types os strings. Try what you read from the database, to see if the same string you read works when fed to the procedure. Well, I hope I gave you some pointer.=20 El mi=C3=A9, 24-08-2005 a las 10:07 +1000, Garrick Welsh escribi=C3=B3: > Thank you. >=20 > I actually have been doing the same sort of encoding as you've > specified. >=20 > The NLS_CHARACTERSET of the database is utf-8 and I've been utf-8 > encoding any of my unicode strings before I attempt to insert them > into the database. Unfortunately when I attempt to access the inserted > information it's done via .NET. The characters inserted are definately > not those that were inserted and the Oracle Table Editor displays the > characters identically to .NET. >=20 > Cheers, > Garrick >=20 > (More implementation details) > russian --=D1=87=D1=82=D0=BE =D1=82=D0=B0=D0=BA=D0=BE=D0=B5 =D0=BE=D1=81= =D0=B5=D0=BD=D1=8C-- russian (is the input) > russian --=C3=91=E2=80=A1=C3=91=E2=80=9A=C3=90=C2=BE =C3=91=E2=80=9A=C3= =90=C2=B0=C3=90=C2=BA=C3=90=C2=BE=C3=90=C2=B5 =C3=90=C2=BE=C3=91=C2=81=C3= =90=C2=B5=C3=90=C2=BD=C3=91=C5=92-- russian (is what is stored > in the database) >=20 > Basically the test text russian --=D1=87=D1=82=D0=BE =D1=82=D0=B0=D0=BA= =D0=BE=D0=B5 =D0=BE=D1=81=D0=B5=D0=BD=D1=8C-- russian is stored > in a utf-8 encoded file. >=20 > f =3D codecs.open('multi.txt','r','utf-8') > a =3D f.readline() =20 > =20 > a =3D a.encode("utf-8") >=20 > This is passed as an argument to a stored procedure... >=20 > The text is then simply inserted into a database table. The text > between the source and the end result is different. >=20 >=20 > On 8/22/05, Marcos S=C3=A1nchez Provencio <ma...@bu...> wrote: > This is an incomplete chunk of one of my programs: > codPythonOracle=3D{ > 'WE8ISO8859P1':'iso-8859-1', > 'WE8ISO8859P15':'iso-8859-15', > 'WE8MSWIN1252':'cp1252', > } > =20 > 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 > from v$nls_parameters > where parameter =3D 'NLS_CHARACTERSET' ''' > codOracle=3Dself.lookup (sqlCodOracle)[0][0] > self.codificacion=3DcodPythonOracle[codOracle] > =20 > I don't have the time to prepare an example, but you can > extract the > information, I hope. > =20 > * The first time you login, you get the default db encoding.=20 > * 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.=20 > * Whenever you receive a string, decode it using the same > encoding, to > work internally in Unicode. > =20 > I hope it helps. This should be done by the cx libs, I guess. > =20 > El lun, 22-08-2005 a las 13:40 +1000, Garrick Welsh escribi=C3=B3= :=20 > > I have the following problem. I have a utf-8 encoded string, > that is > > to be inserted into an Oracle DB using cx_Oracle. > > > > Now cx_Oracle appears to be configured to do a character > translation=20 > > 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=20 > > there a way to configure the encoding type that cx_Oracle > expects... > > > > Garrick > > > > -- > > Garrick Welsh > > > > The human race is a race of cowards; and I am not only > marching in=20 > > that > > procession but carrying a banner. > > -- Mark Twain > -- > Marcos S=C3=A1nchez Provencio <ma...@bu...> > =20 > =20 > =20 > -------------------------------------------------------=20 > SF.Net email is Sponsored by the Better Software Conference & > EXPO > September 19-22, 2005 * San Francisco, CA * Development > Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * > Testing & QA=20 > Security * Process Improvement & Measurement * > http://www.sqe.com/bsce5sf > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users >=20 >=20 >=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...> |