public static string RemoveComments(string sqlText) { string s = sqlText; string expression = ResManager.GetRegularExpression("SqlAnalyze_Comments"); Regex r = new Regex(expression, RegexOptions.IgnoreCase | RegexOptions.Compiled); return(r.Replace(sqlText, " ")); }
private IDictionary <string, SqlVariable> GetVariables_WithDataTypes(string sqlText) { IDictionary <string, SqlVariable> result = new Dictionary <string, SqlVariable>(); string expression = ResManager.GetRegularExpression("SqlAnalyze_VariableWithDataType"); expression = SqlAnalyzeHelper.ReplaceDataTypesWithQualifiedOnes(expression); //Regex r = new Regex(expression, RegexOptions.IgnoreCase | RegexOptions.Compiled); Match m; SqlVariable v = null; Group g = null; for (m = Regex.Match(sqlText, expression, RegexOptions.IgnoreCase); m.Success; m = m.NextMatch()) { g = m.Groups["Name"]; if (g == null) { continue; } string dName = String.Empty; if (result.ContainsKey(g.Value)) { continue; } dName = SqlAnalyzeHelper.CleanIdentifier(g.Value); v = new SqlVariable(); v.Name = dName; v.FullyQualifiedName = dName; g = m.Groups["DataType"]; result.Add(dName, v); if (g != null) { v.DataType = SqlAnalyzeHelper.CleanIdentifier(g.Value); v.FullyQualifiedName += " " + v.DataType; } } return(result); }
private IDictionary <string, SqlVariable> GetVariables_NameOnly(string sqlText) { IDictionary <string, SqlVariable> result = new Dictionary <string, SqlVariable>(); string expression = ResManager.GetRegularExpression("SqlAnalyze_VariableNameOnly"); Match m = null; SqlVariable v = null; for (m = Regex.Match(sqlText, expression, RegexOptions.IgnoreCase); m.Success; m = m.NextMatch()) { if (!result.ContainsKey(m.Value)) { v = new SqlVariable(); v.Name = m.Value; v.FullyQualifiedName = m.Value; result.Add(m.Value, v); } } return(result); }
public static string MatchTableName(string value) { string expression = ResManager.GetRegularExpression("SqlAnalyze_Words"); Regex r = new Regex(expression, RegexOptions.IgnoreCase | RegexOptions.Compiled); string result = value; Match m = null;; string prevMatch = String.Empty; for (m = r.Match(value); m.Success; m = m.NextMatch()) { prevMatch = result; result = m.Value; } if (result.Trim().ToLowerInvariant() == "as") { return(prevMatch); } else { return(result); } }
public IDictionary <string, SqlTableAlias> GetTableAliases(string sqlText, TableAliasType aliasType) { IDictionary <string, SqlTableAlias> result = new Dictionary <string, SqlTableAlias>(); string expression = String.Empty; switch (aliasType) { case TableAliasType.From: expression = ResManager.GetRegularExpression("SqlAnalyze_TableAliasFrom"); break; case TableAliasType.Join: expression = ResManager.GetRegularExpression("SqlAnalyze_TableAliasJoin"); break; default: return(result); } Match m; SqlTableAlias ta = null; Group g = null; for (m = Regex.Match(sqlText, expression, RegexOptions.IgnoreCase); m.Success; m = m.NextMatch()) { g = m.Groups["TableName"]; if (g == null) { continue; } string tName = SqlAnalyzeHelper.CleanIdentifier(g.Value); if (tName.Contains("(") || tName.Contains(")")) { continue; } tName = SqlAnalyzeHelper.MatchTableName(tName); if (result.ContainsKey(tName)) { continue; } if (ShallIgnore(m)) { continue; } ta = new SqlTableAlias(aliasType); ta.TableName = tName; result.Add(ta.TableName, ta); g = m.Groups["TableAlias"]; if (g != null) { if (SqlAnalyzeHelper.CleanIdentifier(g.Value).Trim() == "on") { ta.TableAlias = ta.TableName; } else { ta.TableAlias = SqlAnalyzeHelper.CleanIdentifier(g.Value); } } } return(result); }
private IDictionary <string, SqlTable> GetTables(string sqlText, TableType tableType) { Dictionary <string, SqlTable> result = new Dictionary <string, SqlTable>(); string expression = String.Empty; switch (tableType) { case TableType.Temp: expression = ResManager.GetRegularExpression("SqlAnalyze_TempTable"); break; case TableType.Variable: expression = ResManager.GetRegularExpression("SqlAnalyze_LocalTableVariable"); break; default: return(result); } expression = SqlAnalyzeHelper.ReplaceDataTypesWithQualifiedOnes(expression); Match m; SqlTable tbl = null; Group g = null; for (m = Regex.Match(sqlText, expression, RegexOptions.Compiled); m.Success; m = m.NextMatch()) { g = m.Groups["TableName"]; if (g == null) { continue; } string tName = SqlAnalyzeHelper.CleanIdentifier(g.Value); if (result.ContainsKey(tName)) { continue; } tbl = new SqlTable(tableType); tbl.TableName = tName; result.Add(tbl.TableName, tbl); g = m.Groups["ColNames"]; string cName = String.Empty; if (g != null) { foreach (Capture c in g.Captures) { cName = SqlAnalyzeHelper.CleanIdentifier(c.Value); tbl.ColumnNames.Add(cName); } } string dName = String.Empty; g = m.Groups["DataTypes"]; if (g != null) { foreach (Capture c in g.Captures) { dName = SqlAnalyzeHelper.CleanIdentifier(c.Value); tbl.ColumnDataTypes.Add(dName); } } for (int i = 0; i < tbl.ColumnNames.Count; i++) { string colName = tbl.ColumnNames[i]; string dataType = String.Empty; if (i < tbl.ColumnDataTypes.Count) { dataType = tbl.ColumnDataTypes[i]; } tbl.FullyQualifiedColumns.Add(colName + (String.IsNullOrEmpty(dataType) ? String.Empty : " " + dataType)); } } return(result); }