private void AddNestedWhere(StringBuilder sb, gsWhereClause whereClause, string originWhereClauseName) { if (whereClause.Terms.Count == 0 && whereClause.SubClauses.Count == 0) { return; } WhereClauseName = "wc" + GetNextID(); string tmpWhereClauseName = WhereClauseName; sb.AppendLine() .AppendLine($"WhereClause {tmpWhereClauseName} = new WhereClause(WhereClauseRelationship.{whereClause.Relationship.ToString()});"); foreach (gsWhereTermBase whereTerm in whereClause.Terms) { if (whereTerm is gsWhereTermExistsOrNotExists) { var whereExists = whereTerm as gsWhereTermExistsOrNotExists; sb.AppendLine(whereExists.Sql) .AppendLine($"string {whereExists.SqlName} = new Reeb.SqlOM.Render.SqlServerRenderer().RenderSelect({whereExists.QueryName});") .AppendLine("//TODO: Replace [new Reeb.SqlOM.Render.SqlServerRenderer()] from above line with [slSys.GetRenderer(AppContext)]"); } else if (whereTerm is gsWhereTermIn) { var whereIn = whereTerm as gsWhereTermIn; if (!string.IsNullOrEmpty(whereIn.Sql)) { sb.AppendLine((whereTerm as gsWhereTermIn).Sql) .AppendLine($"string {whereIn.SqlName} = new Reeb.SqlOM.Render.SqlServerRenderer().RenderSelect({whereIn.QueryName});") .AppendLine("//TODO: Replace [new Reeb.SqlOM.Render.SqlServerRenderer()] from above line with [slSys.GetRenderer(AppContext)]"); } } string whereTermStr = whereTerm.ToString(); if (whereTerm.InnerSqlOm.HasValue()) { sb.AppendLine(whereTerm.InnerSqlOm); } sb.AppendLine($"{tmpWhereClauseName}.Terms.Add({whereTermStr});"); } foreach (gsWhereClause subClause in whereClause.SubClauses) { subClause.WhereClauseOrigin = tmpWhereClauseName; AddNestedWhere(sb, subClause, subClause.WhereClauseOrigin); } if (originWhereClauseName.HasValue()) { sb.AppendLine() .Append($"{originWhereClauseName}.SubClauses.Add({tmpWhereClauseName});"); } }
public gsSelectQuery() { QryName = "qry"; Columns = new List <gsSelectColumn>(); FromClause = new gsFromClause(); Joins = new List <gsJoin>(); GroupByTerms = new List <gsGroupByTerm>(); HavingPhrase = new gsWhereClause(); OrderByTerms = new List <gsOrderByTerm>(); WhereClause = new gsWhereClause(); }