public static List <string> GetSQLParametersName(string strSql) { List <string> list = new List <string>(); List <string> result; if (strSql == null || strSql.Trim().Length < 1) { result = list; } else { SqlTokenizer sqlTokenizer = new SqlTokenizer(strSql); Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (LexToken current in sqlTokenizer.getTokens(false, false)) { if (SqlTokenizer.IsSQLParameterToken(current)) { if (current.isSpecial() || !dictionary.ContainsKey(current.getToken())) { dictionary.Add(current.getToken(), current.getToken()); list.Add(current.getToken()); } } } result = list; } return(result); }
public static string CleanSQL(string strSql) { string result; if (strSql == null || strSql.Trim().Length < 1) { result = null; } else { SqlTokenizer sqlTokenizer = new SqlTokenizer(strSql); StringBuilder stringBuilder = new StringBuilder(); foreach (LexToken current in sqlTokenizer.getTokens(false, true)) { stringBuilder.Append(current.getInitString()); } result = stringBuilder.ToString(); } return(result); }
public static List <LexTokenCollection> SplitSQLToken(string strSql, bool isContainsComments) { List <LexTokenCollection> result; if (strSql == null || strSql.Trim().Length < 1) { result = null; } else { SqlTokenizer sqlTokenizer = new SqlTokenizer(strSql); List <LexTokenCollection> list = new List <LexTokenCollection>(); LexTokenCollection lexTokenCollection = new LexTokenCollection(); foreach (LexToken current in sqlTokenizer.getTokens(isContainsComments, false)) { if ((current.isSpecial() && current.Equals(";")) || (current.isName() && current.getToken().Equals("GO", StringComparison.CurrentCultureIgnoreCase))) { if (lexTokenCollection.Count > 0) { list.Add(lexTokenCollection); } lexTokenCollection = new LexTokenCollection(); } else { lexTokenCollection.Add(current); } } if (lexTokenCollection.Count > 0) { list.Add(lexTokenCollection); } result = ((list.Count > 0) ? list : null); } return(result); }