|
8 | 8 |
|
9 | 9 | from django import VERSION |
10 | 10 | from django.db.backends.base.introspection import BaseDatabaseIntrospection |
11 | | -from django.db.backends.base.introspection import FieldInfo |
| 11 | +from django.db.backends.base.introspection import FieldInfo as BaseFieldInfo |
12 | 12 | from django.db.backends.base.introspection import TableInfo as BaseTableInfo |
13 | 13 | from django.db.models.indexes import Index |
14 | 14 | from django.conf import settings |
|
17 | 17 | SQL_BIGAUTOFIELD = -777444 |
18 | 18 | SQL_TIMESTAMP_WITH_TIMEZONE = -155 |
19 | 19 |
|
| 20 | +FieldInfo = namedtuple("FieldInfo", BaseFieldInfo._fields + ("comment",)) |
20 | 21 | TableInfo = namedtuple("TableInfo", BaseTableInfo._fields + ("comment",)) |
21 | 22 |
|
22 | 23 | def get_schema_name(): |
@@ -144,15 +145,27 @@ def get_table_description(self, cursor, table_name, identity_check=True): |
144 | 145 | column.append(collation_name[0] if collation_name else '') |
145 | 146 | else: |
146 | 147 | column.append('') |
147 | | - |
| 148 | + if VERSION >= (4, 2): |
| 149 | + sql = """select CAST(ep.value AS VARCHAR) AS COMMENT |
| 150 | + FROM sys.columns c |
| 151 | + INNER JOIN sys.tables t ON c.object_id = t.object_id |
| 152 | + INNER JOIN sys.extended_properties ep ON c.object_id=ep.major_id AND ep.minor_id = c.column_id |
| 153 | + WHERE t.name = '%s' AND c.name = '%s' AND ep.name = 'MS_Description' |
| 154 | + """ % (table_name, column[0]) |
| 155 | + cursor.execute(sql) |
| 156 | + comment = cursor.fetchone() |
| 157 | + column.append(comment) |
148 | 158 | if identity_check and self._is_auto_field(cursor, table_name, column[0]): |
149 | 159 | if column[1] == Database.SQL_BIGINT: |
150 | 160 | column[1] = SQL_BIGAUTOFIELD |
151 | 161 | else: |
152 | 162 | column[1] = SQL_AUTOFIELD |
153 | 163 | if column[1] == Database.SQL_WVARCHAR and column[3] < 4000: |
154 | 164 | column[1] = Database.SQL_WCHAR |
155 | | - items.append(FieldInfo(*column)) |
| 165 | + if VERSION >= (4, 2): |
| 166 | + items.append(FieldInfo(*column)) |
| 167 | + else: |
| 168 | + items.append(BaseFieldInfo(*column)) |
156 | 169 | return items |
157 | 170 |
|
158 | 171 | def get_sequences(self, cursor, table_name, table_fields=()): |
|
0 commit comments