8000 gh-135795: Support `.tables` in the sqlite3 command-line interface by tanloong · Pull Request #135796 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135795: Support .tables in the sqlite3 command-line interface #135796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix false filtering out table names with "sqlite" prefix instead of "…
…sqlite_"
  • Loading branch information
tanloong committed Jun 23, 2025
commit 473e78dd27c91df020b8f6b1ef85445fc9db55a5
2 changes: 1 addition & 1 deletion Lib/sqlite3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
END
FROM "{schema}".sqlite_master
WHERE type IN ('table', 'view')
AND name NOT LIKE 'sqlite_%'"""
AND name NOT LIKE 'sqlite_%' ESCAPE '_'"""
for schema in schema_names
)
command = " UNION ALL ".join(select_clauses) + " ORDER BY 1"
Expand Down
15 changes: 12 additions & 3 deletions Lib/test/test_sqlite3/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_interact_version(self):
def test_interact_tables(self):
out, err = self.run_cli(commands=(
"CREATE TABLE table_ (id INTEGER);",
"CREATE TABLE sqlitee (id INTEGER);",
"CREATE TEMP TABLE temp_table (id INTEGER);",
"CREATE VIEW view_ AS SELECT 1;",
"CREATE TEMP VIEW temp_view AS SELECT 1;",
Expand All @@ -141,10 +142,18 @@ def test_interact_tables(self):
))
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 12)
self.assertEqual(out.count(self.PS1), 13)
self.assertEqual(out.count(self.PS2), 0)
self.assertIn("123.table_\n123.view_\nattach_.table_\nattach_.view_\n"
"table_\ntemp.temp_table\ntemp.temp_view\nview_\n", out)
tables = ("123.table_",
"123.view_",
"attach_.table_",
"attach_.view_",
"sqlitee",
"table_",
"temp.temp_table",
"temp.temp_view",
"view_")
self.assertIn("\n".join(tables), out)

def test_interact_empty_source(self):
out, err = self.run_cli(commands=("", " "))
Expand Down
Loading
0