Subject Re: [firebird-python] Jsonify
Author Philippe Makowski
nxciro [2012-05-04 14:35] :
> 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
>
will check


but you can try this :

import json
import fdb

def db(database_name='localhost:employee'):
return fdb.connect(dsn=database_name,
user='sysdba',
password='masterkey')

def query_db(query, one=False):
cur = db().cursor()
cur.execute(query)
r = [(dict(row)) for row in cur.fetchallmap()]
cur.close()
return (r[0] if r else None) if one else r

my_query = query_db("select * from country")
json_output = json.dumps(my_query)
print(json_output)