Implemented ?_search=XXX + UI if a FTS table is detected

Closes #131
This commit is contained in:
Simon Willison 2017-11-19 08:59:26 -08:00
commit eed6a0fe36
No known key found for this signature in database
GPG key ID: FBB38AFE227189DB
5 changed files with 75 additions and 5 deletions

View file

@ -235,3 +235,20 @@ def get_all_foreign_keys(conn):
})
return table_to_foreign_keys
def detect_fts(conn, table, return_sql=False):
"Detect if table has a corresponding FTS virtual table and return it"
rows = conn.execute(detect_fts_sql(table)).fetchall()
if len(rows) == 0:
return None
else:
return rows[0][0]
def detect_fts_sql(table):
return r'''
select name from sqlite_master
where rootpage = 0
and sql like '%VIRTUAL TABLE%USING FTS%content="{}"%';
'''.format(table)