Fixed bug with detect_fts for table with single quote in name, closes #1257

This commit is contained in:
Simon Willison 2021-06-01 20:27:04 -07:00
commit 0f1e47287c
2 changed files with 17 additions and 1 deletions

View file

@ -547,7 +547,7 @@ def detect_fts_sql(table):
)
)
""".format(
table=table
table=table.replace("'", "''")
)

View file

@ -200,6 +200,22 @@ def test_detect_fts(open_quote, close_quote):
assert "Street_Tree_List_fts" == utils.detect_fts(conn, "Street_Tree_List")
@pytest.mark.parametrize("table", ("regular", "has'single quote"))
def test_detect_fts_different_table_names(table):
sql = """
CREATE TABLE [{table}] (
"TreeID" INTEGER,
"qSpecies" TEXT
);
CREATE VIRTUAL TABLE [{table}_fts] USING FTS4 ("qSpecies", content="{table}");
""".format(
table=table
)
conn = utils.sqlite3.connect(":memory:")
conn.executescript(sql)
assert "{table}_fts".format(table=table) == utils.detect_fts(conn, table)
@pytest.mark.parametrize(
"url,expected",
[