Skip to content
Permalink
Browse files

detect_fts now works with alternative table escaping (#571)

  • Loading branch information...
simonw committed Sep 3, 2019
1 parent f04deeb commit 2dc5c8dc259a0606162673d394ba8cc1c6f54428
Showing with 7 additions and 3 deletions.
  1. +1 −0 datasette/utils/__init__.py
  2. +6 −3 tests/test_utils.py
@@ -469,6 +469,7 @@ def detect_fts_sql(table):
where rootpage = 0
and (
sql like '%VIRTUAL TABLE%USING FTS%content="{table}"%'
or sql like '%VIRTUAL TABLE%USING FTS%content=[{table}]%'
or (
tbl_name = "{table}"
and sql like '%VIRTUAL TABLE%USING FTS%'
@@ -159,7 +159,8 @@ def test_validate_sql_select_good(good_sql):
utils.validate_sql_select(good_sql)


def test_detect_fts():
@pytest.mark.parametrize("open_quote,close_quote", [('"', '"'), ("[", "]")])
def test_detect_fts(open_quote, close_quote):
sql = """
CREATE TABLE "Dumb_Table" (
"TreeID" INTEGER,
@@ -175,9 +176,11 @@ def test_detect_fts():
"qCaretaker" TEXT
);
CREATE VIEW Test_View AS SELECT * FROM Dumb_Table;
CREATE VIRTUAL TABLE "Street_Tree_List_fts" USING FTS4 ("qAddress", "qCaretaker", "qSpecies", content="Street_Tree_List");
CREATE VIRTUAL TABLE {open}Street_Tree_List_fts{close} USING FTS4 ("qAddress", "qCaretaker", "qSpecies", content={open}Street_Tree_List{close});
CREATE VIRTUAL TABLE r USING rtree(a, b, c);
"""
""".format(
open=open_quote, close=close_quote
)
conn = utils.sqlite3.connect(":memory:")
conn.executescript(sql)
assert None is utils.detect_fts(conn, "Dumb_Table")

0 comments on commit 2dc5c8d

Please sign in to comment.
You can’t perform that action at this time.