--- /dev/null
+.. change::
+ :tag: bug, sqlite
+
+ 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.
@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()
assert b.c.id.references(a.c.id)
+class KeywordInDatabaseNameTest(fixtures.TestBase):
+ __only_on__ = 'sqlite'
+
+ @classmethod
+ def setup_class(cls):
+ with testing.db.begin() as conn:
+ conn.execute("ATTACH %r AS \"default\"" % conn.engine.url.database)
+ conn.execute('CREATE TABLE "default".a (id INTEGER PRIMARY KEY)')
+
+ @classmethod
+ def teardown_class(cls):
+ with testing.db.begin() as conn:
+ try:
+ conn.execute('drop table "default".a')
+ except Exception:
+ pass
+ conn.execute('DETACH DATABASE "default"')
+
+ def test_reflect(self):
+ with testing.db.begin() as conn:
+ meta = MetaData(bind=conn, schema='default')
+ meta.reflect()
+ assert 'default.a' in meta.tables
+
+
class ConstraintReflectionTest(fixtures.TestBase):
__only_on__ = 'sqlite'