mercredi 29 juillet 2015

Python database closes without .close()

Here is the following Python code for a Flask application:

g.db = connectDB()
cur = g.db.execute(statement for table 1)
received-data = [dict(first=row[0], second=row[1]) for row in cur.fetchall()]
cur = g.db.execute(statement for table 2)
g.db.close()

As you can see, there is g.db.close() after both the queries. For an unknown reason, the program fails on the second statement. I get an error stating the database is closed

If I was to remove the 3rd line, then the program will continue and the query will be executed. Why is there an issue in the first place and what can be done to fix it?

Thanks.

Aucun commentaire:

Enregistrer un commentaire