From 68b52c48b775f9a99d0bc3666ebe02c54e401303 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 28 Sep 2017 16:47:28 -0400 Subject: 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 --- lib/sqlalchemy/dialects/sqlite/base.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/dialects/sqlite/base.py') 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() -- cgit v1.2.1