Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
 /// <summary>
 /// Looks for a * in the select list and throws an exception if there's any
 /// </summary>
 /// <param name="qs"></param>
 protected void ValidateStarInSelectList(QuerySpecification qs)
 {
     // Look for stars (*) in the select list
     foreach (var i in qs.FindDescendant <SelectList>().Nodes)
     {
         if (i is Mul)
         {
             throw CreateException(ExceptionMessages.StarColumnNotAllowed, i);
         }
     }
 }
Beispiel #3
0
        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);
            }
        }
        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));
            }
        }
Beispiel #5
0
        private void AppendPartitioningConditions(QuerySpecification qs, SimpleTableSource ts)
        {
            if (!double.IsInfinity(PartitioningKeyFrom) || !double.IsInfinity(PartitioningKeyTo))
            {
                var cg = new SqlServerCodeGenerator();

                string format;
                if (double.IsInfinity(PartitioningKeyFrom) && double.IsInfinity(PartitioningKeyTo))
                {
                    format = "{1} <= {0} AND {0} < {2}";
                }
                else if (double.IsInfinity(PartitioningKeyFrom))
                {
                    format = "{0} < {2}";
                }
                else
                {
                    format = "{1} <= {0}";
                }

                string sql = String.Format(format,
                    cg.GetResolvedColumnName(ts.PartitioningColumnReference),
                    PartitioningKeyFrom.ToString(System.Globalization.CultureInfo.InvariantCulture),
                    PartitioningKeyTo.ToString(System.Globalization.CultureInfo.InvariantCulture));

                var parser = new Jhu.Graywulf.SqlParser.SqlParser();
                var sc = (SearchCondition)parser.Execute(new SearchCondition(), sql);

                var where = qs.FindDescendant<WhereClause>();
                if (where == null)
                {
                    where = WhereClause.Create(sc);
                    var ws = Whitespace.Create();

                    var wsn = qs.Stack.AddAfter(qs.Stack.Find(qs.FindDescendant<FromClause>()), ws);
                    qs.Stack.AddAfter(wsn, where);
                }
                else
                {
                    where.AppendCondition(sc, "AND");
                }
            }

            // --- remove partition clause
            ts.Stack.Remove(ts.FindDescendant<TablePartitionClause>());
        }
Beispiel #6
0
 /// <summary>
 /// Looks for a * in the select list and throws an exception if there's any
 /// </summary>
 /// <param name="qs"></param>
 protected void ValidateStarInSelectList(QuerySpecification qs)
 {
     // Look for stars (*) in the select list
     foreach (var i in qs.FindDescendant<SelectList>().Nodes)
     {
         if (i is Mul)
         {
             throw CreateException(ExceptionMessages.StarColumnNotAllowed, i);
         }
     }
 }
Beispiel #7
0
        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);
            }
        }