1111_completion_matches = []
1212
1313
14+ def _quote_schema (schema ):
15+ # Quote an SQLite identifier, doubling embedded double quotes.
16+ return '"' + schema .replace ('"' , '""' ) + '"'
17+
18+
1419def _complete (con , text , state ):
1520 global _completion_matches
1621
@@ -32,7 +37,7 @@ def _complete(con, text, state):
3237 # escape '_' which can appear in attached database names
3338 select_clauses = (
3439 f"""\
35- SELECT name || ' ' FROM \" { schema } \" .sqlite_master
40+ SELECT name || ' ' FROM { _quote_schema ( schema ) } .sqlite_master
3641 WHERE name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'"""
3742 for schema in schemata
3843 )
@@ -46,8 +51,8 @@ def _complete(con, text, state):
4651 try :
4752 select_clauses = (
4853 f"""\
49- SELECT pti.name || ' ' FROM " { schema } " .sqlite_master AS sm
50- JOIN pragma_table_xinfo(sm.name,' { schema } ' ) AS pti
54+ SELECT pti.name || ' ' FROM { _quote_schema ( schema ) } .sqlite_master AS sm
55+ JOIN pragma_table_xinfo(sm.name,{ _quote_schema ( schema ) } ) AS pti
5156 WHERE sm.type='table' AND
5257 pti.name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'"""
5358 for schema in schemata
@@ -108,4 +113,4 @@ def complete(text, state):
108113 readline .parse_and_bind (command_string )
109114 yield
110115 finally :
111- readline .set_completer (old_completer )
116+ readline .set_completer (old_completer )
0 commit comments