From a51d8c4c79841735be34c5a9b5ba7cc770ef3a61 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 13 Jun 2012 15:27:42 +0000 Subject: [PATCH] replacing identifier safe char " with [] enclosing for MsSQL --- lib/core/common.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 575b94f5e..b29477330 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2733,11 +2733,13 @@ def safeSQLIdentificatorNaming(name, isTable=False): parts = name.split('.') for i in xrange(len(parts)): - if not re.match(r"\A[A-Za-z0-9_]+\Z", parts[i]): + 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 if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ACCESS): parts[i] = "`%s`" % parts[i].strip("`") - elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.DB2): + elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL, DBMS.DB2): parts[i] = "\"%s\"" % parts[i].strip("\"") + elif Backend.getIdentifiedDbms() in (DBMS.MSSQL,): + parts[i] = "[%s]" % parts[i].strip("[]") retVal = ".".join(parts) @@ -2753,8 +2755,11 @@ def unsafeSQLIdentificatorNaming(name): if isinstance(name, basestring): if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ACCESS): retVal = name.replace("`", "") - elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.DB2): + elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL, DBMS.DB2): retVal = name.replace("\"", "") + elif Backend.getIdentifiedDbms() in (DBMS.MSSQL,): + retVal = name.replace("[", "").replace("]", "") + if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): prefix = "%s." % DEFAULT_MSSQL_SCHEMA if retVal.startswith(prefix):