Re: [cx-oracle-users] Help with fetchraw
Brought to you by:
atuining
From: Leith P. <lei...@gm...> - 2005-05-15 23:18:44
|
Hi Chris, This is a quick example i knocked togethor ages ago to return a dict result set instead of tuples. In retrospect fetchall() would probably be better writtern as a generator under the newer python stuff. eg r =3D db.fetchone() r['FIELDNAME'] Prehaps Anthony could give some feedback as to the "correctness" of this. --- SNIP --- from cx_Oracle import * # DictCursor for Oracle, returns dicts instead of tuples class DictConnect(Connection): def cursor(self): return DictCursor(self) class DictCursor(Cursor): def fetchall(self): r =3D Cursor.fetchall(self) result =3D [] for l in r: result.append( dict([(a[0],b) for a,b in zip(self.description, l)]) ) return result def fetchone(self): r =3D Cursor.fetchone(self) if r: return dict([(a[0],b) for a,b in zip(self.description, r)]) else: return None # factory class def connect(**kw): return DictConnect(**kw) ---- SNIP ---- On 5/15/05, Chris Dunscombe <cdu...@ya...> wrote: > Leith, >=20 > Thanks, I like the sub-classing idea but my OO Python isn't that good so = if you could give me a > code example that would be much appreciated. >=20 > Thanks very much, >=20 > Chris > --- Leith Parkin <lei...@gm...> wrote: >=20 > > Hi Chris, > > > > No worries. We have a very similair setup at work, transferring > > summarised data from oracle into MySQL. > > > > Depending on the database you are transferring too, couldnt you set a > > trigger, inserting NULL (eg, a python None from Oracle) into the table > > generates an empty string? > > > > Failing that, subclassing cx_Oracles cursor object to return a the > > empty string when the column type is textual and the value is null > > might be another option. > > > > Good luck, > > > > Leith > > > > > > On 5/13/05, Chris Dunscombe <cdu...@ya...> wrote: > > > Leith, > > > > > > I didn't mention that for 1) the target table is in a separate databa= se and using database > > links > > > isn't an option (although I wish it was) due to reasons that are too = lengthy to go into here. > > > Hence PL/SQL isn't really viable. So I'd still like to look at curso= r.fetchraw() > > > > > > Now for 2) you maybe right that PL/SQL could be used but I'll still h= ave to write out to file > > > using Python as util_file can only write to files that the database s= erver can "see" which > > isn't > > > always the case for my app. > > > > > > Thanks for the idea, > > > > > > Chris > > > > > > > > > --- Leith Parkin <lei...@gm...> wrote: > > > > This sounds like something better done in PL/SQL? > > > > > > > > Regards, > > > > > > > > Leith > > > > On 5/13/05, Chris Dunscombe <cdu...@ya...> wrote: > > > > > I'm looking to use cursor.fetchraw to help improve performance in= an app I'm writing. I've > > > > looked > > > > > at CopyData from cx_OracleTools but I'm afraid I couldn't work it= out. > > > > > If possible I'd like a simple full example to show me the way. Th= e context is: > > > > > > > > > > 1) Retrieve rows from source table and insert into a target table= which has exactly the > > same > > > > > structure. > > > > > > > > > > 2) Retrieve rows from source table, add some column formatting an= d write out to a file. > > > > > > > > > > Thanks very much, > > > > > > > > > > Chris Dunscombe > > > > > > > > > > PS Thanks for all the input re my previous posting on Nulls and N= one. I've still got some > > > > thinking > > > > > and work to do on which is best for performance and how best to c= ope with different > > datatypes, > > > > > particularly Longs (what a pain they are!!) > > > > > > > > > > __________________________________ > > > > > Yahoo! Mail Mobile > > > > > Take Yahoo! Mail with you! Check email on your mobile phone. > > > > > http://mobile.yahoo.com/learn/mail > > > > > > > > > > ------------------------------------------------------- > > > > > This SF.Net email is sponsored by Oracle Space Sweepstakes > > > > > Want to be the first software developer in space? > > > > > Enter now for the Oracle Space Sweepstakes! > > > > > http://ads.osdn.com/?ad_id=3D7393&alloc_id=3D16281&op=3Dclick > > > > > _______________________________________________ > > > > > cx-oracle-users mailing list > > > > > cx-...@li... > > > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > > This SF.Net email is sponsored by Oracle Space Sweepstakes > > > > Want to be the first software developer in space? > > > > Enter now for the Oracle Space Sweepstakes! > > > > http://ads.osdn.com/?ad_ids93&alloc_id=16281&op=3Dclick > > > > _______________________________________________ > > > > cx-oracle-users mailing list > > > > cx-...@li... > > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > > > __________________________________________________ > > > Do You Yahoo!? > > > Tired of spam? Yahoo! Mail has the best spam protection around > > > http://mail.yahoo.com > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email is sponsored by Oracle Space Sweepstakes > > > Want to be the first software developer in space? > > > Enter now for the Oracle Space Sweepstakes! > > > http://ads.osdn.com/?ad_id=3D7393&alloc_id=3D16281&op=3Dclick > > > _______________________________________________ > > > cx-oracle-users mailing list > > > cx-...@li... > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by Oracle Space Sweepstakes > > Want to be the first software developer in space? > > Enter now for the Oracle Space Sweepstakes! > > http://ads.osdn.com/?ad_ids93&alloc_id=16281&op=3Dclick > > _______________________________________________ > > cx-oracle-users mailing list > > cx-...@li... > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > >=20 > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by Oracle Space Sweepstakes > Want to be the first software developer in space? > Enter now for the Oracle Space Sweepstakes! > http://ads.osdn.com/?ad_id=3D7393&alloc_id=3D16281&op=3Dclick > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |