Subject | execute a whole script |
---|---|
Author | Hamish Moffatt |
Post date | 2014-05-14T07:35:03Z |
Hi,
I've got a whole script full of SQL for Firebird that I want to execute
from python with fdb. Is there a way?
The sqlite3 module has an 'executescript' extension for this.
Currently I'm using sqlparse to split the script into individual
statements and executing those individually. There are two problems I've
run into so far;
1. Any COMMIT statement causes the following commands to fail with an
"SQL error code = -901\n- invalid transaction handle (expecting explicit
transaction start" error. I've trapped those and converted them to
cursor.commit() which is ugly; there must be a better way.
2. Now I'm trying to declare a procedure in the SQL, which requires SET
TERM before and after, and sqlparse can't grok that.
Any suggestions?
Thanks
Hamish
I've got a whole script full of SQL for Firebird that I want to execute
from python with fdb. Is there a way?
The sqlite3 module has an 'executescript' extension for this.
Currently I'm using sqlparse to split the script into individual
statements and executing those individually. There are two problems I've
run into so far;
1. Any COMMIT statement causes the following commands to fail with an
"SQL error code = -901\n- invalid transaction handle (expecting explicit
transaction start" error. I've trapped those and converted them to
cursor.commit() which is ugly; there must be a better way.
2. Now I'm trying to declare a procedure in the SQL, which requires SET
TERM before and after, and sqlparse can't grok that.
Any suggestions?
Thanks
Hamish