@@ -77,19 +77,22 @@ def get_table_list(self, cursor):
7777 """
7878 Returns a list of table and view names in the current database.
7979 """
80- sql = """SELECT
81- TABLE_NAME,
82- TABLE_TYPE,
83- CAST(ep.value AS VARCHAR) AS COMMENT
84- FROM INFORMATION_SCHEMA.TABLES i
85- LEFT JOIN sys.tables t ON t.name = i.TABLE_NAME
86- LEFT JOIN sys.extended_properties ep ON t.object_id = ep.major_id
87- AND ((ep.name = 'MS_DESCRIPTION' AND ep.minor_id = 0) OR ep.value IS NULL)
88- AND i.TABLE_SCHEMA = %s""" % (
89- get_schema_name ())
80+ if VERSION >= (4 , 2 ) and self .connection .features .supports_comments :
81+ sql = """SELECT
82+ TABLE_NAME,
83+ TABLE_TYPE,
84+ CAST(ep.value AS VARCHAR) AS COMMENT
85+ FROM INFORMATION_SCHEMA.TABLES i
86+ LEFT JOIN sys.tables t ON t.name = i.TABLE_NAME
87+ LEFT JOIN sys.extended_properties ep ON t.object_id = ep.major_id
88+ AND ((ep.name = 'MS_DESCRIPTION' AND ep.minor_id = 0) OR ep.value IS NULL)
89+ AND i.TABLE_SCHEMA = %s""" % (
90+ get_schema_name ())
91+ else :
92+ sql = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = %s' % (get_schema_name ())
9093 cursor .execute (sql )
9194 types = {'BASE TABLE' : 't' , 'VIEW' : 'v' }
92- if VERSION >= (4 , 2 ):
95+ if VERSION >= (4 , 2 ) and self . connection . features . supports_comments :
9396 return [TableInfo (row [0 ], types .get (row [1 ]), row [2 ])
9497 for row in cursor .fetchall ()
9598 if row [0 ] not in self .ignored_tables ]
@@ -145,7 +148,7 @@ def get_table_description(self, cursor, table_name, identity_check=True):
145148 column .append (collation_name [0 ] if collation_name else '' )
146149 else :
147150 column .append ('' )
148- if VERSION >= (4 , 2 ):
151+ if VERSION >= (4 , 2 ) and self . connection . features . supports_comments :
149152 sql = """select CAST(ep.value AS VARCHAR) AS COMMENT
150153 FROM sys.columns c
151154 INNER JOIN sys.tables t ON c.object_id = t.object_id
@@ -174,8 +177,7 @@ def get_table_description(self, cursor, table_name, identity_check=True):
174177 start += 1
175178 end -= 1
176179 column [7 ] = default_value [start :end + 1 ]
177-
178- if VERSION >= (4 , 2 ):
180+ if VERSION >= (4 , 2 ) and self .connection .features .supports_comments :
179181 items .append (FieldInfo (* column ))
180182 else :
181183 items .append (BaseFieldInfo (* column ))
0 commit comments