mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-28 03:44:31 +02:00
sqlite-utils optimize command, .optimize() and .detect_fts() table methods
This commit is contained in:
parent
015bd2a840
commit
0a8194e730
7 changed files with 146 additions and 4 deletions
|
|
@ -243,6 +243,40 @@ class Table:
|
|||
self.db.conn.executescript(sql)
|
||||
return self
|
||||
|
||||
def detect_fts(self):
|
||||
"Detect if table has a corresponding FTS virtual table and return it"
|
||||
rows = self.db.conn.execute(
|
||||
"""
|
||||
SELECT name FROM sqlite_master
|
||||
WHERE rootpage = 0
|
||||
AND (
|
||||
sql LIKE '%VIRTUAL TABLE%USING FTS%content="{table}"%'
|
||||
OR (
|
||||
tbl_name = "{table}"
|
||||
AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
|
||||
)
|
||||
)
|
||||
""".format(
|
||||
table=self.name
|
||||
)
|
||||
).fetchall()
|
||||
if len(rows) == 0:
|
||||
return None
|
||||
else:
|
||||
return rows[0][0]
|
||||
|
||||
def optimize(self):
|
||||
fts_table = self.detect_fts()
|
||||
if fts_table is not None:
|
||||
self.db.conn.execute(
|
||||
"""
|
||||
INSERT INTO [{table}] ([{table}]) VALUES ("optimize");
|
||||
""".format(
|
||||
table=fts_table
|
||||
)
|
||||
)
|
||||
return self
|
||||
|
||||
def detect_column_types(self, records):
|
||||
all_column_types = {}
|
||||
for record in records:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue