Skip to content

Commit ee97346

Browse files
authored
Format update (microsoft#139)
1 parent c25bed2 commit ee97346

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

mssql/introspection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
SQL_AUTOFIELD = -777555
1414
SQL_BIGAUTOFIELD = -777444
1515

16+
1617
def get_schema_name():
1718
return getattr(settings, 'SCHEMA_TO_INSPECT', 'SCHEMA_NAME()')
1819

20+
1921
class DatabaseIntrospection(BaseDatabaseIntrospection):
2022
# Map type codes to Django Field types.
2123
data_types_reverse = {
@@ -66,7 +68,8 @@ def get_table_list(self, cursor):
6668
"""
6769
Returns a list of table and view names in the current database.
6870
"""
69-
sql = f'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = {get_schema_name()}'
71+
sql = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = %s' % (
72+
get_schema_name())
7073
cursor.execute(sql)
7174
types = {'BASE TABLE': 't', 'VIEW': 'v'}
7275
return [TableInfo(row[0], types.get(row[1]))
@@ -114,7 +117,7 @@ def get_table_description(self, cursor, table_name, identity_check=True):
114117
""" % (table_name, column[0])
115118
cursor.execute(sql)
116119
collation_name = cursor.fetchone()
117-
column.append(collation_name[0] if collation_name else '')
120+
column.append(collation_name[0] if collation_name else '')
118121
else:
119122
column.append('')
120123

mssql/schema.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
392392
result = cursor.fetchall()
393393
columns_to_recreate_index = ', '.join(['%s' % self.quote_name(column[0]) for column in result])
394394
filter_definition = result[0][1]
395-
sql_restore_index += f'CREATE UNIQUE INDEX {index_name} ON {model._meta.db_table} ({columns_to_recreate_index}) WHERE {filter_definition};'
395+
sql_restore_index += 'CREATE UNIQUE INDEX %s ON %s (%s) WHERE %s;' % (
396+
index_name, model._meta.db_table, columns_to_recreate_index, filter_definition)
396397
self.execute(self._db_table_delete_constraint_sql(
397398
self.sql_delete_index, model._meta.db_table, index_name))
398399
self.execute(self._rename_field_sql(model._meta.db_table, old_field, new_field, new_type))
@@ -453,7 +454,7 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
453454
(old_field.db_index or not new_field.db_index) and
454455
new_field.db_index or
455456
((indexes_dropped and sorted(indexes_dropped) == sorted([index.name for index in model._meta.indexes])) or
456-
(indexes_dropped and sorted(indexes_dropped) == sorted(auto_index_names)))
457+
(indexes_dropped and sorted(indexes_dropped) == sorted(auto_index_names)))
457458
):
458459
create_index_sql_statement = self._create_index_sql(model, [new_field])
459460
if create_index_sql_statement.__str__() not in [sql.__str__() for sql in self.deferred_sql]:
@@ -580,8 +581,8 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
580581
for columns in index_columns:
581582
create_index_sql_statement = self._create_index_sql(model, columns)
582583
if (create_index_sql_statement.__str__()
583-
not in [sql.__str__() for sql in self.deferred_sql] + [statement[0].__str__() for statement in post_actions]
584-
):
584+
not in [sql.__str__() for sql in self.deferred_sql] + [statement[0].__str__() for statement in post_actions]
585+
):
585586
self.execute(create_index_sql_statement)
586587

587588
# Type alteration on primary key? Then we need to alter the column

0 commit comments

Comments
 (0)