Skip to content

Commit 473e78d

Browse files
committed
Fix false filtering out table names with "sqlite" prefix instead of "sqlite_"
1 parent a26f75c commit 473e78d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Lib/sqlite3/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
7272
END
7373
FROM "{schema}".sqlite_master
7474
WHERE type IN ('table', 'view')
75-
AND name NOT LIKE 'sqlite_%'"""
75+
AND name NOT LIKE 'sqlite_%' ESCAPE '_'"""
7676
for schema in schema_names
7777
)
7878
command = " UNION ALL ".join(select_clauses) + " ORDER BY 1"

Lib/test/test_sqlite3/test_cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def test_interact_version(self):
128128
def test_interact_tables(self):
129129
out, err = self.run_cli(commands=(
130130
"CREATE TABLE table_ (id INTEGER);",
131+
"CREATE TABLE sqlitee (id INTEGER);",
131132
"CREATE TEMP TABLE temp_table (id INTEGER);",
132133
"CREATE VIEW view_ AS SELECT 1;",
133134
"CREATE TEMP VIEW temp_view AS SELECT 1;",
@@ -141,10 +142,18 @@ def test_interact_tables(self):
141142
))
142143
self.assertIn(self.MEMORY_DB_MSG, err)
143144
self.assertEndsWith(out, self.PS1)
144-
self.assertEqual(out.count(self.PS1), 12)
145+
self.assertEqual(out.count(self.PS1), 13)
145146
self.assertEqual(out.count(self.PS2), 0)
146-
self.assertIn("123.table_\n123.view_\nattach_.table_\nattach_.view_\n"
147-
"table_\ntemp.temp_table\ntemp.temp_view\nview_\n", out)
147+
tables = ("123.table_",
148+
"123.view_",
149+
"attach_.table_",
150+
"attach_.view_",
151+
"sqlitee",
152+
"table_",
153+
"temp.temp_table",
154+
"temp.temp_view",
155+
"view_")
156+
self.assertIn("\n".join(tables), out)
148157

149158
def test_interact_empty_source(self):
150159
out, err = self.run_cli(commands=("", " "))

0 commit comments

Comments
 (0)