.enable_fts() now works with columns with spaces in them, closes #90

This commit is contained in:
Simon Willison 2020-03-01 22:10:43 -08:00
commit 0c36feb6ca
2 changed files with 15 additions and 1 deletions

View file

@ -785,7 +785,7 @@ class Table(Queryable):
INSERT INTO [{table}_fts] (rowid, {columns})
SELECT rowid, {columns} FROM [{table}];
""".format(
table=self.name, columns=", ".join(columns)
table=self.name, columns=", ".join("[{}]".format(c) for c in columns)
)
self.db.conn.executescript(sql)
return self

View file

@ -44,6 +44,20 @@ def test_enable_fts_escape_table_names(fresh_db):
assert [] == table.search("bar")
def test_enable_fts_table_names_containing_spaces(fresh_db):
table = fresh_db["test"]
table.insert({"column with spaces": "in its name"})
table.enable_fts(["column with spaces"])
assert [
"test",
"test_fts",
"test_fts_data",
"test_fts_idx",
"test_fts_docsize",
"test_fts_config",
] == fresh_db.table_names()
def test_populate_fts(fresh_db):
table = fresh_db["populatable"]
table.insert(search_records[0])