mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow loading of calibre sqlite extension when connecting via python sqlite3 module as well
This commit is contained in:
parent
4467f1e54c
commit
a8483d8626
@ -344,6 +344,15 @@ class Plugins(collections.abc.Mapping):
|
||||
finally:
|
||||
conn.enableloadextension(False)
|
||||
|
||||
def load_sqlite3_extension(self, conn, name):
|
||||
conn.enable_load_extension(True)
|
||||
try:
|
||||
ext = 'pyd' if iswindows else 'so'
|
||||
path = os.path.join(plugins_loc, f'{name}.{ext}')
|
||||
conn.load_extension(path)
|
||||
finally:
|
||||
conn.enable_load_extension(False)
|
||||
|
||||
|
||||
plugins = None
|
||||
if plugins is None:
|
||||
|
@ -448,6 +448,11 @@ calibre_sqlite_extension_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_ro
|
||||
fts5api->xCreateTokenizer(fts5api, "porter", reinterpret_cast<void *>(fts5api), &tok2, NULL);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
MYEXPORT int
|
||||
sqlite3_sqliteextension_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi){
|
||||
return calibre_sqlite_extension_init(db, pzErrMsg, pApi);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
|
@ -17,7 +17,7 @@ from functools import partial
|
||||
from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
||||
from calibre.utils.date import parse_date, isoformat, local_tz, UNDEFINED_DATE
|
||||
from calibre import isbytestring, force_unicode
|
||||
from calibre.constants import iswindows, DEBUG, plugins_loc
|
||||
from calibre.constants import iswindows, DEBUG, plugins_loc, plugins
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre_extensions import speedup as _c_speedup
|
||||
from calibre import prints
|
||||
@ -270,6 +270,7 @@ def do_connect(path, row_factory=None):
|
||||
# Dummy functions for dynamically created filters
|
||||
conn.create_function('books_list_filter', 1, lambda x: 1)
|
||||
conn.create_collation(native_string_type('icucollate'), icu_collator)
|
||||
plugins.load_sqlite3_extension(conn, 'sqlite_extension')
|
||||
return conn
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user