Thread: [cx-oracle-users] Results as dict
Brought to you by:
atuining
From: Christian K. <ckl...@no...> - 2006-11-08 09:50:12
|
Hello cx_oracle users, who knows a simple way to get results from a fetchall as dict´s instead of lists?? Thx in advance Christian |
From: Amaury F. d'A. <ama...@gm...> - 2006-11-08 10:17:02
|
Christian Klinger wrote: > Hello cx_oracle users, > > who knows a simple way to get results from a fetchall as dict=B4s instead > of lists?? You may use the cursor.description to get the column names. Something like: data =3D cur.fetchall() desc =3D cur.description dict_data =3D [dict((col[0], value) for col, value in zip(desc, row)) for row in data] Hope this helps, --=20 Amaury |
From: Christian K. <ckl...@no...> - 2006-11-08 15:18:15
|
Amaury Forgeot d'Arc schrieb: > Christian Klinger wrote: >> Hello cx_oracle users, >> >> who knows a simple way to get results from a fetchall as dict´s instead >> of lists?? > > You may use the cursor.description to get the column names. Something like: > > data = cur.fetchall() > desc = cur.description > dict_data = [dict((col[0], value) for col, value in zip(desc, row)) > for row in data] > > Hope this helps, > Helps perfect, btw other database-modules have out of the box solutions for this (mysql,informix) thx a lot christian |
From: Anthony T. <ant...@gm...> - 2006-11-08 15:26:17
|
On 11/8/06, Christian Klinger <ckl...@no...> wrote: > Amaury Forgeot d'Arc schrieb: > > Christian Klinger wrote: > >> Hello cx_oracle users, > >> > >> who knows a simple way to get results from a fetchall as dict=B4s inst= ead > >> of lists?? > > > > You may use the cursor.description to get the column names. Something l= ike: > > > > data =3D cur.fetchall() > > desc =3D cur.description > > dict_data =3D [dict((col[0], value) for col, value in zip(desc, row)) > > for row in data] > > > > Hope this helps, > > > Helps perfect, > > btw other database-modules have out of the box solutions for this > (mysql,informix) How do they go about this? Is that all they do or is there some switch or some different method call that they make? > thx a lot > > christian > > > ------------------------------------------------------------------------- > 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 > |
From: Christian K. <ckl...@no...> - 2006-11-08 15:37:01
|
Anthony Tuininga schrieb: > On 11/8/06, Christian Klinger <ckl...@no...> wrote: >> Amaury Forgeot d'Arc schrieb: >>> Christian Klinger wrote: >>>> Hello cx_oracle users, >>>> >>>> who knows a simple way to get results from a fetchall as dict´s instead >>>> of lists?? >>> You may use the cursor.description to get the column names. Something like: >>> >>> data = cur.fetchall() >>> desc = cur.description >>> dict_data = [dict((col[0], value) for col, value in zip(desc, row)) >>> for row in data] >>> >>> Hope this helps, >>> >> Helps perfect, >> >> btw other database-modules have out of the box solutions for this >> (mysql,informix) > > How do they go about this? Is that all they do or is there some switch > or some different method call that they make? > They define a additional CursorClass for this > db1 = MySQLdb.connect(user = "username", passwd="password", host= "host", db > = "database", cursorclass=MySQLdb.cursors.DictCursor) http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-4.html#usage >> thx a lot >> >> christian >> >> >> ------------------------------------------------------------------------- >> 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 >> > > ------------------------------------------------------------------------- > 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 |
From: Anthony T. <ant...@gm...> - 2006-11-08 15:54:19
|
On 11/8/06, Christian Klinger <ckl...@no...> wrote: > Anthony Tuininga schrieb: > > On 11/8/06, Christian Klinger <ckl...@no...> wrote: > >> Amaury Forgeot d'Arc schrieb: > >>> Christian Klinger wrote: > >>>> Hello cx_oracle users, > >>>> > >>>> who knows a simple way to get results from a fetchall as dict=B4s in= stead > >>>> of lists?? > >>> You may use the cursor.description to get the column names. Something= like: > >>> > >>> data =3D cur.fetchall() > >>> desc =3D cur.description > >>> dict_data =3D [dict((col[0], value) for col, value in zip(desc, row)) > >>> for row in data] > >>> > >>> Hope this helps, > >>> > >> Helps perfect, > >> > >> btw other database-modules have out of the box solutions for this > >> (mysql,informix) > > > > How do they go about this? Is that all they do or is there some switch > > or some different method call that they make? > > > > They define a additional CursorClass for this > db1 =3D > MySQLdb.connect(user =3D "username", passwd=3D"password", host=3D "host",= db > > =3D "database", cursorclass=3DMySQLdb.cursors.DictCursor) Ah, I see. You can do the same thing with cx_Oracle (create a subclassed cursor that returns rows as dictionaries) quite easily. Its simply not "out of the box" as you say. There is an implicit performance penalty involved (dictionaries cost a great deal more to build than tuples do relatively speaking) so I've tended to avoid such techniques. My personal preference for when performance is not an issue is to return objects with attributes defined for each of the columns. Both of these techniques are possible to use without any help from any module author and should be available globally as a recipe or some such. Would there be appreciation for including such things as part of documentation or sample files? > http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-4.html#usage > > > > >> thx a lot > >> > >> christian > >> > >> > >> ----------------------------------------------------------------------= --- > >> Using Tomcat but need to do more? Need to support web services, securi= ty? > >> 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 Gero= nimo > >> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&da= t=3D121642 > >> _______________________________________________ > >> 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, securit= y? > > 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 Geron= imo > > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > > > ------------------------------------------------------------------------- > 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 > |
From: Chris D. <cdu...@ya...> - 2006-11-09 08:44:56
|
--- Anthony Tuininga <ant...@gm...> wrote: > > Ah, I see. You can do the same thing with cx_Oracle (create a > subclassed cursor that returns rows as dictionaries) quite easily. Its > simply not "out of the box" as you say. There is an implicit > performance penalty involved (dictionaries cost a great deal more to > build than tuples do relatively speaking) so I've tended to avoid such > techniques. My personal preference for when performance is not an > issue is to return objects with attributes defined for each of the > columns. Both of these techniques are possible to use without any help > from any module author and should be available globally as a recipe or > some such. Would there be appreciation for including such things as > part of documentation or sample files? > I would appreciate these sort things very much. Thanks, Chris Dunscombe ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com |
From: <wa...@li...> - 2006-11-09 09:00:06
|
Chris Dunscombe wrote: > > --- Anthony Tuininga <ant...@gm...> wrote: > >> Ah, I see. You can do the same thing with cx_Oracle (create a >> subclassed cursor that returns rows as dictionaries) quite easily. Its >> simply not "out of the box" as you say. There is an implicit >> performance penalty involved (dictionaries cost a great deal more to >> build than tuples do relatively speaking) so I've tended to avoid such >> techniques. My personal preference for when performance is not an >> issue is to return objects with attributes defined for each of the >> columns. Both of these techniques are possible to use without any help >> from any module author and should be available globally as a recipe or >> some such. Would there be appreciation for including such things as >> part of documentation or sample files? > > I would appreciate these sort things very much. ll-orasql (http://www.livinglogic.de/Python/orasql/) implements that kind of functionality (i.e. column access via row.column and row["column"]). Servus, Walter |
From: Hancock, D. (DHANCOCK) <DHA...@ar...> - 2006-11-09 13:16:04
|
We've been using dtuple for several years to do the same thing. You can get it at: http://www.lyra.org/greg/python/dtuple.py Cheers! --=20 David Hancock | dha...@ar... From: Walter D=F6rwald <wa...@li...> Organization: LivingLogic AG, Bayreuth/Germany Reply-To: <cx-...@li...> Date: Thu, 9 Nov 2006 03:59:38 -0500 To: <cx-...@li...> Conversation: [cx-oracle-users] Results as dict Subject: Re: [cx-oracle-users] Results as dict Chris Dunscombe wrote: > > --- Anthony Tuininga <ant...@gm...> wrote: > >> Ah, I see. You can do the same thing with cx_Oracle (create a >> subclassed cursor that returns rows as dictionaries) quite easily. Its >> simply not "out of the box" as you say. There is an implicit >> performance penalty involved (dictionaries cost a great deal more to >> build than tuples do relatively speaking) so I've tended to avoid such >> techniques. My personal preference for when performance is not an >> issue is to return objects with attributes defined for each of the >> columns. Both of these techniques are possible to use without any help >> from any module author and should be available globally as a recipe or >> some such. Would there be appreciation for including such things as >> part of documentation or sample files? > > I would appreciate these sort things very much. ll-orasql (http://www.livinglogic.de/Python/orasql/) implements that kind of functionality (i.e. column access via row.column and row["column"])= . Servus, Walter ------------------------------------------------------------------------- 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=3Dlnk=3D120709=3D263057=3D121642 <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 |
From: Anthony T. <ant...@gm...> - 2006-11-09 15:29:38
|
Hmm, in that case perhaps a simple reference to these things in the README would suffice. Any others that people have used that I should reference? On 11/9/06, Hancock, David (DHANCOCK) <DHA...@ar...> wrote: > > We've been using dtuple for several years to do the same thing. You can = get > it at: > > http://www.lyra.org/greg/python/dtuple.py > > Cheers! > -- > David Hancock | dha...@ar... > > > ________________________________ > From: Walter D=F6rwald <wa...@li...> > Organization: LivingLogic AG, Bayreuth/Germany > Reply-To: <cx-...@li...> > Date: Thu, 9 Nov 2006 03:59:38 -0500 > To: <cx-...@li...> > Conversation: [cx-oracle-users] Results as dict > Subject: Re: [cx-oracle-users] Results as dict > > Chris Dunscombe wrote: > > > > --- Anthony Tuininga <ant...@gm...> wrote: > > > >> Ah, I see. You can do the same thing with cx_Oracle (create a > >> subclassed cursor that returns rows as dictionaries) quite easily. It= s > >> simply not "out of the box" as you say. There is an implicit > >> performance penalty involved (dictionaries cost a great deal more to > >> build than tuples do relatively speaking) so I've tended to avoid suc= h > >> techniques. My personal preference for when performance is not an > >> issue is to return objects with attributes defined for each of the > >> columns. Both of these techniques are possible to use without any hel= p > >> from any module author and should be available globally as a recipe o= r > >> some such. Would there be appreciation for including such things as > >> part of documentation or sample files? > > > > I would appreciate these sort things very much. > > ll-orasql (http://www.livinglogic.de/Python/orasql/) > implements that > kind of functionality (i.e. column access via row.column and > row["column"]). > > Servus, > Walter > > > ------------------------------------------------------------------------- > 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 Geroni= mo > http://sel.as-us.falkag.net/sel?cmd=3Dlnk=3D120709=3D263057=3D121642 > <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 > > > ------------------------------------------------------------------------- > 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 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 > > > |
From: Andy H. <and...@gm...> - 2006-11-09 21:50:45
|
Another one for your list is db_row which I've used quite a lot: http://opensource.theopalgroup.com/ Does all the normal things you'd expect - lets you reference results by either index, name or attribute. It does it in a space efficient manner, by only having a single dict for the whole result set (everything else is just stored as the tuple returned by the DBAPI). There's also a C extension module for slightly speedier performance. Andy |