mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 02:44:33 +02:00
Fix bug with detect_fts() and similar table names, closes #434
This commit is contained in:
parent
1b09538bc6
commit
b8af3b96f5
3 changed files with 39 additions and 15 deletions
|
|
@ -2212,24 +2212,26 @@ class Table(Queryable):
|
|||
|
||||
def detect_fts(self) -> Optional[str]:
|
||||
"Detect if table has a corresponding FTS virtual table and return it"
|
||||
sql = (
|
||||
textwrap.dedent(
|
||||
"""
|
||||
sql = textwrap.dedent(
|
||||
"""
|
||||
SELECT name FROM sqlite_master
|
||||
WHERE rootpage = 0
|
||||
AND (
|
||||
sql LIKE '%VIRTUAL TABLE%USING FTS%content=%{table}%'
|
||||
sql LIKE :like
|
||||
OR sql LIKE :like2
|
||||
OR (
|
||||
tbl_name = "{table}"
|
||||
tbl_name = :table
|
||||
AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
|
||||
)
|
||||
)
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(table=self.name)
|
||||
)
|
||||
rows = self.db.execute(sql).fetchall()
|
||||
).strip()
|
||||
args = {
|
||||
"like": "%VIRTUAL TABLE%USING FTS%content=[{}]%".format(self.name),
|
||||
"like2": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name),
|
||||
"table": self.name,
|
||||
}
|
||||
rows = self.db.execute(sql, args).fetchall()
|
||||
if len(rows) == 0:
|
||||
return None
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue