當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sqlite3.Connection.enable_load_extension用法及代碼示例

用法:

enable_load_extension(enabled)

此例程允許/禁止 SQLite 引擎從共享庫加載 SQLite 擴展。 SQLite 擴展可以定義新的函數、聚合或全新的虛擬表實現。一個眾所周知的擴展是隨 SQLite 分發的 fulltext-search 擴展。

默認情況下禁用可加載擴展。見1

使用參數 connectionenabled 引發審計事件 sqlite3.enable_load_extension

3.2 版中的新函數。

在 3.10 版中更改:添加了sqlite3.enable_load_extension審計事件。

import sqlite3

con = sqlite3.connect(":memory:")

# enable extension loading
con.enable_load_extension(True)

# Load the fulltext search extension
con.execute("select load_extension('./fts3.so')")

# alternatively you can load the extension using an API call:
# con.load_extension("./fts3.so")

# disable extension loading again
con.enable_load_extension(False)

# example from SQLite wiki
con.execute("create virtual table recipe using fts3(name, ingredients)")
con.executescript("""
    insert into recipe (name, ingredients) values ('broccoli stew', 'broccoli peppers cheese tomatoes');
    insert into recipe (name, ingredients) values ('pumpkin stew', 'pumpkin onions garlic celery');
    insert into recipe (name, ingredients) values ('broccoli pie', 'broccoli cheese onions flour');
    insert into recipe (name, ingredients) values ('pumpkin pie', 'pumpkin sugar flour butter');
    """)
for row in con.execute("select rowid, name, ingredients from recipe where name match 'pie'"):
    print(row)

con.close()

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 sqlite3.Connection.enable_load_extension。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。