diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-10-29 01:36:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-10-29 01:36:19 +0000 |
| commit | ed7bef700477ac85819040478ce2f2cca78c5700 (patch) | |
| tree | cbc47a732d2c4defffd90b491b4fa867245f43ef /lib/sqlalchemy/dialects | |
| parent | 92cafa979370478f5fc698fd82b4caac3d7971fa (diff) | |
| parent | 59f2d0c96152128d8e02e43dcda045593153c86e (diff) | |
| download | sqlalchemy-ed7bef700477ac85819040478ce2f2cca78c5700.tar.gz | |
Merge "use only object_id() function for temp tables" into main
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index fdb0704f6..5d42d98e3 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -3226,28 +3226,13 @@ class MSDialect(default.DefaultDialect): if tablename.startswith("#"): # temporary table # mssql does not support temporary views # SQL Error [4103] [S0001]: "#v": Temporary views are not allowed - tables = ischema.mssql_temp_table_columns - - s = sql.select(tables.c.table_name).where( - tables.c.table_name.like( - self._temp_table_name_like_pattern(tablename) + return bool( + connection.scalar( + # U filters on user tables only. + text("SELECT object_id(:table_name, 'U')"), + {"table_name": "tempdb.dbo.[{}]".format(tablename)}, ) ) - - # #7168: fetch all (not just first match) in case some other #temp - # table with the same name happens to appear first - table_names = connection.scalars(s).all() - # #6910: verify it's not a temp table from another session - for table_name in table_names: - if bool( - connection.scalar( - text("SELECT object_id(:table_name)"), - {"table_name": "tempdb.dbo.[{}]".format(table_name)}, - ) - ): - return True - else: - return False else: tables = ischema.tables |
