From 893eac06e511f3765c0c89bab76d7933d83ffccc Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Mon, 16 Jul 2018 10:10:55 -0400 Subject: Fix quoting schemas in _get_table_sql for the SQLite backend Fixed issue where the "schema" name used for a SQLite database within table reflection would not quote the schema name correctly. Pull request courtesy Phillip Cloud. Change-Id: I2770788c1f094a7743209250ec26b5ef5fb2d9e8 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/463 --- lib/sqlalchemy/dialects/sqlite/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/dialects/sqlite') diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index c6932be8f..cc17b6c9b 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1567,20 +1567,25 @@ class SQLiteDialect(default.DefaultDialect): @reflection.cache def _get_table_sql(self, connection, table_name, schema=None, **kw): + if schema: + schema_expr = "%s." % ( + self.identifier_preparer.quote_identifier(schema)) + else: + schema_expr = "" try: s = ("SELECT sql FROM " " (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 "", + "schema": schema_expr, "table": table_name}) rs = connection.execute(s) except exc.DBAPIError: s = ("SELECT sql FROM %(schema)ssqlite_master " "WHERE name = '%(table)s' " "AND type = 'table'" % { - "schema": ("%s." % schema) if schema else "", + "schema": schema_expr, "table": table_name}) rs = connection.execute(s) return rs.scalar() -- cgit v1.2.1