From 0c36feb6ca5c3ffb9a6df4c8ea4bb732fcab74f4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 1 Mar 2020 22:10:43 -0800 Subject: [PATCH] .enable_fts() now works with columns with spaces in them, closes #90 --- sqlite_utils/db.py | 2 +- tests/test_fts.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 5d17ad2..746978a 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -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 diff --git a/tests/test_fts.py b/tests/test_fts.py index 134e0e7..7817477 100644 --- a/tests/test_fts.py +++ b/tests/test_fts.py @@ -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])