@@ -2275,12 +2275,10 @@ def create_index(
22752275 "{}_{}" .format (index_name , suffix ) if suffix else index_name
22762276 )
22772277 sql = (
2278- textwrap .dedent (
2279- """
2278+ textwrap .dedent ("""
22802279 CREATE {unique}INDEX {if_not_exists}{index_name}
22812280 ON {table_name} ({columns});
2282- """
2283- )
2281+ """ )
22842282 .strip ()
22852283 .format (
22862284 index_name = quote_identifier (created_index_name ),
@@ -2475,8 +2473,7 @@ def enable_counts(self) -> None:
24752473 See :ref:`python_api_cached_table_counts` for details.
24762474 """
24772475 sql = (
2478- textwrap .dedent (
2479- """
2476+ textwrap .dedent ("""
24802477 {create_counts_table}
24812478 CREATE TRIGGER IF NOT EXISTS {trigger_insert} AFTER INSERT ON {table}
24822479 BEGIN
@@ -2501,8 +2498,7 @@ def enable_counts(self) -> None:
25012498 );
25022499 END;
25032500 INSERT OR REPLACE INTO _counts VALUES ({table_quoted}, (select count(*) from {table}));
2504- """
2505- )
2501+ """ )
25062502 .strip ()
25072503 .format (
25082504 create_counts_table = _COUNTS_TABLE_CREATE_SQL .format (
@@ -2554,14 +2550,12 @@ def enable_fts(
25542550 :param replace: Should any existing FTS index for this table be replaced by the new one?
25552551 """
25562552 create_fts_sql = (
2557- textwrap .dedent (
2558- """
2553+ textwrap .dedent ("""
25592554 CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
25602555 {columns},{tokenize}
25612556 content={table}
25622557 )
2563- """
2564- )
2558+ """ )
25652559 .strip ()
25662560 .format (
25672561 table = quote_identifier (self .name ),
@@ -2599,8 +2593,7 @@ def enable_fts(
25992593 table = quote_identifier (self .name )
26002594 table_fts = quote_identifier (self .name + "_fts" )
26012595 triggers = (
2602- textwrap .dedent (
2603- """
2596+ textwrap .dedent ("""
26042597 CREATE TRIGGER {table_ai} AFTER INSERT ON {table} BEGIN
26052598 INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26062599 END;
@@ -2611,8 +2604,7 @@ def enable_fts(
26112604 INSERT INTO {table_fts} ({table_fts}, rowid, {columns}) VALUES('delete', old.rowid, {old_cols});
26122605 INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26132606 END;
2614- """
2615- )
2607+ """ )
26162608 .strip ()
26172609 .format (
26182610 table = table ,
@@ -2637,12 +2629,10 @@ def populate_fts(self, columns: Iterable[str]) -> "Table":
26372629 """
26382630 columns_quoted = ", " .join (quote_identifier (c ) for c in columns )
26392631 sql = (
2640- textwrap .dedent (
2641- """
2632+ textwrap .dedent ("""
26422633 INSERT INTO {table_fts} (rowid, {columns})
26432634 SELECT rowid, {columns} FROM {table};
2644- """
2645- )
2635+ """ )
26462636 .strip ()
26472637 .format (
26482638 table = quote_identifier (self .name ),
@@ -2659,17 +2649,11 @@ def disable_fts(self) -> "Table":
26592649 if fts_table :
26602650 self .db [fts_table ].drop ()
26612651 # Now delete the triggers that related to that table
2662- sql = (
2663- textwrap .dedent (
2664- """
2652+ sql = textwrap .dedent ("""
26652653 SELECT name FROM sqlite_master
26662654 WHERE type = 'trigger'
26672655 AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
2668- """
2669- )
2670- .strip ()
2671- .format (fts_table , fts_table )
2672- )
2656+ """ ).strip ().format (fts_table , fts_table )
26732657 trigger_names = []
26742658 for row in self .db .execute (sql ).fetchall ():
26752659 trigger_names .append (row [0 ])
@@ -2695,8 +2679,7 @@ def rebuild_fts(self) -> "Table":
26952679
26962680 def detect_fts (self ) -> Optional [str ]:
26972681 "Detect if table has a corresponding FTS virtual table and return it"
2698- sql = textwrap .dedent (
2699- """
2682+ sql = textwrap .dedent ("""
27002683 SELECT name FROM sqlite_master
27012684 WHERE rootpage = 0
27022685 AND (
@@ -2707,8 +2690,7 @@ def detect_fts(self) -> Optional[str]:
27072690 AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
27082691 )
27092692 )
2710- """
2711- ).strip ()
2693+ """ ).strip ()
27122694 args = {
27132695 "like" : '%VIRTUAL TABLE%USING FTS%content="{}"%' .format (self .name ),
27142696 "like2" : '%VIRTUAL TABLE%USING FTS%content="{}"%' .format (self .name ),
@@ -2724,13 +2706,9 @@ def optimize(self) -> "Table":
27242706 "Run the ``optimize`` operation against the associated full-text search index table."
27252707 fts_table = self .detect_fts ()
27262708 if fts_table is not None :
2727- self .db .execute (
2728- """
2709+ self .db .execute ("""
27292710 INSERT INTO {table} ({table}) VALUES ("optimize");
2730- """ .strip ().format (
2731- table = quote_identifier (fts_table )
2732- )
2733- )
2711+ """ .strip ().format (table = quote_identifier (fts_table )))
27342712 return self
27352713
27362714 def search_sql (
@@ -2768,8 +2746,7 @@ def search_sql(
27682746 )
27692747 fts_table_quoted = quote_identifier (fts_table )
27702748 virtual_table_using = self .db .table (fts_table ).virtual_table_using
2771- sql = textwrap .dedent (
2772- """
2749+ sql = textwrap .dedent ("""
27732750 with {original} as (
27742751 select
27752752 rowid,
@@ -2786,8 +2763,7 @@ def search_sql(
27862763 order by
27872764 {order_by}
27882765 {limit_offset}
2789- """
2790- ).strip ()
2766+ """ ).strip ()
27912767 if virtual_table_using == "FTS5" :
27922768 rank_implementation = "{}.rank" .format (fts_table_quoted )
27932769 else :
0 commit comments