|
23 | 23 | from sqlalchemy.dialects import mysql
|
24 | 24 | mysql_tinyinteger = mysql.base.MSTinyInteger
|
25 | 25 | from sqlalchemy.engine import default
|
26 |
| -from sqlalchemy.sql import compiler |
| 26 | +from sqlalchemy.sql import compiler, bindparam |
27 | 27 | from sqlalchemy.sql.compiler import SQLCompiler
|
28 | 28 |
|
29 | 29 | from pyhive import presto
|
@@ -205,10 +205,44 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
|
205 | 205 | return []
|
206 | 206 |
|
207 | 207 | def get_table_names(self, connection, schema=None, **kw):
|
208 |
| - query = 'SHOW TABLES' |
209 | 208 | if schema:
|
210 |
| - query += ' FROM ' + self.identifier_preparer.quote_identifier(schema) |
211 |
| - return [row.Table for row in connection.execute(text(query))] |
| 209 | + table_name_query = """ |
| 210 | + SELECT table_name FROM information_schema.tables |
| 211 | + WHERE table_type = 'TABLE' |
| 212 | + AND table_schema = :schema |
| 213 | + """ |
| 214 | + query = text(table_name_query).bindparams( |
| 215 | + bindparam("schema", type_=types.Unicode) |
| 216 | + ) |
| 217 | + else: |
| 218 | + table_name_query = """ |
| 219 | + SELECT table_name FROM information_schema.tables |
| 220 | + WHERE table_type = 'VIEW' |
| 221 | + """ |
| 222 | + query = text(table_name_query) |
| 223 | + |
| 224 | + result = connection.execute(query, dict(schema=schema)) |
| 225 | + return [row[0] for row in result] |
| 226 | + |
| 227 | + def get_view_names(self, connection, schema=None, **kw): |
| 228 | + if schema: |
| 229 | + view_name_query = """ |
| 230 | + SELECT table_name FROM information_schema.tables |
| 231 | + WHERE table_type = 'VIEW' |
| 232 | + AND table_schema = :schema |
| 233 | + """ |
| 234 | + query = text(view_name_query).bindparams( |
| 235 | + bindparam("schema", type_=types.Unicode) |
| 236 | + ) |
| 237 | + else: |
| 238 | + view_name_query = """ |
| 239 | + SELECT table_name FROM information_schema.tables |
| 240 | + WHERE table_type = 'VIEW' |
| 241 | + """ |
| 242 | + query = text(view_name_query) |
| 243 | + |
| 244 | + result = connection.execute(query, dict(schema=schema)) |
| 245 | + return [row[0] for row in result] |
212 | 246 |
|
213 | 247 | def do_rollback(self, dbapi_connection):
|
214 | 248 | # No transactions for Presto
|
|
0 commit comments