public override void Visit(QuerySpecification node) { WhereClause lol = node.WhereClause; HavingClause xD = node.HavingClause; if (lol != null) { if (!GetNodeTokenText(lol).ToLower().Contains("select")) { seperate(GetNodeTokenText(lol).ToLower().Replace("where", "")); } else { seperate(GetNodeTokenText(lol).ToLower().Substring(6, GetNodeTokenText(lol).Length - 6)); } } if (xD != null) { string havingClause = GetNodeTokenText(xD).ToLower().Substring(6, GetNodeTokenText(xD).Length - 6); havingClause = havingClause.Replace("\r\n", ""); Regex rgx = new Regex(@"\s+"); havingClause = rgx.Replace(havingClause, " "); selection += "|" + havingClause; filtreHaving = havingClause; } /* MY BIG PART OF CODE ! mouahaha*/ id_requete_courante = Int32.Parse(this.id); node.ToString(); //bool starExpression = false; if (this.id_requete_courante != this.id_requete_precedante) { projectionList = new List <String>(); Regex rxUser = new Regex(@"\[[^\[\]\(\)]*\]\.\[[^\[\]\(\)]*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches.// //Console.WriteLine(this.PhysicalTableList["[1002].[Tokyo_0_merged.csv]"]); MatchCollection matchesUser = rxUser.Matches(this.requete); if (matchesUser.Count > 0) { String matchTexte = matchesUser[0].Groups[0].Value; this.user_courant = matchTexte.Split('.')[0].Replace("[", "").Replace("]", ""); } //Jesus christ recursifRecuperationProjection(node); ProjectionListPerQuery.Add(this.id_requete_courante, projectionList); int nombreProjectionsCommunes = 0; int nombreProjections = projectionList.Count; if (user_precedant.Equals("") || !user_courant.Equals(user_precedant)) { nombreProjectionsCommunes = 0; if (!user_courant.Equals(user_precedant)) { this.id_explo = this.id_explo + 1; } } else { if (user_precedant.Equals(user_courant)) { nombreProjectionsCommunes = previousProjectionList.Intersect(projectionList, StringComparer.InvariantCultureIgnoreCase).ToList().Count; //Faire l'intersection } } using (StreamWriter sw = File.AppendText(path_explo)) { sw.WriteLine(this.id_requete_courante + ";" + user_courant + ";" + this.id_explo); } previousProjectionList = projectionList; user_precedant = user_courant; using (StreamWriter sw = File.AppendText(path_myfriend)) { sw.Write("\n-------\nProjection pour la requête : " + this.requete); //sw.Write("Projections pour la requête : " + text_requete_courante); // Console.WriteLine(" Sont : "); //sw.Write("\n Sont :"); foreach (String projection in projectionList) { //Console.WriteLine(projection); sw.Write("\n" + projection); } sw.Write("\n--------\n"); } } this.id_requete_precedante = this.id_requete_courante; }
public override void Visit(QuerySpecification node) { WhereClause lol = node.WhereClause; HavingClause xD = node.HavingClause; if (lol != null) { if (!GetNodeTokenText(lol).ToLower().Contains("select")) { seperate(GetNodeTokenText(lol).ToLower().Replace("where", "")); } else { seperate(GetNodeTokenText(lol).ToLower().Substring(6, GetNodeTokenText(lol).Length - 6)); } } if (xD != null) { string havingClause = GetNodeTokenText(xD).ToLower().Substring(6, GetNodeTokenText(xD).Length - 6); havingClause = havingClause.Replace("\r\n", ""); Regex rgx = new Regex(@"\s+"); havingClause = rgx.Replace(havingClause, " "); selection += "|" + havingClause; filtreHaving = havingClause; } /* MY BIG PART OF CODE ! mouahaha*/ id_requete_courante = Int32.Parse(this.id); node.ToString(); bool starExpression = false; if (this.id_requete_courante != this.id_requete_precedante) { projectionList = new List <String>(); Regex rxUser = new Regex(@"\[[^\[\]\(\)]*\]\.\[[^\[\]\(\)]*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches.// //Console.WriteLine(this.PhysicalTableList["[1002].[Tokyo_0_merged.csv]"]); MatchCollection matchesUser = rxUser.Matches(this.requete); if (matchesUser.Count > 0) { String matchTexte = matchesUser[0].Groups[0].Value; this.user_courant = matchTexte.Split('.')[0].Replace("[", "").Replace("]", ""); } if (node.SelectElements != null) { foreach (TSqlFragment selectElement in node.SelectElements) { if (selectElement is SelectStarExpression) { starExpression = true; if (node.SelectElements.Count > 1) { //Lever une exception qui dit que c'est non géré* break; } else { if (node.FromClause != null) { foreach (TSqlFragment fromElement in node.FromClause.TableReferences) { if (fromElement is NamedTableReference) { String namedTableReferenceText = GetNodeTokenText(fromElement); if (this.dictTableWith.ContainsKey(this.id_requete_courante)) { foreach (CommonTableExpression commonTableExpression in this.dictTableWith[this.id_requete_courante]) { if (commonTableExpression.ExpressionName.Value == namedTableReferenceText) { if (commonTableExpression.QueryExpression is QuerySpecification) { QuerySpecification queryUsedForTableDefinition = (QuerySpecification)commonTableExpression.QueryExpression; foreach (SelectElement selectElementInQueryUsedForTableDefinition in queryUsedForTableDefinition.SelectElements) { projectionList.Add(GetNodeTokenText(selectElementInQueryUsedForTableDefinition)); } } } } } else { Regex rx = new Regex(@"\[.*\]\.\[.*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches. //Console.WriteLine(this.PhysicalTableList["[1002].[Tokyo_0_merged.csv]"]); String matchText = ""; MatchCollection matches = rx.Matches(namedTableReferenceText); if (matches.Count > 0) { matchText = matches[0].Groups[0].Value; } if (this.PhysicalTableList.ContainsKey(matchText.ToLower())) { foreach (String attribut in this.PhysicalTableList[matchText.ToLower()]) { projectionList.Add(attribut); } } } } } } } } } if (starExpression == false) { foreach (SelectElement selectElement in node.SelectElements) { if (GetNodeTokenText(selectElement).Contains(',')) { // Console.WriteLine(GetNodeTokenText(selectElement)); } projectionList.Add(GetNodeTokenText(selectElement)); } } } ProjectionListPerQuery.Add(this.id_requete_courante, projectionList); int nombreProjectionsCommunes = 0; int nombreProjections = projectionList.Count; if (user_precedant.Equals("") || !user_courant.Equals(user_precedant)) { nombreProjectionsCommunes = 0; if (!user_courant.Equals(user_precedant)) { this.id_explo = this.id_explo + 1; } } else { if (user_precedant.Equals(user_courant)) { nombreProjectionsCommunes = previousProjectionList.Intersect(projectionList, StringComparer.InvariantCultureIgnoreCase).ToList().Count; //Faire l'intersection } } using (StreamWriter sw = File.AppendText(path_explo)) { sw.WriteLine(this.id_requete_courante + ";" + user_courant + ";" + this.id_explo); } previousProjectionList = projectionList; user_precedant = user_courant; using (StreamWriter sw = File.AppendText(path_myfriend)) { sw.Write("\n-------\nProjection pour la requête : " + this.requete); //sw.Write("Projections pour la requête : " + text_requete_courante); // Console.WriteLine(" Sont : "); //sw.Write("\n Sont :"); foreach (String projection in projectionList) { //Console.WriteLine(projection); sw.Write("\n" + projection); } sw.Write("\n--------\n"); } } this.id_requete_precedante = this.id_requete_courante; }