0
我正在使用karellen-sqlite Python模塊中的set_update_hook()
函數來自動將數據庫更改發送到函數。基本上,它的工作原理是這樣的:將數據包含在鉤子中?
from pysqlite2 import connect
def hook(conn, op, db_name, table_name, rowid):
"""Handle notification here. Do not modify the connection!"""
with connect(":memory:") as conn:
conn.set_update_hook(hook)
conn.execute("CREATE TABLE a (int id);")
conn.execute("INSERT INTO a VALUES (1);")
我想,以確定是否發送到hook
的信息包含已插入,更新或刪除數據庫中的數據。
所以,執行一個insert
後,我印刷的hook
的參數的值:
conn = ['DataError', 'DatabaseError', 'Error', 'IntegrityError', 'InterfaceError', 'InternalError', 'NotSupportedError', 'OperationalError', 'ProgrammingError', 'Warning', '__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_update_hook', '_update_hook_cb', '_update_hook_last_error', 'close', 'commit', 'create_aggregate', 'create_collation', 'create_function', 'cursor', 'enable_load_extension', 'execute', 'executemany', 'executescript', 'in_transaction', 'interrupt', 'isolation_level', 'iterdump', 'last_update_hook_error', 'load_extension', 'rollback', 'row_factory', 'set_authorizer', 'set_progress_handler', 'set_trace_callback', 'set_update_hook', 'text_factory', 'total_changes']
op = UpdateHookOps.SQLITE_INSERT
db_name = main
table_name = test
rowid = 3
但哪一個數據?我是否必須執行單獨的查詢來檢索它(在插入或更新的情況下)?
謝謝:)