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])