Re: [cx-oracle-users] Help with fetchraw
Brought to you by:
atuining
From: Chris D. <cdu...@ya...> - 2005-05-17 01:17:58
|
Leith, Thanks very much, Chris --- Leith Parkin <lei...@gm...> wrote: > 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 = 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 = Cursor.fetchall(self) > result = [] > for l in r: > result.append( dict([(a[0],b) for a,b in > zip(self.description, l)]) ) > > return result > > def fetchone(self): > r = 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, > > > > 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. > > > > Thanks very much, > > > > Chris > > --- Leith Parkin <lei...@gm...> wrote: > > > > > 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 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |