Subject Jsonify
Author nxciro
Following code works fine with kinterbasdb but
fails with fdb :

File "jsonify-firebird.py", line 22, in <module>
cols = [x[0] for x in cur.description]
TypeError: 'NoneType' object is not iterable


Having said that , if I uncomment the line
#print cur.description[0]
fdb also works ok.
Something not initialized in fdb after query execution ?




# test to jsonify firebird query output

import json
import fdb,kinterbasdb

def ystockconnector():
try:
ystockc=fdb.connect(dsn='ystockmaster',user='sysdba',password='masterkey',charset='UNICODE_FSS')
return ystockc
except:
print 'No connection ystockmaster'

mycon=ystockconnector()
cur=mycon.cursor()

mq="select ssymbol,sname,boardlot from stockcodes"
cur.execute(mq)

#print cur.description[0]

rows = [x for x in cur]
cols = [x[0] for x in cur.description]
mydata = []

for row in rows:
dx = {}
for prop, val in zip(cols, row):
dx[prop] = val

mydata.append(dx)

dbJSON = json.dumps(mydata)

print dbJSON