summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/sqlite/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-28 16:47:28 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-28 16:51:35 -0400
commit68b52c48b775f9a99d0bc3666ebe02c54e401303 (patch)
tree3bd8eca79db0f4458ec87269934e6497fdbd0145 /lib/sqlalchemy/dialects/sqlite/base.py
parent21ff71b0eb032d8ffd125ba7532ca2d29a206fb9 (diff)
downloadsqlalchemy-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.py17
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()