Skip to content

Commit 01a683a

Browse files
authored
gh-158277: sqlite3 CLI completer: include views in column completion (GH-158278)
1 parent 395d766 commit 01a683a

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎Lib/sqlite3/_completer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _complete(con, text, state):
4848
f"""\
4949
SELECT pti.name || ' ' FROM "{schema}".sqlite_master AS sm
5050
JOIN pragma_table_xinfo(sm.name,'{schema}') AS pti
51-
WHERE sm.type='table' AND
51+
WHERE sm.type IN ('table', 'view') AND
5252
pti.name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'"""
5353
for schema in schemata
5454
)

‎Lib/test/test_sqlite3/test_cli.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ def test_complete_columns(self):
326326
input_ = textwrap.dedent("""\
327327
CREATE TABLE _table (_col_table);
328328
CREATE TEMP TABLE _temp_table (_col_temp);
329+
CREATE VIEW _view AS SELECT _col_table AS _col_table_alias
330+
FROM _table;
329331
ATTACH ':memory:' AS attached;
330332
CREATE TABLE attached._attached_table (_col_attached);
331333
@@ -340,9 +342,9 @@ def test_complete_columns(self):
340342
candidates = [l.strip() for l in lines[start+1:end]]
341343

342344
self.assertEqual(
343-
candidates, ["_col_attached", "_col_table", "_col_temp"]
345+
candidates,
346+
["_col_attached", "_col_table", "_col_table_alias", "_col_temp"],
344347
)
345-
346348
@unittest.skipIf(sqlite3.sqlite_version_info < (3, 30, 0),
347349
"PRAGMA function_list is not available until "
348350
"SQLite 3.30.0")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :mod:`sqlite3` CLI completer to include view columns in
2+
column-name completion.
3+

0 commit comments

Comments
 (0)