Re: [cx-oracle-users] Question concerning executemany() in cx_Oracle
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2007-02-06 18:22:25
|
On 2/6/07, matilda matilda <ma...@gr...> wrote: > Hi all, hi Anthony, Hi. > while testing some unicode and encoding related stuff > (yes Anthony, I work on that. ;-) ) I struggled over That's good. :-) > the following code: > --------------8<-------------------------------- > #!/usr/bin/python > # -*- coding: utf8 -*- > import sys > import os > import cx_Oracle as dbi > > utf8 =3D 'GERMAN_GERMANY.UTF8' > latin1 =3D 'GERMAN_GERMANY.WE8ISO8859P1' > > if __name__ =3D=3D '__main__': > os.environ['NLS_LANG'] =3D latin1 > con =3D dbi.connect('scott/tiger@twws') > cur =3D con.cursor() > a =3D u'=C4' * 4000 > u =3D u'=DC' * 4000 > o =3D u'=D6' * 4000 > ae =3D a.encode('latin1') > ue =3D u.encode('latin1') > oe =3D o.encode('latin1') > print "Length ae:", len(ae) > print "Length ue:", len(ue) > print "Length oe:", len(oe) > list =3D ( (ae,), (ue,), (oe,) ) > print type(list) > con.begin() > cur.executemany('insert into tst values (:val)', list) > con.commit() > cur.close() > con.close() > --------------8<-------------------------------- > > Running this code gives me an ugly exception: > Traceback (most recent call last): > File "./i.py", line 26, in ? > cur.executemany('insert into tst values (:val)', list) > TypeError: argument 2 must be list, not tuple > > I'm surprised: A tuple is a sequence and PEP249 > (http://www.python.org/dev/peps/pep-0249/) says: > "[...] execute it against all parameter sequences or > mappings found in the sequence seq_of_parameters.[..]" > > So, what am I missing: Please enlight me. :-)) First, your insert statement is specifying ":val" which is a named parameter. You need to specify dictionaries, then. Or you can specify ":1" and use what you have defined. Second, you need to specify a list as the top level as in list =3D [ (ae,), (ue,), (oe,) ] That should resolve your issues, I believe. > Best regards > Andreas Mock > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job ea= sier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |