如何使用 kinterbasdb 运行 DDL 脚本
有没有办法使用 Firebird 数据库的 kinterbasdb 库从 Python 执行 DDL 脚本?
基本上我想复制“isql -i myscript.sql”命令。
Is there way to execute DDL script from Python with kinterbasdb library for Firebird database?
Basically I'd like to replicate 'isql -i myscript.sql' command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自从我使用 kinterbasdb 以来已经有一段时间了,但据我所知,您应该能够使用任何查询命令来执行此操作,这些命令也可用于 INSERT、UPDATE 和 DELETE(即不会生成结果集)。所以 Connection.execute_immediate 和 Cursor.execute 应该可以工作。
你真的尝试过这个吗?
顺便说一句:对于 Firebird,建议不要在一个事务中混合 DDL 和 DML。
编辑:
我刚刚意识到您可能指的是包含多个语句的完整 DDL 脚本,如果这就是您的意思,那么:不,您不能,您需要单独执行每个语句。
您也许能够使用 EXECUTE BLOCK 语句,但您可能需要对脚本进行大量修改,以便尝试将实际脚本拆分为单独的语句会更容易。
It has been a while since I used kinterbasdb, but as far as I know you should be able to do this with any query command which can also be used for INSERT, UPDATE and DELETE (ie nothing that produces a resultset). So Connection.execute_immediate and Cursor.execute should work.
Did you actually try this.
BTW: With Firebird it is advisable not to mix DDL and DML in one transaction.
EDIT:
I just realised that you might have meant a full DDL script with multiple statements, if that is what you mean, then: no you cannot, you need to execute each statement individually.
You might be able to use an EXECUTE BLOCK statement, but you may need to modify your script so much that it would be easier to simply try to split the actual script into individual statements.