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

标签 python firebird trace

我正在尝试将审核和跟踪服务与 Firebird 2.5、Python 2.7 和 FDB 1.4 结合使用。

这就是我在空闲时所做的事情:

>>> 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/

相关文章:

sql - 如何使用SQL MAX函数获取一行的所有字段?

c - 多线程应用程序中的 dlopen() 以 "Trace/BPT trap"退出

python - 如何去除 VideoCapture 中的黑色边框?

firebird - 复制实时 Firebird .fdb 数据库

python - 如何使用 Django REST 框架在 Spyder IDE 中启动新的 Web 应用程序

sql - Firebird - 获取触发器内所有修改的字段

linux - 记录执行期间的内存访问

sql-server - 跟踪文件 - 如何使用它

python - 如何检查命令是否已经执行

python - Jupyter 在系统 python 之前找不到我的内核 python