Re: [cx-oracle-users] How to use unicode in the right way?
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2006-10-10 13:33:10
|
cx_Oracle currently does not support binding unicode directly. You will have to do the following: unicodeString.decode(connection.encoding) OR unicodeString.decode(connection.nencoding) depending on whether you are inserting into varchar2 or nvarchar2 This necessity will be removed at some point but I'm not sure exactly when yet. :-) I'm still learning about unicode and I don't want to do anything too hastily. On 10/8/06, Vizcayno Tamparantan <pre...@ho...> wrote: > > Hello: > I have have problems saving ascii and unicode data that contains spanish > symbols, please look at the next py25 code using last version of cx_oracl= e > under Windows XP2: > # -*- coding: utf-8 -*- > import cx_Oracle as Ora > connOra =3D Ora.connect("user", "pass", "DB") > cursOra =3D connOra.cursor() > cursOra.execute("CREATE TABLE ASCTAB (txt VARCHAR2(30))") > connOra.commit() > txt =3D "=E1=E9=ED=F3=FA > =F1=D1 > =BF?" > print "String: ", txt > cursOra.execute("INSERT INTO ASCTAB VALUES('%s')" % txt) > connOra.commit() > cursOra.execute("SELECT * FROM ASCTAB") > for i in cursOra.fetchall(): > print "DB data: ", i[0] > > cursOra.execute("CREATE TABLE UNITAB (txt NVARCHAR2(30))") > connOra.commit() > uTxt =3D unicode('"=E1=E9=ED=F3=FA > =F1=D1 > =BF?"', 'latin-1') > print "Unicode: ", uTxt > cursOra.execute("INSERT INTO UNITAB VALUES('%s')" % uTxt) > connOra.commit() > cursOra.execute("SELECT * FROM UNITAB") > for i in cursOra.fetchall(): > print i[0] > > connOra.close() > > The results I get after executing previous program are: > .python test.py > String: =DF=DA=DD=BE=B7 > =B1=D0 > +? > DB data: ????? > ?? > ?? > Unicode: "=E1=E9=ED=F3=FA > =F1=D1 > =BF?" > Traceback (most recent call last): > File "test.py", line 19, in <module> > cursOra.execute("INSERT INTO UNITAB VALUES('%s')" % uTxt) > TypeError: expecting None or a string > > SQL> select * from asctab; > > TXT > ------------------------------ > ????? > ?? > ?? > > SQL> > > > The source file test.py was saved as utf-8. > > How can I save and retrieve spanish characters in a correct way? > > Many thanks for your help. > > _________________________________________________________________ > MSN Amor: busca tu =BD naranja http://latam.msn.com/amor/ > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share y= our > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |