加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在sqlite中使用editdist3

发布时间:2020-12-12 18:54:41 所属栏目:百科 来源:网络整理
导读:根据 answer to another question,在sqlite中,Levenshtein距离在名为editdist3的SQL函数中实现. (比较 documentation) 现在,当我尝试使用它时,我得到的只是一个不存在的错误: ╰┄┄ sqlite3SQLite version 3.11.1 2016-03-03 16:17:53Enter ".help" for us
根据 answer to another question,在sqlite中,Levenshtein距离在名为editdist3的SQL函数中实现. (比较 documentation)

现在,当我尝试使用它时,我得到的只是一个不存在的错误:

╰┄┄> sqlite3
SQLite version 3.11.1 2016-03-03 16:17:53
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE test (col1 TEXT);
sqlite> INSERT INTO test VALUES ('foobar');
sqlite> SELECT * FROM test WHERE editdist3(col1,'f00bar') < 3;
Error: no such function: editdist3

我在Gentoo Linux上使用sqlite-3.11.1(默认)USE标志icu,readline和secure-delete.

解决方法

事实证明,editdist3包含在必须明确加载的sqlite扩展中.由于我没有在Gentoo sqlite包中找到它,我也必须自己构建它.正如 documentation所说:

The spellfix1 virtual table is not included in the SQLite amalgamation
and is not a part of any standard SQLite build. It is a loadable
extension.

首先,我获取了源代码

wget https://sqlite.org/2016/sqlite-src-3110100.zip
unzip sqlite-src-3110100.zip

然后它必须编译

gcc -shared -fPIC -Wall -Isqlite-src-3110100 sqlite-src-3110100/ext/misc/spellfix.c -o spellfix.so

最后它可以加载

.load ./spellfix

请注意,sqlite会自动附加扩展名.so.

要在python中使用它 – 这是我的初衷 – 需要完成以下工作:

db = sqlite3.connect(':memory:')

db.enable_load_extension(True)
db.load_extension('./spellfix')
db.enable_load_extension(False)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读