[sql lab] quote schema and table name (#5195)

fixes https://github.com/apache/incubator-superset/issues/4595
This commit is contained in:
Maxime Beauchemin 2018-06-18 08:42:08 -07:00 committed by GitHub
parent ccf211036d
commit c89933d870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -275,7 +275,7 @@ class BaseEngineSpec(object):
return False
@classmethod
def select_star(cls, my_db, table_name, schema=None, limit=100,
def select_star(cls, my_db, table_name, engine, schema=None, limit=100,
show_cols=False, indent=True, latest_partition=True,
cols=None):
fields = '*'
@ -286,9 +286,14 @@ class BaseEngineSpec(object):
if show_cols:
fields = [sqla.column(c.get('name')) for c in cols]
full_table_name = table_name
quote = engine.dialect.identifier_preparer.quote
if schema:
full_table_name = schema + '.' + table_name
full_table_name = quote(schema) + '.' + quote(table_name)
else:
full_table_name = quote(table_name)
qry = select(fields).select_from(text(full_table_name))
if limit:
qry = qry.limit(limit)
if latest_partition:

View File

@ -720,8 +720,10 @@ class Database(Model, AuditMixinNullable, ImportMixin):
self, table_name, schema=None, limit=100, show_cols=False,
indent=True, latest_partition=True, cols=None):
"""Generates a ``select *`` statement in the proper dialect"""
eng = self.get_sqla_engine(schema=schema)
return self.db_engine_spec.select_star(
self, table_name, schema=schema, limit=limit, show_cols=show_cols,
self, table_name, schema=schema, engine=eng,
limit=limit, show_cols=show_cols,
indent=indent, latest_partition=latest_partition, cols=cols)
def apply_limit_to_sql(self, sql, limit=1000):