Subject | Re: [firebird-python] Jsonify |
---|---|
Author | Philippe Makowski |
Post date | 2012-05-07T09:47:24Z |
nxciro [2012-05-04 14:35] :
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)
> Following code works fine with kinterbasdb butwill check
> 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
>
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)