MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _internal_has_table

Method _internal_has_table

lib/sqlalchemy/dialects/mssql/base.py:3456–3485  ·  view source on GitHub ↗
(self, connection, tablename, owner, **kw)

Source from the content-addressed store, hash-verified

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

Callers 2

has_tableMethod · 0.95

Calls 9

textFunction · 0.85
or_Method · 0.80
startswithMethod · 0.45
scalarMethod · 0.45
whereMethod · 0.45
selectMethod · 0.45
and_Method · 0.45
executeMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected