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, 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); }