@@ -2348,12 +2348,10 @@ def create_index(
23482348 "{}_{}" .format (index_name , suffix ) if suffix else index_name
23492349 )
23502350 sql = (
2351- textwrap .dedent (
2352- """
2351+ textwrap .dedent ("""
23532352 CREATE {unique}INDEX {if_not_exists}{index_name}
23542353 ON {table_name} ({columns});
2355- """
2356- )
2354+ """ )
23572355 .strip ()
23582356 .format (
23592357 index_name = quote_identifier (created_index_name ),
@@ -2548,8 +2546,7 @@ def enable_counts(self) -> None:
25482546 See :ref:`python_api_cached_table_counts` for details.
25492547 """
25502548 sql = (
2551- textwrap .dedent (
2552- """
2549+ textwrap .dedent ("""
25532550 {create_counts_table}
25542551 CREATE TRIGGER IF NOT EXISTS {trigger_insert} AFTER INSERT ON {table}
25552552 BEGIN
@@ -2574,8 +2571,7 @@ def enable_counts(self) -> None:
25742571 );
25752572 END;
25762573 INSERT OR REPLACE INTO _counts VALUES ({table_quoted}, (select count(*) from {table}));
2577- """
2578- )
2574+ """ )
25792575 .strip ()
25802576 .format (
25812577 create_counts_table = _COUNTS_TABLE_CREATE_SQL .format (
@@ -2627,14 +2623,12 @@ def enable_fts(
26272623 :param replace: Should any existing FTS index for this table be replaced by the new one?
26282624 """
26292625 create_fts_sql = (
2630- textwrap .dedent (
2631- """
2626+ textwrap .dedent ("""
26322627 CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
26332628 {columns},{tokenize}
26342629 content={table}
26352630 )
2636- """
2637- )
2631+ """ )
26382632 .strip ()
26392633 .format (
26402634 table = quote_identifier (self .name ),
@@ -2672,8 +2666,7 @@ def enable_fts(
26722666 table = quote_identifier (self .name )
26732667 table_fts = quote_identifier (self .name + "_fts" )
26742668 triggers = (
2675- textwrap .dedent (
2676- """
2669+ textwrap .dedent ("""
26772670 CREATE TRIGGER {table_ai} AFTER INSERT ON {table} BEGIN
26782671 INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26792672 END;
@@ -2684,8 +2677,7 @@ def enable_fts(
26842677 INSERT INTO {table_fts} ({table_fts}, rowid, {columns}) VALUES('delete', old.rowid, {old_cols});
26852678 INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26862679 END;
2687- """
2688- )
2680+ """ )
26892681 .strip ()
26902682 .format (
26912683 table = table ,
@@ -2710,12 +2702,10 @@ def populate_fts(self, columns: Iterable[str]) -> "Table":
27102702 """
27112703 columns_quoted = ", " .join (quote_identifier (c ) for c in columns )
27122704 sql = (
2713- textwrap .dedent (
2714- """
2705+ textwrap .dedent ("""
27152706 INSERT INTO {table_fts} (rowid, {columns})
27162707 SELECT rowid, {columns} FROM {table};
2717- """
2718- )
2708+ """ )
27192709 .strip ()
27202710 .format (
27212711 table = quote_identifier (self .name ),
@@ -2732,17 +2722,11 @@ def disable_fts(self) -> "Table":
27322722 if fts_table :
27332723 self .db [fts_table ].drop ()
27342724 # Now delete the triggers that related to that table
2735- sql = (
2736- textwrap .dedent (
2737- """
2725+ sql = textwrap .dedent ("""
27382726 SELECT name FROM sqlite_master
27392727 WHERE type = 'trigger'
27402728 AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
2741- """
2742- )
2743- .strip ()
2744- .format (fts_table , fts_table )
2745- )
2729+ """ ).strip ().format (fts_table , fts_table )
27462730 trigger_names = []
27472731 for row in self .db .execute (sql ).fetchall ():
27482732 trigger_names .append (row [0 ])
@@ -2768,8 +2752,7 @@ def rebuild_fts(self) -> "Table":
27682752
27692753 def detect_fts (self ) -> Optional [str ]:
27702754 "Detect if table has a corresponding FTS virtual table and return it"
2771- sql = textwrap .dedent (
2772- """
2755+ sql = textwrap .dedent ("""
27732756 SELECT name FROM sqlite_master
27742757 WHERE rootpage = 0
27752758 AND (
@@ -2780,8 +2763,7 @@ def detect_fts(self) -> Optional[str]:
27802763 AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
27812764 )
27822765 )
2783- """
2784- ).strip ()
2766+ """ ).strip ()
27852767 args = {
27862768 "like" : '%VIRTUAL TABLE%USING FTS%content="{}"%' .format (self .name ),
27872769 "like2" : '%VIRTUAL TABLE%USING FTS%content="{}"%' .format (self .name ),
@@ -2797,13 +2779,9 @@ def optimize(self) -> "Table":
27972779 "Run the ``optimize`` operation against the associated full-text search index table."
27982780 fts_table = self .detect_fts ()
27992781 if fts_table is not None :
2800- self .db .execute (
2801- """
2782+ self .db .execute ("""
28022783 INSERT INTO {table} ({table}) VALUES ("optimize");
2803- """ .strip ().format (
2804- table = quote_identifier (fts_table )
2805- )
2806- )
2784+ """ .strip ().format (table = quote_identifier (fts_table )))
28072785 return self
28082786
28092787 def search_sql (
@@ -2841,8 +2819,7 @@ def search_sql(
28412819 )
28422820 fts_table_quoted = quote_identifier (fts_table )
28432821 virtual_table_using = self .db .table (fts_table ).virtual_table_using
2844- sql = textwrap .dedent (
2845- """
2822+ sql = textwrap .dedent ("""
28462823 with {original} as (
28472824 select
28482825 rowid,
@@ -2859,8 +2836,7 @@ def search_sql(
28592836 order by
28602837 {order_by}
28612838 {limit_offset}
2862- """
2863- ).strip ()
2839+ """ ).strip ()
28642840 if virtual_table_using == "FTS5" :
28652841 rank_implementation = "{}.rank" .format (fts_table_quoted )
28662842 else :
0 commit comments