| 3454 | |
| 3455 | @reflection.cache |
| 3456 | def _internal_has_table(self, connection, tablename, owner, **kw): |
| 3457 | if tablename.startswith("#"): # temporary table |
| 3458 | # mssql does not support temporary views |
| 3459 | # SQL Error [4103] [S0001]: "#v": Temporary views are not allowed |
| 3460 | return bool( |
| 3461 | connection.scalar( |
| 3462 | # U filters on user tables only. |
| 3463 | text("SELECT object_id(:table_name, 'U')"), |
| 3464 | {"table_name": f"tempdb.dbo.[{tablename}]"}, |
| 3465 | ) |
| 3466 | ) |
| 3467 | else: |
| 3468 | tables = ischema.tables |
| 3469 | |
| 3470 | s = sql.select(tables.c.table_name).where( |
| 3471 | sql.and_( |
| 3472 | sql.or_( |
| 3473 | tables.c.table_type == "BASE TABLE", |
| 3474 | tables.c.table_type == "VIEW", |
| 3475 | ), |
| 3476 | tables.c.table_name == tablename, |
| 3477 | ) |
| 3478 | ) |
| 3479 | |
| 3480 | if owner: |
| 3481 | s = s.where(tables.c.table_schema == owner) |
| 3482 | |
| 3483 | c = connection.execute(s) |
| 3484 | |
| 3485 | return c.first() is not None |
| 3486 | |
| 3487 | @reflection.cache |
| 3488 | @_db_plus_owner |