从Python访问firebird,提交后无法发送新命令

2024-09-27 21:28:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Firebird的SQL和Python,但一旦我创建了第一行“提交”,其他所有事务都需要一个新事务,但我似乎找不到如何启动一个事务

fbsql.ShowEverythingInTable("Cakes", con) #Works
fbsql.DropFullTable('dummy',con) #Works
fbsql.DropFullTable('Cakes',con) #Works
fbsql.CommitTransaction(con) #Works
fbsql.ShowEverythingInTable('Objects',con) #YOU SHALL NOT PASS
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\graciele.davince\PycharmProjects\helloworld\venv\firebirdSQL.py", line 61, in ShowEverythingInTable
    cur.execute(SQLSelectEverything + tableName +";")
  File "C:\Users\graciele.davince\PycharmProjects\helloworld\venv\lib\site-packages\fdb\fbcore.py", line 3688, in execute
    self._ps = PreparedStatement(operation, self, True)
  File "C:\Users\graciele.davince\PycharmProjects\helloworld\venv\lib\site-packages\fdb\fbcore.py", line 2306, in __init__
    raise exception_from_status(DatabaseError, self._isc_status,
fdb.fbcore.DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -901\n- invalid transaction handle (expecting explicit transaction start)', -901, 335544332)

Tags: inpyvenvlinecon事务usershelloworld
1条回答
网友
1楼 · 发布于 2024-09-27 21:28:54

如果将COMMIT作为语句执行,而不是使用连接对象的commit()函数,则可能会出现此问题。这样做会使驱动程序处于不一致的状态

使用commit语句的问题是FDB不知道它,因此客户端it认为它仍然有一个事务,而服务器端事务结束并且不再存在。当FDB随后执行另一条语句时,它发送旧的事务句柄,导致服务器报告错误,因为该事务不再存在

简而言之:您需要使用con.commit()(其中con是FDB连接对象)

相关问题 更多 >

    热门问题