diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-02 13:03:29 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-02 17:41:24 -0400 |
| commit | e091775f1c4c817093e9a936a3abc79b5e311f93 (patch) | |
| tree | ef1f8dc40d92176ff8eda0a2896fc060f3fc449d /lib/sqlalchemy/testing/suite/test_reflection.py | |
| parent | a4e0995dc817acda7d669b8925c9bc3defdb660b (diff) | |
| download | sqlalchemy-e091775f1c4c817093e9a936a3abc79b5e311f93.tar.gz | |
Always include a schema name in SQLite PRAGMA
Fixed bug where usage of "PRAGMA table_info" in SQLite dialect meant that
reflection features to detect for table existence, list of table columns,
and list of foreign keys, would default to any table in any attached
database, when no schema name was given and the table did not exist in the
base schema. The fix explicitly runs PRAGMA for the 'main' schema and then
the 'temp' schema if the 'main' returned no rows, to maintain the behavior
of tables + temp tables in the "no schema" namespace, attached tables only
in the "schema" namespace.
Fixes: #4793
Change-Id: I75bc03ef42581c46b98987510d2d2e701df07412
Diffstat (limited to 'lib/sqlalchemy/testing/suite/test_reflection.py')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 53e1599b3..9ca13ec4e 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -24,6 +24,8 @@ from ...engine.reflection import Inspector from ...schema import DDL from ...schema import Index from ...sql.elements import quoted_name +from ...testing import is_false +from ...testing import is_true metadata, users = None, None @@ -40,11 +42,39 @@ class HasTableTest(fixtures.TablesTest): Column("id", Integer, primary_key=True), Column("data", String(50)), ) + if testing.requires.schemas.enabled: + Table( + "test_table_s", + metadata, + Column("id", Integer, primary_key=True), + Column("data", String(50)), + schema=config.test_schema, + ) def test_has_table(self): with config.db.begin() as conn: - assert config.db.dialect.has_table(conn, "test_table") - assert not config.db.dialect.has_table(conn, "nonexistent_table") + is_true(config.db.dialect.has_table(conn, "test_table")) + is_false(config.db.dialect.has_table(conn, "test_table_s")) + is_false(config.db.dialect.has_table(conn, "nonexistent_table")) + + @testing.requires.schemas + def test_has_table_schema(self): + with config.db.begin() as conn: + is_false( + config.db.dialect.has_table( + conn, "test_table", schema=config.test_schema + ) + ) + is_true( + config.db.dialect.has_table( + conn, "test_table_s", schema=config.test_schema + ) + ) + is_false( + config.db.dialect.has_table( + conn, "nonexistent_table", schema=config.test_schema + ) + ) class ComponentReflectionTest(fixtures.TablesTest): |
