diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-28 16:47:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-28 16:51:35 -0400 |
| commit | 68b52c48b775f9a99d0bc3666ebe02c54e401303 (patch) | |
| tree | 3bd8eca79db0f4458ec87269934e6497fdbd0145 /lib/sqlalchemy/dialects/sqlite/base.py | |
| parent | 21ff71b0eb032d8ffd125ba7532ca2d29a206fb9 (diff) | |
| download | sqlalchemy-68b52c48b775f9a99d0bc3666ebe02c54e401303.tar.gz | |
Take schema name into account when querying sqlite_master
Fixed bug where SQLite CHECK constraint reflection would fail
if the referenced table were in a remote schema, e.g. on SQLite a
remote database referred to by ATTACH.
Also add suite support for general CHECK constraint reflection.
Change-Id: I073a72cb47dc4f8c5683000d708768523759332f
Fixes: #4099
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/base.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 4bc60be62..d8ce7f394 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1545,14 +1545,19 @@ class SQLiteDialect(default.DefaultDialect): def _get_table_sql(self, connection, table_name, schema=None, **kw): try: s = ("SELECT sql FROM " - " (SELECT * FROM sqlite_master UNION ALL " - " SELECT * FROM sqlite_temp_master) " - "WHERE name = '%s' " - "AND type = 'table'") % table_name + " (SELECT * FROM %(schema)ssqlite_master UNION ALL " + " SELECT * FROM %(schema)ssqlite_temp_master) " + "WHERE name = '%(table)s' " + "AND type = 'table'" % { + "schema": ("%s." % schema) if schema else "", + "table": table_name}) rs = connection.execute(s) except exc.DBAPIError: - s = ("SELECT sql FROM sqlite_master WHERE name = '%s' " - "AND type = 'table'") % table_name + s = ("SELECT sql FROM %(schema)ssqlite_master " + "WHERE name = '%(table)s' " + "AND type = 'table'" % { + "schema": ("%s." % schema) if schema else "", + "table": table_name}) rs = connection.execute(s) return rs.scalar() |
