Skip to content

Commit cbccf92

Browse files
committed
fixed quote_name for tests
1 parent d57d6cc commit cbccf92

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

mssql/operations.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,35 +378,27 @@ def quote_name(self, name):
378378
Returns a quoted version of the given table, index or column name. Does
379379
not quote the given name if it's already been quoted.
380380
381-
Handles special cases:
381+
Supports:
382382
- Schema.table format: quotes both schema and table separately
383-
- Names with spaces or special characters: ensures proper quoting
384-
- Already quoted names: leaves them unchanged
383+
- Names with spaces: handles proper quoting
385384
"""
386385
if not name:
387386
return name
388-
389-
# If already fully quoted, return as-is
387+
388+
# Already quoted
390389
if name.startswith('[') and name.endswith(']'):
391390
return name # Quoting once is enough.
392391

393-
# Handle schema.table format (e.g., "inspectdb_schema.table name")
394-
if '.' in name and not (name.startswith('[') and name.endswith(']')):
395-
parts = name.split('.', 1) # Split on first dot only
396-
schema_part = parts[0]
397-
table_part = parts[1]
392+
# Handle schema.table format (e.g., "inspectdb_special.table name")
393+
if '.' in name and not name.startswith('['):
394+
parts = name.split('.', 1) # Split only on first dot
395+
schema = parts[0].strip()
396+
table = parts[1].strip()
398397

399-
# Quote schema part if needed
400-
if not (schema_part.startswith('[') and schema_part.endswith(']')):
401-
schema_part = '[%s]' % schema_part
402-
403-
# Quote table part if needed
404-
if not (table_part.startswith('[') and table_part.endswith(']')):
405-
table_part = '[%s]' % table_part
406-
407-
return '%s.%s' % (schema_part, table_part)
398+
# Always quote both parts for SQL Server safety
399+
return '[%s].[%s]' % (schema, table)
408400

409-
# For simple names, just add brackets
401+
# Always quote single names for SQL Server safety
410402
return '[%s]' % name
411403

412404
def random_function_sql(self):

0 commit comments

Comments
 (0)