]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Changed the queries used by Firebird to list table and view names
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Dec 2013 21:39:54 +0000 (16:39 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Dec 2013 21:39:54 +0000 (16:39 -0500)
to query from the ``rdb$relations`` view instead of the
``rdb$relation_fields`` and ``rdb$view_relations`` views.
Variants of both the old and new queries are mentioned on many
FAQ and blogs, however the new queries are taken straight from
the "Firebird FAQ" which appears to be the most official source
of info. [ticket:2898]

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/firebird/base.py

index 3106eefb80aeb7264372b64018f0beb404afdecb..61a368decf6feca73d2a5b20d5838232b9f3a8d8 100644 (file)
 .. changelog::
     :version: 0.9.0b2
 
+    .. change::
+        :tags: bug, firebird
+        :tickets: 2898
+
+        Changed the queries used by Firebird to list table and view names
+        to query from the ``rdb$relations`` view instead of the
+        ``rdb$relation_fields`` and ``rdb$view_relations`` views.
+        Variants of both the old and new queries are mentioned on many
+        FAQ and blogs, however the new queries are taken straight from
+        the "Firebird FAQ" which appears to be the most official source
+        of info.
+
     .. change::
         :tags: bug, mysql
         :tickets: 2893
index 777d3ce26664491cf36fd7f26d1d301314c312ba..0a305e054f8b4d9b264ad8d59f8c3b90b51c0bbb 100644 (file)
@@ -475,18 +475,34 @@ class FBDialect(default.DefaultDialect):
 
     @reflection.cache
     def get_table_names(self, connection, schema=None, **kw):
+        # there are two queries commonly mentioned for this.
+        # this one, using view_blr, is at the Firebird FAQ among other places:
+        # http://www.firebirdfaq.org/faq174/
         s = """
-        SELECT DISTINCT rdb$relation_name
-        FROM rdb$relation_fields
-        WHERE rdb$system_flag=0 AND rdb$view_context IS NULL
+        select rdb$relation_name
+        from rdb$relations
+        where rdb$view_blr is null
+        and (rdb$system_flag is null or rdb$system_flag = 0);
         """
+
+        # the other query is this one.  It's not clear if there's really
+        # any difference between these two.  This link:
+        # http://www.alberton.info/firebird_sql_meta_info.html#.Ur3vXfZGni8
+        # states them as interchangeable.  Some discussion at [ticket:2898]
+        # SELECT DISTINCT rdb$relation_name
+        # FROM rdb$relation_fields
+        # WHERE rdb$system_flag=0 AND rdb$view_context IS NULL
+
         return [self.normalize_name(row[0]) for row in connection.execute(s)]
 
     @reflection.cache
     def get_view_names(self, connection, schema=None, **kw):
+        # see http://www.firebirdfaq.org/faq174/
         s = """
-        SELECT distinct rdb$view_name
-        FROM rdb$view_relations
+        select rdb$relation_name
+        from rdb$relations
+        where rdb$view_blr is not null
+        and (rdb$system_flag is null or rdb$system_flag = 0);
         """
         return [self.normalize_name(row[0]) for row in connection.execute(s)]