Ejemplo n.º 1
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>());
        }
 public IAnd And(string name, object value, string comparation = "=")
 {
     Clauses.Add(WhereClause.Create(new { Name = name, Value = value, Comparation = comparation, TypeLogical = "AND" }));
     return(this);
 }
 public IOr OrWhereIn(string name, params object[] values)
 {
     Clauses.Add(WhereClause.Create(new { Name = name, Values = values, Comparation = "IN", TypeLogical = "AND" }));
     return(this);
 }
 public IOr OrWhereBetween <TTo, TFrom>(string name, TTo initial, TFrom end)
 {
     Clauses.Add(WhereClause.Create(new { Name = name, Initial = initial, End = end, Comparation = "BETWEEN", TypeLogical = "OR" }));
     return(this);
 }
 public IAnd WhereNull(string name)
 {
     Clauses.Add(WhereClause.Create(new { Name = name, Comparation = "ISNULL", TypeLogical = "AND" }));
     return(this);
 }