diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index fdb94bdd3..557d11c99 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -4034,6 +4034,7 @@ def search_sql( original_quoted = quote_identifier(original) columns_sql = "*" columns_with_prefix_sql = f"{original_quoted}.*" + columns = list(columns) if columns is not None else None if columns: columns_sql = ",\n ".join(quote_identifier(c) for c in columns) columns_with_prefix_sql = ",\n ".join( diff --git a/tests/test_fts.py b/tests/test_fts.py index 60c77269e..00d6cbbf2 100644 --- a/tests/test_fts.py +++ b/tests/test_fts.py @@ -112,6 +112,16 @@ def test_search_duplicate_columns_are_deduped(fresh_db): ] +def test_search_columns_accepts_iterator(fresh_db): + # https://github.com/simonw/sqlite-utils/issues/942 + table = fresh_db.table("t") + table.insert_all(search_records) + table.enable_fts(["text", "country"]) + assert list(table.search("tanuki", columns=iter(["text", "country"]))) == [ + {"text": "tanuki are running tricksters", "country": "Japan"} + ] + + def test_search_limit_offset(fresh_db): table = fresh_db.table("t") table.insert_all(search_records)