@@ -2733,11 +2733,13 @@ def safeSQLIdentificatorNaming(name, isTable=False):
27332733 parts = name .split ('.' )
27342734
27352735 for i in xrange (len (parts )):
2736- if not re .match (r"\A[A-Za-z0-9_]+\Z" , parts [i ]):
2736+ if not re .match (r"\A[A-Za-z0-9_@\$ ]+\Z" , parts [i ]): # reference: http://stackoverflow.com/questions/954884/what-special-characters-are-allowed-in-t-sql-column-name
27372737 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .ACCESS ):
27382738 parts [i ] = "`%s`" % parts [i ].strip ("`" )
2739- elif Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS . ORACLE , DBMS .PGSQL , DBMS .DB2 ):
2739+ elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .PGSQL , DBMS .DB2 ):
27402740 parts [i ] = "\" %s\" " % parts [i ].strip ("\" " )
2741+ elif Backend .getIdentifiedDbms () in (DBMS .MSSQL ,):
2742+ parts [i ] = "[%s]" % parts [i ].strip ("[]" )
27412743
27422744 retVal = "." .join (parts )
27432745
@@ -2753,8 +2755,11 @@ def unsafeSQLIdentificatorNaming(name):
27532755 if isinstance (name , basestring ):
27542756 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .ACCESS ):
27552757 retVal = name .replace ("`" , "" )
2756- elif Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS . ORACLE , DBMS .PGSQL , DBMS .DB2 ):
2758+ elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .PGSQL , DBMS .DB2 ):
27572759 retVal = name .replace ("\" " , "" )
2760+ elif Backend .getIdentifiedDbms () in (DBMS .MSSQL ,):
2761+ retVal = name .replace ("[" , "" ).replace ("]" , "" )
2762+
27582763 if Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS .SYBASE ):
27592764 prefix = "%s." % DEFAULT_MSSQL_SCHEMA
27602765 if retVal .startswith (prefix ):
0 commit comments