Skip to main content
 首页 » 编程设计

python 和 sqlite3,检查我是否可以使用 fts5 扩展

2025年05月04日11jiqing9006

我最近发现 FTS5扩展已经发布。
检查我的应用程序是否可以在用户系统上使用它的最佳方法是什么?
只检查 python3 版本,或者根据 release page 检查 sqlite3.sqlite_version ??还是别的?

请您参考如下方法:

/这是之前对 OP 帖子的编辑,但我将其移至此处以明确问题

所以这感觉好像可行,在问题 here 中找到了它

import sqlite3 
 
con = sqlite3.connect(':memory:') 
cur = con.cursor() 
cur.execute('pragma compile_options;') 
available_pragmas = cur.fetchall() 
con.close() 
 
print(available_pragmas) 
 
if ('ENABLE_FTS5',) in available_pragmas: 
    print('YES') 
else: 
    print('NO') 

但奇怪的是,我在几台虚拟机上运行它,没有一个启用 fts4,但我却像什么都没有一样愉快地使用它......也许它的 fts3/fts4 相当相同,或者它可能完全错误.

/编辑
来自文档

Note that enabling FTS3 also makes FTS4 available. There is not a separate SQLITE_ENABLE_FTS4 compile-time option. A build of SQLite either supports both FTS3 and FTS4 or it supports neither.