summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-10-10 10:41:13 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2021-10-31 12:18:02 -0400
commitde61582933b800272cc818d36de9e0b7f86aa4fe (patch)
treea849fa02e7b989f764072bdb1ff3226d55c6099e /lib/sqlalchemy/engine
parentcdce33e2ccb60365f12eb07c0b86fdc2b89b5033 (diff)
downloadsqlalchemy-de61582933b800272cc818d36de9e0b7f86aa4fe.tar.gz
The ``has_table`` method now also checks views
The :meth:`_engine.Inspector.has_table` method will now consistently check for views of the given name as well as tables. Previously this behavior was dialect dependent, with PostgreSQL, MySQL/MariaDB and SQLite supporting it, and Oracle and SQL Server not supporting it. Third party dialects should also seek to ensure their :meth:`_engine.Inspector.has_table` method searches for views as well as tables for the given name. Fixes: #7161 Change-Id: I9e523c76741b19596c81ef577dc6f0823e44183b
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/interfaces.py9
-rw-r--r--lib/sqlalchemy/engine/reflection.py8
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py
index d1484718e..fdaeaddcd 100644
--- a/lib/sqlalchemy/engine/interfaces.py
+++ b/lib/sqlalchemy/engine/interfaces.py
@@ -463,7 +463,7 @@ class Dialect(object):
def has_table(self, connection, table_name, schema=None, **kw):
"""For internal dialect use, check the existence of a particular table
- in the database.
+ or view in the database.
Given a :class:`_engine.Connection` object, a string table_name and
optional schema name, return True if the given table exists in the
@@ -481,6 +481,13 @@ class Dialect(object):
Alternatively, for legacy cross-compatibility, the
:meth:`_engine.Engine.has_table` method may be used.
+ .. versionchanged:: 2.0
+
+ The :meth:`_engine.Dialect.has_table` method should also check
+ for the presence of views. In previous versions this
+ behavior was dialect specific. New dialect suite tests were added
+ to ensure that dialects conform with this behavior consistently.
+
"""
raise NotImplementedError()
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index 113aa8ea0..d8c2bcbd7 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -268,8 +268,7 @@ class Inspector(object):
)
def has_table(self, table_name, schema=None):
- """Return True if the backend has a table of the given name.
-
+ """Return True if the backend has a table or view of the given name.
:param table_name: name of the table to check
:param schema: schema name to query, if not the default schema.
@@ -277,6 +276,11 @@ class Inspector(object):
.. versionadded:: 1.4 - the :meth:`.Inspector.has_table` method
replaces the :meth:`_engine.Engine.has_table` method.
+ .. versionchanged:: 2.0:: The method checks also for views.
+ In previous version this behaviour was dialect specific. New
+ dialect suite tests were added to ensure all dialect conform with
+ this behaviour.
+
"""
# TODO: info_cache?
with self._operation_context() as conn: