mirror of
https://github.com/simonw/datasette.git
synced 2026-09-11 11:04:07 +02:00
Escape LIKE metacharacters in FTS detection
This commit is contained in:
parent
59618371e9
commit
bf348a22fc
1 changed files with 5 additions and 4 deletions
|
|
@ -829,13 +829,14 @@ def detect_fts(conn, table):
|
|||
|
||||
|
||||
def detect_fts_sql(table):
|
||||
escaped_table = table.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
|
||||
return (
|
||||
r"""
|
||||
select name from sqlite_master
|
||||
where rootpage = 0
|
||||
and (
|
||||
sql like :fts_double_quoted
|
||||
or sql like :fts_bracket_quoted
|
||||
sql like :fts_double_quoted escape char(92)
|
||||
or sql like :fts_bracket_quoted escape char(92)
|
||||
or (
|
||||
tbl_name = :table
|
||||
and sql like '%VIRTUAL TABLE%USING FTS%'
|
||||
|
|
@ -843,8 +844,8 @@ def detect_fts_sql(table):
|
|||
)
|
||||
""",
|
||||
{
|
||||
"fts_double_quoted": f'%VIRTUAL TABLE%USING FTS%content="{table}"%',
|
||||
"fts_bracket_quoted": f"%VIRTUAL TABLE%USING FTS%content=[{table}]%",
|
||||
"fts_double_quoted": f'%VIRTUAL TABLE%USING FTS%content="{escaped_table}"%',
|
||||
"fts_bracket_quoted": f"%VIRTUAL TABLE%USING FTS%content=[{escaped_table}]%",
|
||||
"table": table,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue