mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-27 02:37:13 +01:00
Merge d978a391ac into 9c66bafa52
This commit is contained in:
commit
14eeff4af8
2 changed files with 16 additions and 0 deletions
|
|
@ -3770,6 +3770,9 @@ class Table(Queryable):
|
||||||
:param tokenize: Custom SQLite tokenizer to use, for example ``"porter"`` to enable Porter stemming.
|
:param tokenize: Custom SQLite tokenizer to use, for example ``"porter"`` to enable Porter stemming.
|
||||||
:param replace: Should any existing FTS index for this table be replaced by the new one?
|
:param replace: Should any existing FTS index for this table be replaced by the new one?
|
||||||
"""
|
"""
|
||||||
|
# columns is used several times below, so a one-shot iterator
|
||||||
|
# would be exhausted after the CREATE VIRTUAL TABLE statement
|
||||||
|
columns = list(columns)
|
||||||
create_fts_sql = (
|
create_fts_sql = (
|
||||||
textwrap.dedent("""
|
textwrap.dedent("""
|
||||||
CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
|
CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,19 @@ def test_enable_fts(fresh_db):
|
||||||
assert [] == list(table.search("bar"))
|
assert [] == list(table.search("bar"))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("create_triggers", [True, False])
|
||||||
|
def test_enable_fts_columns_iterator(fresh_db, create_triggers):
|
||||||
|
# columns is typed Iterable[str], so a one-shot iterator has to work
|
||||||
|
table = fresh_db.table("searchable")
|
||||||
|
table.insert_all(search_records)
|
||||||
|
table.enable_fts(iter(["text", "country"]), create_triggers=create_triggers)
|
||||||
|
assert [row["rowid"] for row in table.search("tanuki")] == [1]
|
||||||
|
assert [row["rowid"] for row in table.search("usa")] == [2]
|
||||||
|
if create_triggers:
|
||||||
|
table.insert({"text": "kitsune", "country": "Japan", "not_searchable": "x"})
|
||||||
|
assert [row["rowid"] for row in table.search("kitsune")] == [3]
|
||||||
|
|
||||||
|
|
||||||
def test_enable_fts_escape_table_names(fresh_db):
|
def test_enable_fts_escape_table_names(fresh_db):
|
||||||
# Table names with restricted chars are handled correctly.
|
# Table names with restricted chars are handled correctly.
|
||||||
# colons and dots are restricted characters for table names.
|
# colons and dots are restricted characters for table names.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue