Skip to content

Commit

Permalink
Merge branch 'dev' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mShan0 authored Apr 2, 2024
2 parents c67001c + 99e83fd commit 82cb956
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
30 changes: 16 additions & 14 deletions mssql/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ def get_table_list(self, cursor):
"""
Returns a list of table and view names in the current database.
"""
sql = """SELECT
TABLE_NAME,
TABLE_TYPE,
CAST(ep.value AS VARCHAR) AS COMMENT
FROM INFORMATION_SCHEMA.TABLES i
LEFT JOIN sys.tables t ON t.name = i.TABLE_NAME
LEFT JOIN sys.extended_properties ep ON t.object_id = ep.major_id
AND ((ep.name = 'MS_DESCRIPTION' AND ep.minor_id = 0) OR ep.value IS NULL)
AND i.TABLE_SCHEMA = %s""" % (
get_schema_name())
if VERSION >= (4, 2) and self.connection.features.supports_comments:
sql = """SELECT
TABLE_NAME,
TABLE_TYPE,
CAST(ep.value AS VARCHAR) AS COMMENT
FROM INFORMATION_SCHEMA.TABLES i
LEFT JOIN sys.tables t ON t.name = i.TABLE_NAME
LEFT JOIN sys.extended_properties ep ON t.object_id = ep.major_id
AND ((ep.name = 'MS_DESCRIPTION' AND ep.minor_id = 0) OR ep.value IS NULL)
AND i.TABLE_SCHEMA = %s""" % (
get_schema_name())
else:
sql = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = %s' % (get_schema_name())
cursor.execute(sql)
types = {'BASE TABLE': 't', 'VIEW': 'v'}
if VERSION >= (4, 2):
if VERSION >= (4, 2) and self.connection.features.supports_comments:
return [TableInfo(row[0], types.get(row[1]), row[2])
for row in cursor.fetchall()
if row[0] not in self.ignored_tables]
Expand Down Expand Up @@ -146,7 +149,7 @@ def get_table_description(self, cursor, table_name, identity_check=True):
column.append(collation_name[0] if collation_name else '')
else:
column.append('')
if VERSION >= (4, 2):
if VERSION >= (4, 2) and self.connection.features.supports_comments:
sql = """select CAST(ep.value AS VARCHAR) AS COMMENT
FROM sys.columns c
INNER JOIN sys.tables t ON c.object_id = t.object_id
Expand Down Expand Up @@ -175,8 +178,7 @@ def get_table_description(self, cursor, table_name, identity_check=True):
start += 1
end -= 1
column[7] = default_value[start:end + 1]

if VERSION >= (4, 2):
if VERSION >= (4, 2) and self.connection.features.supports_comments:
items.append(FieldInfo(*column))
else:
items.append(BaseFieldInfo(*column))
Expand Down
2 changes: 2 additions & 0 deletions mssql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ def add_field(self, model, field):
# It might not actually have a column behind it
if definition is None:
return
if col_type_suffix := field.db_type_suffix(connection=self.connection):
definition += f" {col_type_suffix}"
# Remove column type from definition if field is generated
if (django_version >= (5,0) and field.generated):
definition = definition[definition.find('AS'):]
Expand Down
1 change: 0 additions & 1 deletion testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
'db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_extract_lookup_name_sql_injection',
'db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_lookup_name_sql_injection',
'schema.tests.SchemaTests.test_autofield_to_o2o',
'schema.tests.SchemaTests.test_add_auto_field',
'prefetch_related.tests.PrefetchRelatedTests.test_m2m_prefetching_iterator_with_chunks',
'migrations.test_operations.OperationTests.test_create_model_with_boolean_expression_in_check_constraint',
'queries.test_qs_combinators.QuerySetSetOperationTests.test_union_in_subquery_related_outerref',
Expand Down

0 comments on commit 82cb956

Please sign in to comment.