2

我正在尝试在 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 永远不会返回。

我在某处错过了一步吗?

4

1 回答 1

3

原来有 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
于 2013-10-27T14:02:18.483 回答