Пример #1
0
 public override void EnterSearch_condition_and([NotNull] TSqlParser.Search_condition_andContext context)
 {
     base.EnterSearch_condition_and(context);
     Debug.WriteLine("EnterSearch_condition_and");
     Debug.WriteLine(context.GetText());
     //var andClause = context.AND().ToList();
     //Debug.WriteLine("EnterSearch_condition_and TEXT");
     //andClause.ForEach(c => Debug.WriteLine($"{c.GetText()}"));
     //Debug.WriteLine("EnterSearch_condition_and TEXT");
 }
Пример #2
0
 //TODO: agregacni funkce resit asi jenom COUNT,MIN, MAX... sum a avg nema smysl nemohl bych maskovat nic,
 //zjistim data zjistim hodnoty pro ktere plati podminka v havingu a ty nebudu maskovat
 public override void EnterSearch_condition_and([NotNull] TSqlParser.Search_condition_andContext context)
 {
     try
     {
         foreach (var nChild in context.children)
         {
             Condition lCondition = ParseCondition.Parse(nChild.GetText().ToLower());
             if (lCondition.ColumnName == null || lCondition.Value == null || lCondition.Operator == null)
             {
                 continue;
             }
             int    lColumnCount = 0;
             string lTableName   = "";
             if (AliasDic.Count == 0)
             {
                 foreach (var nTable in Database.Tables)
                 {
                     if (mMentionedTables.FirstOrDefault(aR => aR.ToLower() == nTable.Name.ToLower()) != null)
                     {
                         if (nTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lCondition.ColumnName.ToLower()) != null &&
                             !nTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lCondition.ColumnName.ToLower()).PrimaryKey)
                         {
                             if (mMentionedTables.Contains(nTable.Name))
                             {
                                 lColumnCount++;
                             }
                             lTableName = nTable.Name;
                         }
                     }
                 }
                 if (lColumnCount > 1)
                 {
                     if (OnAnalyzingError != null)
                     {
                         OnAnalyzingError(this, "Ambiguous column name. Some conditions are not involved");
                     }
                     continue;
                 }
                 if (lColumnCount == 0)
                 {
                     if (OnAnalyzingError != null)
                     {
                         OnAnalyzingError(this, "Column not found. Some conditions are not involved");
                     }
                     continue;
                 }
                 if (lColumnCount == 1)
                 {
                     ParsedQueryStructure.Table lTable = AnalyzedWorkload.FirstOrDefault(aR => aR.Name == lTableName);
                     foreach (var nCondition in ChangeCondition(lCondition, lTableName))
                     {
                         ParsedQueryStructure.Condition lNewCondition = new Condition(nCondition.ColumnName, nCondition.Operator, nCondition.Value);
                         if (lTable.Columns.FirstOrDefault(aR => aR.Name == lCondition.ColumnName) != null)
                         {
                             if (lTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lCondition.ColumnName.ToLower()).Conditions.FirstOrDefault(aR => Condition.IsSameCondition(aR, lNewCondition)) != null)
                             {
                                 continue;
                             }
                             AnalyzedWorkload.FirstOrDefault(aR => aR.Name == lTableName).Columns.FirstOrDefault(aR => aR.Name == lCondition.ColumnName)
                             .Conditions.Add(lNewCondition);
                         }
                         else
                         {
                             AnalyzedWorkload.FirstOrDefault(aR => aR.Name == lTableName).Columns.Add(new ParsedQueryStructure.Column(lCondition.ColumnName));
                             AnalyzedWorkload.FirstOrDefault(aR => aR.Name == lTableName).Columns.FirstOrDefault(aR => aR.Name == lCondition.ColumnName)
                             .Conditions.Add(lNewCondition);
                         }
                     }
                 }
             }
             else
             {
                 foreach (var nCondition in ChangeCondition(lCondition, lTableName))
                 {
                     Tuple <string, string> lColNameParts = ParseCondition.SplitAlias(nCondition.ColumnName);
                     if (lColNameParts != null)
                     {
                         string lTableFromDic = AliasDic.Where(aR => aR.Value == lColNameParts.Item1).Select(aR => aR.Key).FirstOrDefault();
                         var    lDBTable      = Database.Tables.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower());
                         if (lDBTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lColNameParts.Item2.ToLower()) != null &&
                             !lDBTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lColNameParts.Item2.ToLower()).PrimaryKey)
                         {
                             ParsedQueryStructure.Table     lTable        = AnalyzedWorkload.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower());
                             ParsedQueryStructure.Condition lNewCondition = new Condition(lColNameParts.Item2, nCondition.Operator, nCondition.Value);
                             if (lTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lColNameParts.Item2.ToLower()) != null)
                             {
                                 if (lTable.Columns.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower()).Conditions.FirstOrDefault(aR => Condition.IsSameCondition(aR, lNewCondition)) != null)
                                 {
                                     continue;
                                 }
                                 AnalyzedWorkload.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower()).Columns.FirstOrDefault(aR => aR.Name.ToLower() == lCondition.ColumnName.ToLower())
                                 .Conditions.Add(lNewCondition);
                             }
                             else
                             {
                                 AnalyzedWorkload.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower()).Columns.Add(new ParsedQueryStructure.Column(lColNameParts.Item2));
                                 AnalyzedWorkload.FirstOrDefault(aR => aR.Name.ToLower() == lTableFromDic.ToLower()).Columns.FirstOrDefault(aR => aR.Name.ToLower() == lColNameParts.Item2.ToLower())
                                 .Conditions.Add(lNewCondition);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch { }
 }
Пример #3
0
 public override void ExitSearch_condition_and([NotNull] TSqlParser.Search_condition_andContext context)
 {
     base.ExitSearch_condition_and(context);
     Debug.WriteLine("ExitSearch_condition_and");
     Debug.WriteLine(context.GetText());
 }