2013-10-22 42 views
2

我試圖用Firebird 2.5,Python 2.7和FDB 1.4來使用審計和跟蹤服務。如何在Python中使用Firebird審計和跟蹤服務?

這是我在做什麼空閒:

>>> 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的永不再來。

我錯過了某個步驟?

+0

乍一看,我會說它應該沒問題,firebird日誌中是否有任何內容? –

+0

沒有在日誌中,除非少數斷開連接,因爲如果重新啓動Python shell。 – Harriv

回答

2

原來,有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