/// <summary> /// Remplit les "Blocs" d'éxécutions élémentaires trouvés dans le script en fonction de l'expression /// </summary> /// <param name="text">Le texte SQL a analyser</param> /// <param name="e">L'expression à trouver</param> private void FillBlocsExpression(string text, RegexFounding e) { var ba = new BlocAnalyzer(); ba.Analyze(e, this.ScriptId, text); myblocs.AddRange(ba.Blocs); }
public void Analyze(RegexFounding e, int scriptId, string text) { blocs.Clear(); MatchCollection cll = e.Expression.Matches(text); if (cll != null && cll.Count > 0) { foreach (Match m in cll) { string db = m.Groups["database"]?.Value; string sch = m.Groups["schema"]?.Value; if (string.IsNullOrWhiteSpace(sch) && !string.IsNullOrWhiteSpace(db)) { sch = db; db = null; } string name = m.Groups["name"]?.Value; string col = string.Empty; if (SqlAction.IsForColumn(e.Action)) { col = m.Groups["col"]?.Value; } else if (e.ApplyOn == TypeObject.Index && SqlAction.IsForIndex(e.Action)) { col = m.Groups["col"]?.Value; } int?clientCode = null; if (int.TryParse(m.Groups["codeClient"].Value, out int cc)) { clientCode = cc; } var res = new Bloc() { ScriptId = scriptId, SqlActionId = e.Action, TypeObjectId = e.ApplyOn, BlocIndex = m.Index, BlocLength = m.Length, BlocDatabase = RegexFounding.Filtre(db), BlocSchema = RegexFounding.Filtre(sch), BlocName = RegexFounding.Filtre(name), BlocColumn = RegexFounding.Filtre(col), ClientCodeId = clientCode }; if (SqlAction.IsForColumn(e.Action)) { res.BlocColumn = m.Groups["col"]?.Value; } blocs.Add(res); } } }