gpt4 book ai didi

python - 如何通过 Python 使用 Firebird 审计和跟踪服务?

转载 作者:太空宇宙 更新时间:2023-11-04 01:23:44 25 4
gpt4 key购买 nike

我正在尝试通过 Firebird 2.5、Python 2.7 和 FDB 1.4 使用审计和跟踪服务。

这是我在 Idle 中所做的:

>>> import fdb
>>> svc = fdb.services.connect(password='masterkey', host='localhost')
>>> trace_config = """<database>
enabled true
log_connections true
log_transactions true
log_statement_finish true
time_threshold 0

</database>"""
>>> trace_id = svc.trace_start(trace_config, 'test_trace_2')
>>> svc.readline()

在此之后我连接到数据库并进行一些选择等,但 readline 永远不会返回。

我是不是漏掉了一步?

最佳答案

原来有 64kb 的缓冲区用于输出。有一种方法可以直接获取输出,来自 FDB 作者 Pavel Cisar:

while 1:
try:
line = svc._QS(fdb.ibase.isc_info_svc_line)
except fdb.OperationalError:
# It is routine for actions such as RESTORE to raise an
# exception at the end of their output. We ignore any such
# exception and assume that it was expected, which is somewhat
# risky. For example, suppose the network connection is broken
# while the client is receiving the action&#39;s output...
break
if not line: # we reached the end of output
break
print line

关于python - 如何通过 Python 使用 Firebird 审计和跟踪服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19521998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com