Thread: Re: [cx-oracle-users] wrapping curs.execute() in another function?
Brought to you by:
atuining
From: Henning v. B. <H.v...@t-...> - 2006-12-07 08:30:47
|
Hi Mark, pls try the following script: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #!/bin/env python # -*- coding: iso-8859-1 -*- # import cx_Oracle # Sample 1 def doAllCurs (curs, stmt, **args): rset =3D curs.execute (stmt, **args) for rec in curs: yield rec return # Sample 2 def doAllConn (conn, stmt, **args): curs =3D conn.cursor() for rec in doAllCurs(curs, stmt, **args): yield rec curs.close() return # Print All Records # This could perhaps be recoded in a more functional programming style def printAll (curs, stmt, **args): for rec in doAllCurs(curs, stmt, **args): print rec def test (uid, query, **bindvars): conn =3D cx_Oracle.connect(uid) curs =3D conn.cursor() printAll (curs, query, **bindvars) =20 print "" print "The first 20 records as a list:" print list (doAllCurs (curs, query, **bindvars))[:20] =20 curs.close() conn.close() # Test me if __name__ =3D=3D "__main__": import sys if len(sys.argv) > 1: uid =3D sys.argv[1] conditions =3D dict ([tuple(arg.split("=3D",1)) for arg in sys.argv[2:] ]) query =3D """ select object_name , object_type from user_objects where 1=3D1""" for nam,val in conditions.items(): query +=3D ("\n and %s =3D :%s" % (nam,nam)) print "Query:" print query print "*" * 70 print "Bind Vars:" for nam,val in conditions.items(): print "%-20s =3D %r" % (nam,val) print "*" * 70 test (uid, query, **conditions); else: print "Test me like this:" print "%s uid/pwd@dbs object_type=3DTABLE" % sys.argv[0] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Just save it as test.py, then call it like test.py userid/password@database object_type=3DTABLE or, with other condiditons: test.py userid/password@database object_type=3DTABLE object_name=3DXYZ (This will probably not return any results) HTH Henning |
From: Henning v. B. <H.v...@t-...> - 2006-12-07 17:35:32
|
Peter Masiar asked: > ... > SQL statement: SELECT x neuron FROM TABLE(SDO_RDF_MATCH( '(?x r:type c:neuron)', SDO_RDF_Models('senselab3'), SDO_RDF_Rulebases('RDFS','senselab3_rb'), SDO_RDF_Aliases(SDO_RDF_Alias('c','http://senselab.med.yale.edu/class#') , SDO_RDF_Alias('i','http://senselab.med.yale.edu/instance#'), SDO_RDF_Alias('r','http://www.w3.org/1999/02/22-rdf-syntax-ns#') ), null)); > ... > DatabaseError: ORA-00911: invalid character Peter, you should not use the semicolon, it is not part of SQL, but rather it is used in SQL*Plus and PL/SQL to delimit statement. Try without it. HtH Henning |
From: D.R. B. <da...@as...> - 2007-01-12 14:50:17
|
When fetching a NaN number (nan in Python) from a BINARY_FLOAT or BINARY_DOUBLE column, the following exception is raised. Traceback (most recent call last): File "<stdin>", line 1, in ? cx_Oracle.DatabaseError: ORA-01722: invalid number Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or BINARY_DOUBLE column results in Traceback (most recent call last): File "<stdin>", line 1, in ? cx_Oracle.DatabaseError: OCI-22065: number to text translation for the given format causes overflow Inserting Infinity and NaN, however, works flawlessly. I've only tried this for cx_Oracle 4.2.1 & 4.1.2, Python 2.3 and Oracle 10gR2, but it would not be surprising if other combinations show the same behaviour. Does anyone have an idea for a solution or clever workaround? Thanks Danny Using cx_Oracle 4.2.1 On Thu, Dec 07, 2006 at 09:30:17AM +0100, Henning von Bargen wrote: > Hi Mark, > > pls try the following script: > ============================================= > > #!/bin/env python > # -*- coding: iso-8859-1 -*- > # > import cx_Oracle > > # Sample 1 > def doAllCurs (curs, stmt, **args): > rset = curs.execute (stmt, **args) > for rec in curs: > yield rec > return > > # Sample 2 > def doAllConn (conn, stmt, **args): > curs = conn.cursor() > for rec in doAllCurs(curs, stmt, **args): > yield rec > curs.close() > return > > # Print All Records > # This could perhaps be recoded in a more functional programming style > def printAll (curs, stmt, **args): > for rec in doAllCurs(curs, stmt, **args): > print rec > > def test (uid, query, **bindvars): > conn = cx_Oracle.connect(uid) > curs = conn.cursor() > printAll (curs, query, **bindvars) > > print "" > print "The first 20 records as a list:" > print list (doAllCurs (curs, query, **bindvars))[:20] > > curs.close() > conn.close() > > # Test me > if __name__ == "__main__": > import sys > if len(sys.argv) > 1: > uid = sys.argv[1] > conditions = dict ([tuple(arg.split("=",1)) > for arg in sys.argv[2:] > ]) > query = """ > select object_name > , object_type > from user_objects > where 1=1""" > for nam,val in conditions.items(): > query += ("\n and %s = :%s" % (nam,nam)) > print "Query:" > print query > print "*" * 70 > print "Bind Vars:" > for nam,val in conditions.items(): > print "%-20s = %r" % (nam,val) > print "*" * 70 > test (uid, query, **conditions); > else: > print "Test me like this:" > print "%s uid/pwd@dbs object_type=TABLE" % sys.argv[0] > > ============================================= > > Just save it as test.py, then call it like > test.py userid/password@database object_type=TABLE > > or, with other condiditons: > test.py userid/password@database object_type=TABLE object_name=XYZ > (This will probably not return any results) > > HTH > Henning > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users |
From: Amaury F. d'A. <ama...@gm...> - 2007-01-18 09:34:21
|
Hello, Boxhoorn wrote: > > When fetching a NaN number (nan in Python) from a BINARY_FLOAT or BINARY_DOUBLE > column, the following exception is raised. > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > cx_Oracle.DatabaseError: ORA-01722: invalid number > > Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or BINARY_DOUBLE > column results in > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > cx_Oracle.DatabaseError: OCI-22065: number to text translation for the given format causes overflow > > Inserting Infinity and NaN, however, works flawlessly. cx_Oracle always uses the OciNumber type to exchange numeric values with the database (this is the C equivalent of the NUMBER datatype). Here the error messages comes from the oci layer trying to convert your data into NUMBER values. Well, this won't help you, but I remember Anthony's proposal about following more closely the Python type when creating bind variables: http://sourceforge.net/mailarchive/forum.php?thread_id=30737382&forum_id=34464 I don't know how far he went in this direction, but an easy addition to his proposal is to create a BINARY_DOUBLE bind variable when the python type is 'double'. Then special values should pass unmodified from the database to the python client. Maybe wait for a future relase? -- Amaury Forgeot d'Arc |
From: Jeanne d' A. H. <Jeanned'<Arc...@In...> - 2007-05-30 22:55:22
|
Hello, How=20to=20call=20a=20procedure=20having=20array=20as=20out=20parameter? I=20tried=20the=20below,=20but=20it=20doesn't=20work.=20There=20is=20no=20= cx_oracle.ARRAY rem_det=20=3D=20curs.var(cx_oracle.NUMBER) curs.execute("BEGIN=20ValidateEmail(:1,=20:2,=20:3);=20END;", =20=20=20=20=20=20=20=20=20=20=20=20=20=20[int(num),=20msg,=20(rem_det)]) Rem_det=20is=20the=20out=20array=20parameter Thanks, Jeanne Interconex=20is=20committed=20to=20providing=20outstanding=20service=20to=20= all=20of=20it=20clients,=20customers,=20and=20colleagues.=20=20This=20e-ma= il=20has=20been=20scanned=20by=20MCI=20Managed=20Email=20Content=20Service= ,=20using=20Skeptic(tm)=20technology=20powered=20by=20MessageLabs=20and=20= is=20free=20of=20any=20viruses. |
From: Anthony T. <ant...@gm...> - 2007-05-31 02:32:19
|
You need to do the following: rem_det = cursor.arrayvar(cx_Oracle.NUMBER, 15) If you want to allocate space for up to 15 elements being returned. Change that number as needed. Make sense? On 5/30/07, Jeanne d' Arc Halabi <Jeanned'Arc...@in...> wrote: > Hello, > > How to call a procedure having array as out parameter? > > I tried the below, but it doesn't work. There is no cx_oracle.ARRAY > > rem_det = curs.var(cx_oracle.NUMBER) > curs.execute("BEGIN ValidateEmail(:1, :2, :3); END;", > [int(num), msg, (rem_det)]) > > Rem_det is the out array parameter > > Thanks, > > Jeanne > > Interconex is committed to providing outstanding service to all of it clients, customers, and colleagues. This e-mail has been scanned by MCI Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs and is free of any viruses. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |
From: Jeanne d' A. H. <Jeanned'<Arc...@In...> - 2007-05-31 17:57:48
|
Hi=20Anthony, =20 Thanks=20for=20your=20input.=20This=20worked=20after=20I=20changed=20the=20= Array=20from=20SQL=20to PL/SQL.=20I=20also=20called=20package=20instead=20of=20procedure. =20 remdet=20=3D=20curs.arrayvar(cx_Oracle.NUMBER,=2015) curs.execute("DECLARE=20remdet=20ValidateAMS.memoarray;BEGIN ValidateAMS.ValidateEmail(:1,=20:2,=20:3);=20END;", =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20[i= nt(num),=20msg.get('Message-ID'),=20remdet]) =20 =20 Thanks, =20 Jeanne=20 =20 =20 -----Original=20Message----- From:=20c...@li... [mailto:cx-...@li...]=20On=20Behalf=20Of Anthony=20Tuininga Sent:=20Wednesday,=20May=2030,=202007=209:32=20PM To:=20c...@li... Subject:=20Re:=20[cx-oracle-users]=20Callable=20procedure=20with=20array=20= out parameter =20 You=20need=20to=20do=20the=20following: =20 rem_det=20=3D=20cursor.arrayvar(cx_Oracle.NUMBER,=2015) =20 If=20you=20want=20to=20allocate=20space=20for=20up=20to=2015=20elements=20= being=20returned. Change=20that=20number=20as=20needed.=20Make=20sense? =20 On=205/30/07,=20Jeanne=20d'=20Arc=20Halabi=20<Jeanned'Arc.Halabi@intercone= x.com> wrote: >=20Hello, >=20 >=20How=20to=20call=20a=20procedure=20having=20array=20as=20out=20paramete= r? >=20 >=20I=20tried=20the=20below,=20but=20it=20doesn't=20work.=20There=20is=20n= o=20cx_oracle.ARRAY >=20 >=20rem_det=20=3D=20curs.var(cx_oracle.NUMBER) >=20curs.execute("BEGIN=20ValidateEmail(:1,=20:2,=20:3);=20END;", >=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20[int(num),=20msg,=20(rem_det= )]) >=20 >=20Rem_det=20is=20the=20out=20array=20parameter >=20 >=20Thanks, >=20 >=20Jeanne >=20 >=20Interconex=20is=20committed=20to=20providing=20outstanding=20service=20= to=20all=20of=20it clients,=20customers,=20and=20colleagues.=20=20This=20e-mail=20has=20been=20= scanned=20by=20MCI Managed=20Email=20Content=20Service,=20using=20Skeptic(tm)=20technology=20= powered=20by MessageLabs=20and=20is=20free=20of=20any=20viruses. >=20 > ------------------------------------------------------------------------ - >=20This=20SF.net=20email=20is=20sponsored=20by=20DB2=20Express >=20Download=20DB2=20Express=20C=20-=20the=20FREE=20version=20of=20DB2=20e= xpress=20and=20take >=20control=20of=20your=20XML.=20No=20limits.=20Just=20data.=20Click=20to=20= get=20it=20now. >=20http://sourceforge.net/powerbar/db2/ >=20_______________________________________________ >=20cx-oracle-users=20mailing=20list >=20c...@li... >=20https://lists.sourceforge.net/lists/listinfo/cx-oracle-users >=20 =20 ------------------------------------------------------------------------ - This=20SF.net=20email=20is=20sponsored=20by=20DB2=20Express Download=20DB2=20Express=20C=20-=20the=20FREE=20version=20of=20DB2=20expre= ss=20and=20take control=20of=20your=20XML.=20No=20limits.=20Just=20data.=20Click=20to=20ge= t=20it=20now. http://sourceforge.net/powerbar/db2/ _______________________________________________ cx-oracle-users=20mailing=20list cx-...@li... https://lists.sourceforge.net/lists/listinfo/cx-oracle-users Interconex=20is=20committed=20to=20providing=20outstanding=20service=20to=20= all=20of=20it=20clients,=20customers,=20and=20colleagues.=20=20This=20e-ma= il=20has=20been=20scanned=20by=20MCI=20Managed=20Email=20Content=20Service= ,=20using=20Skeptic(tm)=20technology=20powered=20by=20MessageLabs=20and=20= is=20free=20of=20any=20viruses. |
From: Anthony T. <ant...@gm...> - 2007-05-31 19:44:08
|
You're welcome. If you're looking for the ability to create SQL arrays I haven't (yet) added that to cx_Oracle. I hope to be able to do so, however, as it solves the problem of having to know the maximum size of the array before making the call. In the meantime, use PL/SQL arrays like you are now doing. On 5/31/07, Jeanne d' Arc Halabi <Jeanned'Arc...@in...> wrote: > > Hi Anthony, > > Thanks for your input. This worked after I changed the Array from SQL to > PL/SQL. I also called package instead of procedure. > > remdet = curs.arrayvar(cx_Oracle.NUMBER, 15) > > curs.execute("DECLARE remdet ValidateAMS.memoarray;BEGIN > ValidateAMS.ValidateEmail(:1, :2, :3); END;", > > [int(num), msg.get('Message-ID'), remdet]) > > > > > > > Thanks, > > > > Jeanne > > > > > > > -----Original Message----- > From: cx-...@li... > [mailto:cx-...@li...] On > Behalf Of Anthony Tuininga > Sent: Wednesday, May 30, 2007 9:32 PM > To: cx-...@li... > Subject: Re: [cx-oracle-users] Callable procedure with array out parameter > > > > You need to do the following: > > > > rem_det = cursor.arrayvar(cx_Oracle.NUMBER, 15) > > > > If you want to allocate space for up to 15 elements being returned. > > Change that number as needed. Make sense? > > > > On 5/30/07, Jeanne d' Arc Halabi <Jeanned'Arc...@in...> wrote: > > > Hello, > > > > > > How to call a procedure having array as out parameter? > > > > > > I tried the below, but it doesn't work. There is no cx_oracle.ARRAY > > > > > > rem_det = curs.var(cx_oracle.NUMBER) > > > curs.execute("BEGIN ValidateEmail(:1, :2, :3); END;", > > > [int(num), msg, (rem_det)]) > > > > > > Rem_det is the out array parameter > > > > > > Thanks, > > > > > > Jeanne > > > > > > Interconex is committed to providing outstanding service to all of it > clients, customers, and colleagues. This e-mail has been scanned by MCI > Managed Email Content Service, using Skeptic(tm) technology powered by > MessageLabs and is free of any viruses. > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by DB2 Express > > > Download DB2 Express C - the FREE version of DB2 express and take > > > control of your XML. No limits. Just data. Click to get it now. > > > http://sourceforge.net/powerbar/db2/ > > > _______________________________________________ > > > cx-oracle-users mailing list > > > cx-...@li... > > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > cx-oracle-users mailing list > > cx-...@li... > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > Interconex is committed to providing outstanding service to all of it > clients, customers, and colleagues. This e-mail has been scanned by MCI > Managed Email Content Service, using Skeptic(tm) technology powered by > MessageLabs and is free of any viruses. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > |
From: Anthony T. <ant...@gm...> - 2007-01-31 23:31:25
|
I'm assuming the attached script yields these errors but unfortunately I don't know which incantation is necessary (which parameters to pass) in order to get the associated error. Can you enlighten me? Thank you. On 1/12/07, D.R. Boxhoorn <da...@as...> wrote: > > When fetching a NaN number (nan in Python) from a BINARY_FLOAT or BINARY_DOUBLE > column, the following exception is raised. > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > cx_Oracle.DatabaseError: ORA-01722: invalid number > > Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or BINARY_DOUBLE > column results in > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > cx_Oracle.DatabaseError: OCI-22065: number to text translation for the given format causes overflow > > Inserting Infinity and NaN, however, works flawlessly. > > > I've only tried this for cx_Oracle 4.2.1 & 4.1.2, Python 2.3 and Oracle 10gR2, > but it would not be surprising if other combinations show the same behaviour. > > Does anyone have an idea for a solution or clever workaround? > > Thanks > > Danny > > > Using cx_Oracle 4.2.1 > On Thu, Dec 07, 2006 at 09:30:17AM +0100, Henning von Bargen wrote: > > Hi Mark, > > > > pls try the following script: > > ============================================= > > > > #!/bin/env python > > # -*- coding: iso-8859-1 -*- > > # > > import cx_Oracle > > > > # Sample 1 > > def doAllCurs (curs, stmt, **args): > > rset = curs.execute (stmt, **args) > > for rec in curs: > > yield rec > > return > > > > # Sample 2 > > def doAllConn (conn, stmt, **args): > > curs = conn.cursor() > > for rec in doAllCurs(curs, stmt, **args): > > yield rec > > curs.close() > > return > > > > # Print All Records > > # This could perhaps be recoded in a more functional programming style > > def printAll (curs, stmt, **args): > > for rec in doAllCurs(curs, stmt, **args): > > print rec > > > > def test (uid, query, **bindvars): > > conn = cx_Oracle.connect(uid) > > curs = conn.cursor() > > printAll (curs, query, **bindvars) > > > > print "" > > print "The first 20 records as a list:" > > print list (doAllCurs (curs, query, **bindvars))[:20] > > > > curs.close() > > conn.close() > > > > # Test me > > if __name__ == "__main__": > > import sys > > if len(sys.argv) > 1: > > uid = sys.argv[1] > > conditions = dict ([tuple(arg.split("=",1)) > > for arg in sys.argv[2:] > > ]) > > query = """ > > select object_name > > , object_type > > from user_objects > > where 1=1""" > > for nam,val in conditions.items(): > > query += ("\n and %s = :%s" % (nam,nam)) > > print "Query:" > > print query > > print "*" * 70 > > print "Bind Vars:" > > for nam,val in conditions.items(): > > print "%-20s = %r" % (nam,val) > > print "*" * 70 > > test (uid, query, **conditions); > > else: > > print "Test me like this:" > > print "%s uid/pwd@dbs object_type=TABLE" % sys.argv[0] > > > > ============================================= > > > > Just save it as test.py, then call it like > > test.py userid/password@database object_type=TABLE > > > > or, with other condiditons: > > test.py userid/password@database object_type=TABLE object_name=XYZ > > (This will probably not return any results) > > > > HTH > > Henning > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share your > > opinions on IT & business topics through brief surveys - and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > cx-oracle-users mailing list > > cx-...@li... > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |
From: D.R. B. <da...@as...> - 2007-02-01 11:08:05
|
Good morning Anthony, Below you'll find a - hopefully - self-contained example to reproduce the errors that can be caused by fetching NaN and Infinity as "binary" doubles and floats. I have the impression that this cannot be solved with a just few lines of C code, but you are the expert here. :) Ciao, Danny ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import struct, sys import cx_Oracle connectstring = 'user/password@tnsname' # Clumsy way to obtain Infinity and NaN as float and double floatinf, = struct.unpack('f', struct.pack('L', 0x7F800000)) floatnan, = struct.unpack('f', struct.pack('L', 0x7F800001)) doubleinf, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000000L)) doublenan, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000001L)) assert str(floatinf) == 'inf', 'floatinf is not "inf", but %s' % floatinf assert str(floatnan) == 'nan', 'floatnan is not "nan", but %s' % floatnan assert str(doubleinf) == 'inf', 'doubleinf is not "inf", but %s' % doubleinf assert str(doublenan) == 'nan', 'doublenan is not "inf", but %s' % doublenan # Get Infinity and NaN as constants to trigger exceptions connection = cx_Oracle.connect(connectstring) cursor = connection.cursor() for typeconversion in ['TO_BINARY_DOUBLE', 'TO_BINARY_FLOAT']: for number in ['floatinf', 'floatnan', 'doubleinf', 'doublenan']: print 'Trying %(typeconversion)s for %(number)s' % vars() cursor.execute('SELECT %(typeconversion)s(:1) FROM DUAL' % vars(), [eval(number)]) try: cursor.fetchone() print 'Ok' except cx_Oracle.DatabaseError, e: print e cursor.close() connection.close() # Expected output # Trying TO_BINARY_DOUBLE for floatinf # OCI-22065: number to text translation for the given format causes overflow # # Trying TO_BINARY_DOUBLE for floatnan # ORA-01722: invalid number # # Trying TO_BINARY_DOUBLE for doubleinf # OCI-22065: number to text translation for the given format causes overflow # # Trying TO_BINARY_DOUBLE for doublenan # ORA-01722: invalid number # # Trying TO_BINARY_FLOAT for floatinf # OCI-22065: number to text translation for the given format causes overflow # # Trying TO_BINARY_FLOAT for floatnan # ORA-01722: invalid number # # Trying TO_BINARY_FLOAT for doubleinf # OCI-22065: number to text translation for the given format causes overflow # # Trying TO_BINARY_FLOAT for doublenan # ORA-01722: invalid number -------------------------------------------------------------------------------- On Wed, Jan 31, 2007 at 04:31:21PM -0700, Anthony Tuininga wrote: > I'm assuming the attached script yields these errors but unfortunately > I don't know which incantation is necessary (which parameters to pass) > in order to get the associated error. Can you enlighten me? Thank you. > > On 1/12/07, D.R. Boxhoorn <da...@as...> wrote: > > > >When fetching a NaN number (nan in Python) from a BINARY_FLOAT or > >BINARY_DOUBLE > >column, the following exception is raised. > > > > Traceback (most recent call last): > > File "<stdin>", line 1, in ? > > cx_Oracle.DatabaseError: ORA-01722: invalid number > > > >Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or > >BINARY_DOUBLE > >column results in > > > > Traceback (most recent call last): > > File "<stdin>", line 1, in ? > > cx_Oracle.DatabaseError: OCI-22065: number to text translation for the > > given format causes overflow > > > >Inserting Infinity and NaN, however, works flawlessly. > > > > > >I've only tried this for cx_Oracle 4.2.1 & 4.1.2, Python 2.3 and Oracle > >10gR2, > >but it would not be surprising if other combinations show the same > >behaviour. > > > >Does anyone have an idea for a solution or clever workaround? > > > >Thanks > > > > Danny > > > > > >Using cx_Oracle 4.2.1 > >On Thu, Dec 07, 2006 at 09:30:17AM +0100, Henning von Bargen wrote: > >> Hi Mark, > >> > >> pls try the following script: > >> ============================================= > >> > >> #!/bin/env python > >> # -*- coding: iso-8859-1 -*- > >> # > >> import cx_Oracle > >> > >> # Sample 1 > >> def doAllCurs (curs, stmt, **args): > >> rset = curs.execute (stmt, **args) > >> for rec in curs: > >> yield rec > >> return > >> > >> # Sample 2 > >> def doAllConn (conn, stmt, **args): > >> curs = conn.cursor() > >> for rec in doAllCurs(curs, stmt, **args): > >> yield rec > >> curs.close() > >> return > >> > >> # Print All Records > >> # This could perhaps be recoded in a more functional programming style > >> def printAll (curs, stmt, **args): > >> for rec in doAllCurs(curs, stmt, **args): > >> print rec > >> > >> def test (uid, query, **bindvars): > >> conn = cx_Oracle.connect(uid) > >> curs = conn.cursor() > >> printAll (curs, query, **bindvars) > >> > >> print "" > >> print "The first 20 records as a list:" > >> print list (doAllCurs (curs, query, **bindvars))[:20] > >> > >> curs.close() > >> conn.close() > >> > >> # Test me > >> if __name__ == "__main__": > >> import sys > >> if len(sys.argv) > 1: > >> uid = sys.argv[1] > >> conditions = dict ([tuple(arg.split("=",1)) > >> for arg in sys.argv[2:] > >> ]) > >> query = """ > >> select object_name > >> , object_type > >> from user_objects > >> where 1=1""" > >> for nam,val in conditions.items(): > >> query += ("\n and %s = :%s" % (nam,nam)) > >> print "Query:" > >> print query > >> print "*" * 70 > >> print "Bind Vars:" > >> for nam,val in conditions.items(): > >> print "%-20s = %r" % (nam,val) > >> print "*" * 70 > >> test (uid, query, **conditions); > >> else: > >> print "Test me like this:" > >> print "%s uid/pwd@dbs object_type=TABLE" % sys.argv[0] > >> > >> ============================================= > >> > >> Just save it as test.py, then call it like > >> test.py userid/password@database object_type=TABLE > >> > >> or, with other condiditons: > >> test.py userid/password@database object_type=TABLE object_name=XYZ > >> (This will probably not return any results) > >> > >> HTH > >> Henning > >> > >> ------------------------------------------------------------------------- > >> Take Surveys. Earn Cash. Influence the Future of IT > >> Join SourceForge.net's Techsay panel and you'll get the chance to share > >your > >> opinions on IT & business topics through brief surveys - and earn cash > >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >> _______________________________________________ > >> cx-oracle-users mailing list > >> cx-...@li... > >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > >------------------------------------------------------------------------- > >Take Surveys. Earn Cash. Influence the Future of IT > >Join SourceForge.net's Techsay panel and you'll get the chance to share > >your > >opinions on IT & business topics through brief surveys - and earn cash > >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >_______________________________________________ > >cx-oracle-users mailing list > >cx-...@li... > >https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > |
From: Anthony T. <ant...@gm...> - 2007-02-03 19:23:20
|
Thank you for the simple test case. :-) I've managed to now implement this so that when native doubles or floats are returned from an Oracle 10g database they are automatically returned as a native float or double without any unnecessary conversion process. I have __NOT__ done the same for binding, however, because of the fact that you cannot use those types when using an Oracle 10g client against an Oracle 9i server. Did you want a patch for this or do you want to wait until I make the next release -- hopefully in the next couple of weeks. On 2/1/07, D.R. Boxhoorn <da...@as...> wrote: > > Good morning Anthony, > > Below you'll find a - hopefully - self-contained example to reproduce > the errors that can be caused by fetching NaN and Infinity as "binary" > doubles and floats. > I have the impression that this cannot be solved with a just few lines of > C code, but you are the expert here. :) > > Ciao, > > Danny > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > import struct, sys > import cx_Oracle > > connectstring = 'user/password@tnsname' > > # Clumsy way to obtain Infinity and NaN as float and double > floatinf, = struct.unpack('f', struct.pack('L', 0x7F800000)) > floatnan, = struct.unpack('f', struct.pack('L', 0x7F800001)) > doubleinf, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000000L)) > doublenan, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000001L)) > > assert str(floatinf) == 'inf', 'floatinf is not "inf", but %s' % floatinf > assert str(floatnan) == 'nan', 'floatnan is not "nan", but %s' % floatnan > assert str(doubleinf) == 'inf', 'doubleinf is not "inf", but %s' % doubleinf > assert str(doublenan) == 'nan', 'doublenan is not "inf", but %s' % doublenan > > # Get Infinity and NaN as constants to trigger exceptions > connection = cx_Oracle.connect(connectstring) > cursor = connection.cursor() > > for typeconversion in ['TO_BINARY_DOUBLE', 'TO_BINARY_FLOAT']: > for number in ['floatinf', 'floatnan', 'doubleinf', 'doublenan']: > print 'Trying %(typeconversion)s for %(number)s' % vars() > cursor.execute('SELECT %(typeconversion)s(:1) FROM DUAL' % vars(), [eval(number)]) > try: > cursor.fetchone() > print 'Ok' > except cx_Oracle.DatabaseError, e: > print e > > cursor.close() > connection.close() > > # Expected output > # Trying TO_BINARY_DOUBLE for floatinf > # OCI-22065: number to text translation for the given format causes overflow > # > # Trying TO_BINARY_DOUBLE for floatnan > # ORA-01722: invalid number > # > # Trying TO_BINARY_DOUBLE for doubleinf > # OCI-22065: number to text translation for the given format causes overflow > # > # Trying TO_BINARY_DOUBLE for doublenan > # ORA-01722: invalid number > # > # Trying TO_BINARY_FLOAT for floatinf > # OCI-22065: number to text translation for the given format causes overflow > # > # Trying TO_BINARY_FLOAT for floatnan > # ORA-01722: invalid number > # > # Trying TO_BINARY_FLOAT for doubleinf > # OCI-22065: number to text translation for the given format causes overflow > # > # Trying TO_BINARY_FLOAT for doublenan > # ORA-01722: invalid number > -------------------------------------------------------------------------------- > > On Wed, Jan 31, 2007 at 04:31:21PM -0700, Anthony Tuininga wrote: > > I'm assuming the attached script yields these errors but unfortunately > > I don't know which incantation is necessary (which parameters to pass) > > in order to get the associated error. Can you enlighten me? Thank you. > > > > On 1/12/07, D.R. Boxhoorn <da...@as...> wrote: > > > > > >When fetching a NaN number (nan in Python) from a BINARY_FLOAT or > > >BINARY_DOUBLE > > >column, the following exception is raised. > > > > > > Traceback (most recent call last): > > > File "<stdin>", line 1, in ? > > > cx_Oracle.DatabaseError: ORA-01722: invalid number > > > > > >Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or > > >BINARY_DOUBLE > > >column results in > > > > > > Traceback (most recent call last): > > > File "<stdin>", line 1, in ? > > > cx_Oracle.DatabaseError: OCI-22065: number to text translation for the > > > given format causes overflow > > > > > >Inserting Infinity and NaN, however, works flawlessly. > > > > > > > > >I've only tried this for cx_Oracle 4.2.1 & 4.1.2, Python 2.3 and Oracle > > >10gR2, > > >but it would not be surprising if other combinations show the same > > >behaviour. > > > > > >Does anyone have an idea for a solution or clever workaround? > > > > > >Thanks > > > > > > Danny > > > > > > > > >Using cx_Oracle 4.2.1 > > >On Thu, Dec 07, 2006 at 09:30:17AM +0100, Henning von Bargen wrote: > > >> Hi Mark, > > >> > > >> pls try the following script: > > >> ============================================= > > >> > > >> #!/bin/env python > > >> # -*- coding: iso-8859-1 -*- > > >> # > > >> import cx_Oracle > > >> > > >> # Sample 1 > > >> def doAllCurs (curs, stmt, **args): > > >> rset = curs.execute (stmt, **args) > > >> for rec in curs: > > >> yield rec > > >> return > > >> > > >> # Sample 2 > > >> def doAllConn (conn, stmt, **args): > > >> curs = conn.cursor() > > >> for rec in doAllCurs(curs, stmt, **args): > > >> yield rec > > >> curs.close() > > >> return > > >> > > >> # Print All Records > > >> # This could perhaps be recoded in a more functional programming style > > >> def printAll (curs, stmt, **args): > > >> for rec in doAllCurs(curs, stmt, **args): > > >> print rec > > >> > > >> def test (uid, query, **bindvars): > > >> conn = cx_Oracle.connect(uid) > > >> curs = conn.cursor() > > >> printAll (curs, query, **bindvars) > > >> > > >> print "" > > >> print "The first 20 records as a list:" > > >> print list (doAllCurs (curs, query, **bindvars))[:20] > > >> > > >> curs.close() > > >> conn.close() > > >> > > >> # Test me > > >> if __name__ == "__main__": > > >> import sys > > >> if len(sys.argv) > 1: > > >> uid = sys.argv[1] > > >> conditions = dict ([tuple(arg.split("=",1)) > > >> for arg in sys.argv[2:] > > >> ]) > > >> query = """ > > >> select object_name > > >> , object_type > > >> from user_objects > > >> where 1=1""" > > >> for nam,val in conditions.items(): > > >> query += ("\n and %s = :%s" % (nam,nam)) > > >> print "Query:" > > >> print query > > >> print "*" * 70 > > >> print "Bind Vars:" > > >> for nam,val in conditions.items(): > > >> print "%-20s = %r" % (nam,val) > > >> print "*" * 70 > > >> test (uid, query, **conditions); > > >> else: > > >> print "Test me like this:" > > >> print "%s uid/pwd@dbs object_type=TABLE" % sys.argv[0] > > >> > > >> ============================================= > > >> > > >> Just save it as test.py, then call it like > > >> test.py userid/password@database object_type=TABLE > > >> > > >> or, with other condiditons: > > >> test.py userid/password@database object_type=TABLE object_name=XYZ > > >> (This will probably not return any results) > > >> > > >> HTH > > >> Henning > > >> > > >> ------------------------------------------------------------------------- > > >> Take Surveys. Earn Cash. Influence the Future of IT > > >> Join SourceForge.net's Techsay panel and you'll get the chance to share > > >your > > >> opinions on IT & business topics through brief surveys - and earn cash > > >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > >> _______________________________________________ > > >> cx-oracle-users mailing list > > >> cx-...@li... > > >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > >------------------------------------------------------------------------- > > >Take Surveys. Earn Cash. Influence the Future of IT > > >Join SourceForge.net's Techsay panel and you'll get the chance to share > > >your > > >opinions on IT & business topics through brief surveys - and earn cash > > >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > >_______________________________________________ > > >cx-oracle-users mailing list > > >cx-...@li... > > >https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > |
From: D.R. B. <da...@as...> - 2007-02-05 08:44:59
|
Thank you very much Anthony! We can wait for the next release and don't need a patch (I hope :). Thanks again, Danny On Sat, Feb 03, 2007 at 12:23:16PM -0700, Anthony Tuininga wrote: > Thank you for the simple test case. :-) I've managed to now implement > this so that when native doubles or floats are returned from an Oracle > 10g database they are automatically returned as a native float or > double without any unnecessary conversion process. I have __NOT__ done > the same for binding, however, because of the fact that you cannot use > those types when using an Oracle 10g client against an Oracle 9i > server. Did you want a patch for this or do you want to wait until I > make the next release -- hopefully in the next couple of weeks. > > On 2/1/07, D.R. Boxhoorn <da...@as...> wrote: > > > > Good morning Anthony, > > > > Below you'll find a - hopefully - self-contained example to reproduce > > the errors that can be caused by fetching NaN and Infinity as "binary" > > doubles and floats. > > I have the impression that this cannot be solved with a just few lines of > > C code, but you are the expert here. :) > > > > Ciao, > > > > Danny > > > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > import struct, sys > > import cx_Oracle > > > > connectstring = 'user/password@tnsname' > > > > # Clumsy way to obtain Infinity and NaN as float and double > > floatinf, = struct.unpack('f', struct.pack('L', 0x7F800000)) > > floatnan, = struct.unpack('f', struct.pack('L', 0x7F800001)) > > doubleinf, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000000L)) > > doublenan, = struct.unpack('d', struct.pack('Q', 0x7FF0000000000001L)) > > > > assert str(floatinf) == 'inf', 'floatinf is not "inf", but %s' % floatinf > > assert str(floatnan) == 'nan', 'floatnan is not "nan", but %s' % floatnan > > assert str(doubleinf) == 'inf', 'doubleinf is not "inf", but %s' % doubleinf > > assert str(doublenan) == 'nan', 'doublenan is not "inf", but %s' % doublenan > > > > # Get Infinity and NaN as constants to trigger exceptions > > connection = cx_Oracle.connect(connectstring) > > cursor = connection.cursor() > > > > for typeconversion in ['TO_BINARY_DOUBLE', 'TO_BINARY_FLOAT']: > > for number in ['floatinf', 'floatnan', 'doubleinf', 'doublenan']: > > print 'Trying %(typeconversion)s for %(number)s' % vars() > > cursor.execute('SELECT %(typeconversion)s(:1) FROM DUAL' % vars(), [eval(number)]) > > try: > > cursor.fetchone() > > print 'Ok' > > except cx_Oracle.DatabaseError, e: > > print e > > > > cursor.close() > > connection.close() > > > > # Expected output > > # Trying TO_BINARY_DOUBLE for floatinf > > # OCI-22065: number to text translation for the given format causes overflow > > # > > # Trying TO_BINARY_DOUBLE for floatnan > > # ORA-01722: invalid number > > # > > # Trying TO_BINARY_DOUBLE for doubleinf > > # OCI-22065: number to text translation for the given format causes overflow > > # > > # Trying TO_BINARY_DOUBLE for doublenan > > # ORA-01722: invalid number > > # > > # Trying TO_BINARY_FLOAT for floatinf > > # OCI-22065: number to text translation for the given format causes overflow > > # > > # Trying TO_BINARY_FLOAT for floatnan > > # ORA-01722: invalid number > > # > > # Trying TO_BINARY_FLOAT for doubleinf > > # OCI-22065: number to text translation for the given format causes overflow > > # > > # Trying TO_BINARY_FLOAT for doublenan > > # ORA-01722: invalid number > > -------------------------------------------------------------------------------- > > > > On Wed, Jan 31, 2007 at 04:31:21PM -0700, Anthony Tuininga wrote: > > > I'm assuming the attached script yields these errors but unfortunately > > > I don't know which incantation is necessary (which parameters to pass) > > > in order to get the associated error. Can you enlighten me? Thank you. > > > > > > On 1/12/07, D.R. Boxhoorn <da...@as...> wrote: > > > > > > > >When fetching a NaN number (nan in Python) from a BINARY_FLOAT or > > > >BINARY_DOUBLE > > > >column, the following exception is raised. > > > > > > > > Traceback (most recent call last): > > > > File "<stdin>", line 1, in ? > > > > cx_Oracle.DatabaseError: ORA-01722: invalid number > > > > > > > >Similary, fetching Infinity (inf in Python) from a BINARY_FLOAT or > > > >BINARY_DOUBLE > > > >column results in > > > > > > > > Traceback (most recent call last): > > > > File "<stdin>", line 1, in ? > > > > cx_Oracle.DatabaseError: OCI-22065: number to text translation for the > > > > given format causes overflow > > > > > > > >Inserting Infinity and NaN, however, works flawlessly. > > > > > > > > > > > >I've only tried this for cx_Oracle 4.2.1 & 4.1.2, Python 2.3 and Oracle > > > >10gR2, > > > >but it would not be surprising if other combinations show the same > > > >behaviour. > > > > > > > >Does anyone have an idea for a solution or clever workaround? > > > > > > > >Thanks > > > > > > > > Danny > > > > > > > > > > > >Using cx_Oracle 4.2.1 > > > >On Thu, Dec 07, 2006 at 09:30:17AM +0100, Henning von Bargen wrote: > > > >> Hi Mark, > > > >> > > > >> pls try the following script: > > > >> ============================================= > > > >> > > > >> #!/bin/env python > > > >> # -*- coding: iso-8859-1 -*- > > > >> # > > > >> import cx_Oracle > > > >> > > > >> # Sample 1 > > > >> def doAllCurs (curs, stmt, **args): > > > >> rset = curs.execute (stmt, **args) > > > >> for rec in curs: > > > >> yield rec > > > >> return > > > >> > > > >> # Sample 2 > > > >> def doAllConn (conn, stmt, **args): > > > >> curs = conn.cursor() > > > >> for rec in doAllCurs(curs, stmt, **args): > > > >> yield rec > > > >> curs.close() > > > >> return > > > >> > > > >> # Print All Records > > > >> # This could perhaps be recoded in a more functional programming style > > > >> def printAll (curs, stmt, **args): > > > >> for rec in doAllCurs(curs, stmt, **args): > > > >> print rec > > > >> > > > >> def test (uid, query, **bindvars): > > > >> conn = cx_Oracle.connect(uid) > > > >> curs = conn.cursor() > > > >> printAll (curs, query, **bindvars) > > > >> > > > >> print "" > > > >> print "The first 20 records as a list:" > > > >> print list (doAllCurs (curs, query, **bindvars))[:20] > > > >> > > > >> curs.close() > > > >> conn.close() > > > >> > > > >> # Test me > > > >> if __name__ == "__main__": > > > >> import sys > > > >> if len(sys.argv) > 1: > > > >> uid = sys.argv[1] > > > >> conditions = dict ([tuple(arg.split("=",1)) > > > >> for arg in sys.argv[2:] > > > >> ]) > > > >> query = """ > > > >> select object_name > > > >> , object_type > > > >> from user_objects > > > >> where 1=1""" > > > >> for nam,val in conditions.items(): > > > >> query += ("\n and %s = :%s" % (nam,nam)) > > > >> print "Query:" > > > >> print query > > > >> print "*" * 70 > > > >> print "Bind Vars:" > > > >> for nam,val in conditions.items(): > > > >> print "%-20s = %r" % (nam,val) > > > >> print "*" * 70 > > > >> test (uid, query, **conditions); > > > >> else: > > > >> print "Test me like this:" > > > >> print "%s uid/pwd@dbs object_type=TABLE" % sys.argv[0] > > > >> > > > >> ============================================= > > > >> > > > >> Just save it as test.py, then call it like > > > >> test.py userid/password@database object_type=TABLE > > > >> > > > >> or, with other condiditons: > > > >> test.py userid/password@database object_type=TABLE object_name=XYZ > > > >> (This will probably not return any results) > > > >> > > > >> HTH > > > >> Henning > > > >> > > > >> ------------------------------------------------------------------------- > > > >> Take Surveys. Earn Cash. Influence the Future of IT > > > >> Join SourceForge.net's Techsay panel and you'll get the chance to share > > > >your > > > >> opinions on IT & business topics through brief surveys - and earn cash > > > >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > >> _______________________________________________ > > > >> cx-oracle-users mailing list > > > >> cx-...@li... > > > >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > >------------------------------------------------------------------------- > > > >Take Surveys. Earn Cash. Influence the Future of IT > > > >Join SourceForge.net's Techsay panel and you'll get the chance to share > > > >your > > > >opinions on IT & business topics through brief surveys - and earn cash > > > >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > >_______________________________________________ > > > >cx-oracle-users mailing list > > > >cx-...@li... > > > >https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > ------------------------------------------------------------------------- > 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 easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users |