@@ -2711,23 +2711,22 @@ def safeSQLIdentificatorNaming(name, isTable=False):
27112711 retVal = name
27122712
27132713 if isinstance (name , basestring ):
2714- name = getUnicode (name )
2715-
2716- if isTable and Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS .SYBASE ) and '.' not in name :
2717- name = "%s.%s" % (DEFAULT_MSSQL_SCHEMA , name )
2718-
2719- parts = name .split ('.' )
2720-
2721- for i in xrange (len (parts )):
2722- 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
2723- if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .ACCESS ):
2724- parts [i ] = "`%s`" % parts [i ].strip ("`" )
2725- elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .PGSQL , DBMS .DB2 ):
2726- parts [i ] = "\" %s\" " % parts [i ].strip ("\" " )
2727- elif Backend .getIdentifiedDbms () in (DBMS .MSSQL ,):
2728- parts [i ] = "[%s]" % parts [i ].strip ("[]" )
2729-
2730- retVal = "." .join (parts )
2714+ retVal = getUnicode (name )
2715+ _ = isTable and Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS .SYBASE )
2716+
2717+ if _ :
2718+ retVal = re .sub (r"(?i)\A%s\." % DEFAULT_MSSQL_SCHEMA , "" , retVal )
2719+
2720+ if not re .match (r"\A[A-Za-z0-9_@\$]+\Z" , retVal ): # Reference: http://stackoverflow.com/questions/954884/what-special-characters-are-allowed-in-t-sql-column-retVal
2721+ if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .ACCESS ):
2722+ retVal = "`%s`" % retVal .strip ("`" )
2723+ elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .PGSQL , DBMS .DB2 ):
2724+ retVal = "\" %s\" " % retVal .strip ("\" " )
2725+ elif Backend .getIdentifiedDbms () in (DBMS .MSSQL ,):
2726+ retVal = "[%s]" % retVal .strip ("[]" )
2727+
2728+ if _ and DEFAULT_MSSQL_SCHEMA not in retVal :
2729+ retVal = "%s.%s" % (DEFAULT_MSSQL_SCHEMA , retVal )
27312730
27322731 return retVal
27332732
0 commit comments