public void NormalizeQuerySpecification(QuerySpecification qs) { foreach (var sq in qs.EnumerateSubqueries()) { NormalizeSelectStatement(sq.SelectStatement); } // Process join conditions conditions = new List <LogicalExpressions.Expression>(); var from = qs.FindDescendant <FromClause>(); if (from != null) { var tablesource = from.FindDescendant <TableSourceExpression>(); foreach (JoinedTable jt in tablesource.EnumerateDescendantsRecursive <JoinedTable>(typeof(Subquery))) { // CROSS JOIN queries have no search condition SearchCondition sc = jt.FindDescendant <SearchCondition>(); if (sc != null) { conditions.Add(GetConjunctiveNormalForm(sc)); } } } // Process where clause WhereClause where = qs.FindDescendant <WhereClause>(); if (where != null) { var sc = where.FindDescendant <SearchCondition>(); conditions.Add(GetConjunctiveNormalForm(sc)); } }
protected void ValidateQuerySpecification(QuerySpecification qs) { // Call recursively for subqueries #if false foreach (var sq in qs.EnumerateSubqueries()) { ValidateQuerySpecification(sq); } #endif ValidateTableReferences(qs); ValidateStarInSelectList(qs); // Loop through all column expressions of the select list and try to resolve them foreach (ColumnExpression ce in qs.FindDescendant <SelectList>().EnumerateDescendants <ColumnExpression>()) { ValidateColumnExpression(qs, ce); } }
/// <summary> /// Internal routine to perform the name resolution steps on a single /// query specification /// </summary> /// <param name="qs"></param> protected void ResolveQuerySpecification(QuerySpecification qs, int depth) { // At this point the table and column references are all parsed // from the query but no name resolution and cross-identification // of these references have happened yet. After the cross-idenfication // routine, the same tables and columns will be tagged by the // same TableReference and ColumnReference instances. // First of all, call everything recursively for subqueries. Subqueries // can appear within the table sources and in the where clause semi-join // expressions foreach (var sq in qs.EnumerateSubqueries()) { ResolveSelectStatement(sq.SelectStatement, depth + 1); } // Substitute default dataset names and schema names // This is typically the MYDB and dbo SubstituteTableAndColumnDefaults(qs); // Column references will be stored under the query specification CollectSourceTableReferences(qs); // Column identifiers can contain table names, aliases or nothing, // resolve them now ResolveTableReferences(qs); // Substitute SELECT * expressions SubstituteStars(qs); // Resolve column references of each occurance ResolveColumnReferences(qs); // Copy resultset columns to the appropriate collection CopyResultsColumns(qs); // Add default aliases to column expressions in the form of tablealias_columnname if (depth == 0) { AssignDefaultColumnAliases(qs); } }
public void NormalizeQuerySpecification(QuerySpecification qs) { foreach (var sq in qs.EnumerateSubqueries()) { NormalizeSelectStatement(sq.SelectStatement); } // Process join conditions conditions = new List<LogicalExpressions.Expression>(); var from = qs.FindDescendant<FromClause>(); if (from != null) { var tablesource = from.FindDescendant<TableSourceExpression>(); foreach (JoinedTable jt in tablesource.EnumerateDescendantsRecursive<JoinedTable>(typeof(Subquery))) { // CROSS JOIN queries have no search condition SearchCondition sc = jt.FindDescendant<SearchCondition>(); if (sc != null) { conditions.Add(GetConjunctiveNormalForm(sc)); } } } // Process where clause WhereClause where = qs.FindDescendant<WhereClause>(); if (where != null) { var sc = where.FindDescendant<SearchCondition>(); conditions.Add(GetConjunctiveNormalForm(sc)); } }
/// <summary> /// Internal routine to perform the name resolution steps on a single /// query specification /// </summary> /// <param name="qs"></param> protected void ResolveQuerySpecification(QuerySpecification qs, int depth) { // At this point the table and column references are all parsed // from the query but no name resolution and cross-identification // of these references have happened yet. After the cross-idenfication // routine, the same tables and columns will be tagged by the // same TableReference and ColumnReference instances. // First of all, call everything recursively for subqueries. Subqueries // can appear within the table sources and in the where clause semi-join // expressions foreach (var sq in qs.EnumerateSubqueries()) { ResolveSelectStatement(sq.SelectStatement, depth + 1); } // Substitute default dataset names and schema names // This is typically the MYDB and dbo SubstituteDefaults(qs); // Column references will be stored under the query specification CollectSourceTableReferences(qs); // Column identifiers can contain table names, aliases or nothing, // resolve them now ResolveTableReferences(qs); // Substitute SELECT * expressions SubstituteStars(qs); // Resolve column references of each occurance ResolveColumnReferences(qs); // Copy resultset columns to the appropriate collection CopyResultsColumns(qs); // Add default aliases to column expressions in the form of tablealias_columnname if (depth == 0) { AssignDefaultColumnAliases(qs); } }
protected void ValidateQuerySpecification(QuerySpecification qs) { // Call recursively for subqueries #if false foreach (var sq in qs.EnumerateSubqueries()) { ValidateQuerySpecification(sq); } #endif ValidateTableReferences(qs); ValidateStarInSelectList(qs); // Loop through all column expressions of the select list and try to resolve them foreach (ColumnExpression ce in qs.FindDescendant<SelectList>().EnumerateDescendants<ColumnExpression>()) { ValidateColumnExpression(qs, ce); } }