Esempio n. 1
0
        public void Test_Calendar_Month(DatabaseType type)
        {
            var tbl = GetTestTable(type);
            var svr = tbl.Database.Server;

            var syntax = tbl.GetQuerySyntaxHelper();

            var lines = new List <CustomLine>();

            lines.Add(new CustomLine("SELECT", QueryComponent.SELECT));
            lines.Add(new CustomLine("count(*) as MyCount,", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.CountFunction
            });
            lines.Add(new CustomLine(syntax.EnsureWrapped("EventDate"), QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                               //tell it which the axis are
            lines.Add(new CustomLine("FROM ", QueryComponent.FROM));
            lines.Add(new CustomLine(tbl.GetFullyQualifiedName(), QueryComponent.FROM));
            lines.Add(new CustomLine("GROUP BY", QueryComponent.GroupBy));
            lines.Add(new CustomLine(syntax.EnsureWrapped("EventDate"), QueryComponent.GroupBy)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                                            //tell it which the axis are

            var axis = new QueryAxis()
            {
                StartDate     = "'2001-01-01'",
                EndDate       = "'2010-01-01'",
                AxisIncrement = AxisIncrement.Month
            };


            var sql = svr.GetQuerySyntaxHelper().AggregateHelper.BuildAggregate(lines, axis);

            using (var con = svr.GetConnection())
            {
                con.Open();

                using (var da = svr.GetDataAdapter(sql, con))
                {
                    using (DataTable dt = new DataTable())
                    {
                        da.Fill(dt);

                        ConsoleWriteTable(dt);

                        Assert.AreEqual(109, dt.Rows.Count); // 109 months between 2001 and 2010 (inclusive)

                        AssertHasRow(dt, "2001-01", 5);
                        AssertHasRow(dt, "2001-02", null);
                    }
                }
            }
        }
Esempio n. 2
0
 private Cardinality AnalyzeAccessGraph(QueryAxis axis, Accessor accessor, TypeNode type, Hashtable visited){
   if (accessor != null){
     if (visited[accessor] != null){
       axis.IsCyclic = true;
       return this.typeSystem.GetCardinality(type, this.TypeViewer);
     }
     visited[accessor] = true;
     SwitchAccessor swa = accessor as SwitchAccessor;
     if (swa != null && swa.Accessors != null && swa.Accessors.Count > 0){
       ArrayList accessors = new ArrayList(swa.Accessors.Values);
       Cardinality c = this.AnalyzeAccessGraph(axis, (Accessor)accessors[0], swa.Type.Types[0], visited);
       for (int i = 1, n = accessors.Count; i < n; i++){
         c = this.typeSystem.GetCardinalityOr(c, this.AnalyzeAccessGraph(axis, (Accessor)accessors[i], swa.Type.Types[i], visited));
       }
       if (swa.Accessors.Count < swa.Type.Types.Count){
         c = this.typeSystem.GetCardinalityOr(c, Cardinality.ZeroOrOne);
       }
       return c;
     }
     SequenceAccessor sqa = accessor as SequenceAccessor;
     if (sqa != null && sqa.Accessors != null && sqa.Accessors.Count > 0){
       Cardinality c = this.AnalyzeAccessGraph(axis, (Accessor)sqa.Accessors[0], type, visited);
       for (int i = 1, n = sqa.Accessors.Count; i < n; i++){
         c = this.typeSystem.GetCardinalityAnd(c, this.AnalyzeAccessGraph(axis, (Accessor)sqa.Accessors[i], type, visited));
       }
       return c;
     }
     MemberAccessor ma = accessor as MemberAccessor;
     if (ma != null){
       if (ma.Yield){
         axis.YieldCount++;
         axis.YieldTypes.Add(ma.Type);
       }
       TypeNode mt = this.typeSystem.GetMemberType(ma.Member);
       Cardinality c = this.typeSystem.GetCardinality(mt, this.TypeViewer);
       if (c == Cardinality.OneOrMore || c == Cardinality.ZeroOrMore){
         axis.IsIterative = true; // member refers to a collection
       }
       if (ma.Next != null){
         c = this.typeSystem.GetCardinalityOr(c, this.AnalyzeAccessGraph(axis, ma.Next, ma.Type, visited));
       }
       return c;
     }
   }
   return Cardinality.None;
 }
Esempio n. 3
0
 public virtual bool Matches(MemberAccessor ma, QueryAxis axis){
   bool hasNameTest = !((axis.Name == null || axis.Name == Identifier.Empty) && (axis.Namespace == null || axis.Namespace == Identifier.Empty));
   bool hasTypeTest = axis.TypeTest != null;
   if (hasNameTest && !XmlHelper.Matches(ma.Member, axis.Name, axis.Namespace)) return false;
   if (hasTypeTest && !this.HasTypeMatch(ma.Type, axis.TypeTest)) return false;
   if (!hasNameTest && !hasTypeTest && this.IsTransparent(ma.Member)) return false;
   return true;
 }
Esempio n. 4
0
 public virtual Expression ResolveAxis(QueryAxis axis){
   if (axis == null) return null;
   if (axis.Source == null) return axis;
   TypeNode stype = axis.Source.Type;
   bool isStatic = false;
   if (axis.Source is Literal && stype == SystemTypes.Type){
     stype = (TypeNode)((Literal)axis.Source).Value;
     isStatic = true;
   }
   if (stype == null) return axis;
   TypeNode elementType = (stype is TupleType) ? stype : this.typeSystem.GetStreamElementType(stype, this.TypeViewer);
   if (elementType == null) return null;
   Accessor acc = this.BuildAccessGraph(elementType, axis.IsDescendant, isStatic);
   axis.AccessPlan = this.ReduceAccessGraph(axis, acc);
   axis.YieldCount = 0;
   axis.YieldTypes = new TypeNodeList();
   axis.Cardinality = Cardinality.One;
   if (axis.AccessPlan != null){
     axis.Cardinality = this.AnalyzeAccessGraph(axis, axis.AccessPlan, elementType, new Hashtable());
     if (axis.TypeTest != null){
       axis.Type = this.GetResultType(axis.Source, axis.TypeTest, axis.Cardinality);
     }
     else{
       axis.YieldTypes = TypeUnion.Normalize(axis.YieldTypes);
       if (axis.YieldTypes.Count > 1){
         TypeNode resultElementType = TypeUnion.For(axis.YieldTypes, this.currentType);
         axis.Type = this.GetResultType(axis.Source, resultElementType, axis.Cardinality);
       }
       else if (axis.YieldCount > 0){
         axis.Type = this.GetResultType(axis.Source, axis.YieldTypes[0], axis.Cardinality);
       }
     }
     if (axis.YieldCount == 1 && !axis.IsIterative){
       Cardinality scard = this.typeSystem.GetCardinality(axis.Source, this.TypeViewer);
       Cardinality acard = this.typeSystem.GetCardinality(axis, this.TypeViewer);
       if ((scard == Cardinality.One || scard == Cardinality.None) &&
         (acard == Cardinality.One || acard == Cardinality.None || acard == Cardinality.ZeroOrOne)){
         Expression simple = this.GetSimpleAxis(axis.Source, axis.AccessPlan);
         if (simple != null) 
           return simple;
       }
     }
   }
   return axis;
 }
Esempio n. 5
0
 public override Node VisitQueryAxis(QueryAxis axis)
 {
     base.VisitQueryAxis(axis);
     return(this.Compose(axis, this.GetComposer(axis.Source)));
 }
    public virtual Differences VisitQueryAxis(QueryAxis axis1, QueryAxis axis2){
      Differences differences = new Differences(axis1, axis2);
      if (axis1 == null || axis2 == null){
        if (axis1 != axis2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryAxis changes = (QueryAxis)axis2.Clone();
      QueryAxis deletions = (QueryAxis)axis2.Clone();
      QueryAxis insertions = (QueryAxis)axis2.Clone();

      //      axis1.AccessPlan;
      //      axis1.Cardinality;
      //      axis1.IsCyclic;
      //      axis1.IsDescendant;
      //      axis1.IsIterative;
      //      axis1.Name;
      //      axis1.Namespace;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Esempio n. 7
0
 public override Node VisitQueryAxis(QueryAxis qa) {
   if (qa == null || this.currentMethod == null || this.currentMethod.Scope == null) return null;
   Class cc = this.currentMethod.Scope.ClosureClass;
   qa.Source = this.VisitExpression(qa.Source);
   if (qa.Source == null || qa.Source.Type == null) return null;
   TypeNode elementType = null;
   if (qa.Source is Literal && qa.Source.Type == SystemTypes.Type) {
     elementType = (TypeNode)((Literal)qa.Source).Value;
   } else {
     elementType = (qa.Source.Type is TupleType) ? qa.Source.Type : this.typeSystem.GetStreamElementType(qa.Source, this.TypeViewer);
   }
   if (qa.AccessPlan == null || qa.YieldCount == 0) {
     string name = string.Empty;
     if (qa.TypeTest != null) name = qa.TypeTest.FullName + "::";
     if (qa.Namespace != null && qa.Namespace != Identifier.Empty) {
       name += qa.Namespace.Name + ":";
     }
     name += (qa.Name != null && qa.Name != Identifier.Empty) ? qa.Name.Name : "*";
     this.HandleError(qa, Error.QueryNoMatch, this.GetTypeName(elementType), name);
     return null;
   }
   if (qa.Type == null) return null;
   return qa;
 }
Esempio n. 8
0
 private bool AnyPathMatches(QueryAxis axis, Accessor accessor){
   return this.AnyPathMatches( axis, accessor, new Hashtable() );
 }
Esempio n. 9
0
 public override Node VisitQueryAxis(QueryAxis axis){
   if (axis == null) return null;
   return base.VisitQueryAxis((QueryAxis)axis.Clone());
 }
        public void Test_Calendar_WithPivot(DatabaseType type)
        {
            var tbl = GetTestTable(type);
            var svr = tbl.Database.Server;

            var lines = new List <CustomLine>();

            lines.Add(new CustomLine("SELECT", QueryComponent.SELECT));
            lines.Add(new CustomLine("count(*) as MyCount,", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.CountFunction
            });
            lines.Add(new CustomLine("EventDate,", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                          //tell it which the axis are
            lines.Add(new CustomLine("Category", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.Pivot
            });                                                                                                                         //tell it which the pivot
            lines.Add(new CustomLine("FROM ", QueryComponent.FROM));
            lines.Add(new CustomLine(tbl.GetFullyQualifiedName(), QueryComponent.FROM));
            lines.Add(new CustomLine("GROUP BY", QueryComponent.GroupBy));
            lines.Add(new CustomLine("EventDate,", QueryComponent.GroupBy)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                       //tell it which the axis are
            lines.Add(new CustomLine("Category", QueryComponent.GroupBy)
            {
                Role = CustomLineRole.Pivot
            });

            var axis = new QueryAxis()
            {
                StartDate     = "'2001-01-01'",
                EndDate       = "'2010-01-01'",
                AxisIncrement = AxisIncrement.Year //by year
            };


            var sql = svr.GetQuerySyntaxHelper().AggregateHelper.BuildAggregate(lines, axis, true);

            using (var con = svr.GetConnection())
            {
                con.Open();

                var       da = svr.GetDataAdapter(sql, con);
                DataTable dt = new DataTable();
                da.Fill(dt);

                //pivot columns should ordered by sum of pivot values (T has the highest followed by E...)

                /*joinDt	T	E&, %a' mp;E	F	G
                 *  2001	3	1	            0	1
                 *  2002	2	1	            2	0
                 *  2003	2	0	            0	0
                 *  2004	0	0	            0	0
                 *  2005	0	1	            0	0
                 *  2006	0	0	            0	0
                 *  2007	0	0	            0	0
                 *  2008	0	0	            0	0
                 *  2009	0	0	            0	0
                 *  2010	0	0	            0	0
                 */

                Assert.AreEqual(10, dt.Rows.Count); //there are 10 years between 2001 and 2010 even though not all years are represented in the data

                StringAssert.AreEqualIgnoringCase("joinDt", dt.Columns[0].ColumnName);
                StringAssert.AreEqualIgnoringCase("T", dt.Columns[1].ColumnName);
                StringAssert.AreEqualIgnoringCase("E&, %a' mp;E", dt.Columns[2].ColumnName);
                StringAssert.AreEqualIgnoringCase("F", dt.Columns[3].ColumnName);
                StringAssert.AreEqualIgnoringCase("G", dt.Columns[4].ColumnName);

                Assert.AreEqual(2001, dt.Rows[0][0]);
                Assert.AreEqual(3, dt.Rows[0][1]);
                Assert.AreEqual(1, dt.Rows[0][2]);
                Assert.AreEqual(0, dt.Rows[0][3]);
                Assert.AreEqual(1, dt.Rows[0][4]);

                Assert.AreEqual(2002, dt.Rows[1][0]);
                Assert.AreEqual(2, dt.Rows[1][1]);
                Assert.AreEqual(1, dt.Rows[1][2]);
                Assert.AreEqual(2, dt.Rows[1][3]);
                Assert.AreEqual(0, dt.Rows[1][4]);

                Assert.AreEqual(2003, dt.Rows[2][0]);
                Assert.AreEqual(2, dt.Rows[2][1]);
                Assert.AreEqual(0, dt.Rows[2][2]);
                Assert.AreEqual(0, dt.Rows[2][3]);
                Assert.AreEqual(0, dt.Rows[2][4]);

                Assert.AreEqual(2004, dt.Rows[3][0]);
                Assert.AreEqual(0, dt.Rows[3][1] == DBNull.Value ? 0 : dt.Rows[3][1]);
                Assert.AreEqual(0, dt.Rows[3][2] == DBNull.Value ? 0 : dt.Rows[3][1]);  //null is permitted because this row doesn't have any matching records... peculiarity of MySql implementation but null=0 is ok for aggregates
                Assert.AreEqual(0, dt.Rows[3][3] == DBNull.Value ? 0 : dt.Rows[3][1]);
                Assert.AreEqual(0, dt.Rows[3][4] == DBNull.Value ? 0 : dt.Rows[3][1]);

                Assert.AreEqual(2005, dt.Rows[4][0]);
                Assert.AreEqual(0, dt.Rows[4][1]);
                Assert.AreEqual(1, dt.Rows[4][2]);
                Assert.AreEqual(0, dt.Rows[4][3]);
                Assert.AreEqual(0, dt.Rows[4][4]);
            }
        }
Esempio n. 11
0
 public virtual Node VisitQueryAxis(QueryAxis axis1, QueryAxis axis2){
   if (axis1 == null) return null;
   if (axis2 == null)
     axis1.Source = this.VisitExpression(axis1.Source, null);
   else
     axis1.Source = this.VisitExpression(axis1.Source, axis2.Source);
   return axis1;
 }
Esempio n. 12
0
 public override Node VisitQueryAxis(QueryAxis axis) {
   if (axis.Type == null) return null; // error handling.
   Cardinality tcard = this.typeSystem.GetCardinality(axis, this.TypeViewer);
   switch( tcard ) {
     case Cardinality.None:
     case Cardinality.One:
     case Cardinality.ZeroOrOne: {
       BlockScope scope = this.currentMethod.Body.Scope;
       Block block = new Block(new StatementList(4));
       AxisBuildState state = new AxisBuildState(axis.Type);
       state.YieldBlock = new Block();
       state.YieldTarget = this.NewClosureLocal(axis.Type, scope);
       if (tcard == Cardinality.ZeroOrOne) {
         block.Statements.Add(new AssignmentStatement(state.YieldTarget, this.typeSystem.ImplicitCoercion(Literal.Null, state.YieldType, this.TypeViewer)));
       }
       block.Statements.Add(this.BuildAxisClosure(axis.Source, state, axis.AccessPlan, scope));
       block.Statements.Add(state.YieldBlock);
       block.Statements.Add(new ExpressionStatement(state.YieldTarget));
       BlockExpression be = new BlockExpression(block, state.YieldType);
       return this.VisitBlockExpression(be);
     }
     default:
     case Cardinality.OneOrMore:
     case Cardinality.ZeroOrMore: {
       TypeNode targetType = this.typeSystem.GetStreamElementType(axis, this.TypeViewer);
       Block body = null;
       Node closure = this.StartQueryClosure(targetType, "axis", out body);
       BlockScope scope = body.Scope;
       AxisBuildState state = new AxisBuildState(targetType);
       if (axis.IsCyclic) state.TypeClosures = new Hashtable();
       Cardinality scard = this.typeSystem.GetCardinality(axis.Source, this.TypeViewer);
       switch( scard ) {
         case Cardinality.None:
         case Cardinality.One:
         case Cardinality.ZeroOrOne:
           body.Statements.Add(this.BuildAxisClosure(axis.Source, state, axis.AccessPlan, scope));
           break;
         case Cardinality.OneOrMore:
         case Cardinality.ZeroOrMore:
           Expression feTarget = null;
           Block inner = null;
           body.Statements.Add(this.BuildClosureForEach(axis.Source, ref feTarget, out inner, scope));
           inner.Statements.Add(this.BuildAxisClosure(feTarget, state, axis.AccessPlan, scope));
           break;
       }
       return this.EndQueryClosure(closure, axis.Type);
     }
   }
 }
Esempio n. 13
0
 // query nodes
 public override Node VisitQueryAxis(QueryAxis axis){
   base.VisitQueryAxis(axis);
   axis.TypeTest = this.VisitTypeReference(axis.TypeTest);
   // resolve namespace from prefix
   if (axis.Namespace == null && axis.Name != null && axis.Name.Prefix != null){
     Identifier prefix = axis.Name.Prefix;
     AliasDefinition aliasDef = this.LookupAlias(prefix);
     if (aliasDef != null){
       axis.Namespace = aliasDef.AliasedUri;
       if (axis.Namespace == null)
         axis.Namespace = (Identifier)aliasDef.AliasedExpression;
     }
   }
   return axis;
 }
Esempio n. 14
0
 public override Node VisitQueryAxis(QueryAxis axis){
   base.VisitQueryAxis(axis);
   return this.Compose(axis, this.GetComposer(axis.Source));
 }
Esempio n. 15
0
 private Accessor ReduceAccessGraph(QueryAxis axis, Accessor accessor){
   return this.ReduceAccessGraph(axis, accessor, new Hashtable());
 }
Esempio n. 16
0
        public void Test_Calendar_ToToday(DatabaseType type)
        {
            var tbl       = GetTestTable(type);
            var svr       = tbl.Database.Server;
            var eventDate = tbl.DiscoverColumn("EventDate");

            var lines = new List <CustomLine>();

            lines.Add(new CustomLine("SELECT", QueryComponent.SELECT));
            lines.Add(new CustomLine("count(*) as MyCount,", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.CountFunction
            });
            lines.Add(new CustomLine(eventDate.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                               //tell it which the axis are
            lines.Add(new CustomLine("FROM ", QueryComponent.FROM));
            lines.Add(new CustomLine(tbl.GetFullyQualifiedName(), QueryComponent.FROM));
            lines.Add(new CustomLine("GROUP BY", QueryComponent.GroupBy));
            lines.Add(new CustomLine(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                                            //tell it which the axis are

            var axis = new QueryAxis()
            {
                StartDate     = "'2001-01-01'",
                EndDate       = tbl.GetQuerySyntaxHelper().GetScalarFunctionSql(MandatoryScalarFunctions.GetTodaysDate),
                AxisIncrement = AxisIncrement.Year //by year
            };


            var sql = svr.GetQuerySyntaxHelper().AggregateHelper.BuildAggregate(lines, axis);

            Console.WriteLine(sql);

            using (var con = svr.GetConnection())
            {
                con.Open();

                using (var da = svr.GetDataAdapter(sql, con))
                {
                    using (DataTable dt = new DataTable())
                    {
                        da.Fill(dt);

                        Assert.GreaterOrEqual(dt.Rows.Count, 19); //there are 19 years between 2001 and 2019 (use greater than because we don't want test to fail in 2020)
                        Assert.AreEqual(2001, dt.Rows[0][0]);
                        Assert.AreEqual(5, dt.Rows[0][1]);
                        Assert.AreEqual(2002, dt.Rows[1][0]);
                        Assert.AreEqual(5, dt.Rows[1][1]);
                        Assert.AreEqual(2003, dt.Rows[2][0]);
                        Assert.AreEqual(2, dt.Rows[2][1]);
                        Assert.AreEqual(2004, dt.Rows[3][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[3][1]);
                        Assert.AreEqual(2005, dt.Rows[4][0]);
                        Assert.AreEqual(1, dt.Rows[4][1]);
                        Assert.AreEqual(2006, dt.Rows[5][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[5][1]);
                        Assert.AreEqual(2007, dt.Rows[6][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[6][1]);
                        Assert.AreEqual(2008, dt.Rows[7][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[7][1]);
                        Assert.AreEqual(2009, dt.Rows[8][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[8][1]);
                        Assert.AreEqual(2010, dt.Rows[9][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[9][1]);

                        //should go up to this year
                        Assert.AreEqual(DateTime.Now.Year, dt.Rows[dt.Rows.Count - 1][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[9][1]);
                    }
                }
            }
        }
Esempio n. 17
0
 private Accessor ReduceAccessGraph(QueryAxis axis, Accessor accessor, Hashtable visited){
   if (accessor == null) return null;
   if (visited[accessor] != null) return accessor;
   visited[accessor] = true;
   if (!this.AnyPathMatches(axis, accessor)) return null;
   SwitchAccessor swa = accessor as SwitchAccessor;
   if (swa != null && swa.Accessors != null && swa.Accessors.Count > 0){
     ArrayList list = new ArrayList(swa.Accessors.Keys);
     foreach( object key in list ){
       Accessor acc = (Accessor) swa.Accessors[key];
       acc = this.ReduceAccessGraph(axis, acc, visited);
       if (acc != null){
         swa.Accessors[key] = acc;
       }
       else{
         swa.Accessors.Remove(key);
       }
     }
     if (swa.Accessors.Count == 0) return null;
     return swa;
   }
   SequenceAccessor sqa = accessor as SequenceAccessor;
   if (sqa != null && sqa.Accessors != null && sqa.Accessors.Count > 0){
     for( int i = sqa.Accessors.Count - 1; i >= 0; i-- ){
       Accessor acc = (Accessor) sqa.Accessors[i];
       if (this.ReduceAccessGraph(axis, acc, visited) == null){
         sqa.Accessors.RemoveAt(i);
       }
     }
     if (sqa.Accessors.Count == 0) return null;
     if (sqa.Accessors.Count == 1) return (Accessor) sqa.Accessors[0];
     return sqa;
   }
   MemberAccessor ma = accessor as MemberAccessor;
   if (ma != null){
     ma.Yield = this.Matches(ma, axis);
     ma.Next = this.ReduceAccessGraph(axis, ma.Next, visited);
     return ma;
   }
   return null;
 }
Esempio n. 18
0
        public void Test_Calendar_SELECTColumnOrder_CountAfterAxisColumn(DatabaseType type)
        {
            var tbl       = GetTestTable(type);
            var svr       = tbl.Database.Server;
            var eventDate = tbl.DiscoverColumn("EventDate");

            var lines = new List <CustomLine>();

            lines.Add(new CustomLine("SELECT", QueryComponent.SELECT));
            lines.Add(new CustomLine(eventDate.GetFullyQualifiedName() + ",", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                                    //tell it which the axis are
            lines.Add(new CustomLine("count(*) as MyCount", QueryComponent.QueryTimeColumn)
            {
                Role = CustomLineRole.CountFunction
            });
            lines.Add(new CustomLine("FROM ", QueryComponent.FROM));
            lines.Add(new CustomLine(tbl.GetFullyQualifiedName(), QueryComponent.FROM));
            lines.Add(new CustomLine("GROUP BY", QueryComponent.GroupBy));
            lines.Add(new CustomLine(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy)
            {
                Role = CustomLineRole.Axis
            });                                                                                                                                                            //tell it which the axis are

            var axis = new QueryAxis()
            {
                StartDate     = "'2001-01-01'",
                EndDate       = "'2010-01-01'",
                AxisIncrement = AxisIncrement.Year //by year
            };


            var sql = svr.GetQuerySyntaxHelper().AggregateHelper.BuildAggregate(lines, axis);

            Console.WriteLine(sql);

            using (var con = svr.GetConnection())
            {
                con.Open();

                using (var da = svr.GetDataAdapter(sql, con))
                {
                    using (DataTable dt = new DataTable())
                    {
                        da.Fill(dt);

                        Assert.AreEqual(10, dt.Rows.Count); //there are 10 years between 2001 and 2010 even though not all years are represented in the data
                        Assert.AreEqual(2001, dt.Rows[0][0]);
                        Assert.AreEqual(5, dt.Rows[0][1]);
                        Assert.AreEqual(2002, dt.Rows[1][0]);
                        Assert.AreEqual(5, dt.Rows[1][1]);
                        Assert.AreEqual(2003, dt.Rows[2][0]);
                        Assert.AreEqual(2, dt.Rows[2][1]);
                        Assert.AreEqual(2004, dt.Rows[3][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[3][1]);
                        Assert.AreEqual(2005, dt.Rows[4][0]);
                        Assert.AreEqual(1, dt.Rows[4][1]);
                        Assert.AreEqual(2006, dt.Rows[5][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[5][1]);
                        Assert.AreEqual(2007, dt.Rows[6][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[6][1]);
                        Assert.AreEqual(2008, dt.Rows[7][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[7][1]);
                        Assert.AreEqual(2009, dt.Rows[8][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[8][1]);
                        Assert.AreEqual(2010, dt.Rows[9][0]);
                        Assert.AreEqual(DBNull.Value, dt.Rows[9][1]);
                    }
                }
            }
        }
Esempio n. 19
0
 private bool AnyPathMatches(QueryAxis axis, Accessor accessor, Hashtable visited){
   if (accessor == null || visited[accessor] != null) return false;
   visited[accessor] = true;
   SwitchAccessor swa = accessor as SwitchAccessor;
   if (swa != null){
     foreach( Accessor acc in swa.Accessors.Values ){
       if (this.AnyPathMatches(axis, acc, visited)) return true;
     }
     return false;
   }
   SequenceAccessor sqa = accessor as SequenceAccessor;
   if (sqa != null){
     foreach( Accessor acc in sqa.Accessors ){
       if (this.AnyPathMatches(axis, acc, visited)) return true;
     }
     return false;
   }
   MemberAccessor ma = accessor as MemberAccessor;
   if (ma != null){
     if (this.Matches(ma, axis)) return true;
     if (ma.Next != null) return this.AnyPathMatches(axis, ma.Next, visited);
     return false;
   }
   return false;
 }
Esempio n. 20
0
 public virtual void VisitQueryAxis(QueryAxis axis){
   if (axis == null) return;
   this.VisitExpression( axis.Source );
 }
Esempio n. 21
0
 public virtual Node VisitQueryAxis(QueryAxis axis){
   if (axis == null) return null;
   axis.Source = this.VisitExpression( axis.Source );
   return axis;
 }
Esempio n. 22
0
 public override Node VisitQueryAxis(QueryAxis axis){
   if (axis == null) return null;
   axis.Source = this.VisitExpression(axis.Source);
   return this.ResolveAxis(axis);
 }
Esempio n. 23
0
 public virtual Node VisitQueryAxis(QueryAxis axis, QueryAxis changes, QueryAxis deletions, QueryAxis insertions){
   this.UpdateSourceContext(axis, changes);
   if (axis == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return axis;
 }
 public EventingVisitor(Action<QueryAxis> visitQueryAxis) { VisitedQueryAxis += visitQueryAxis; } public event Action<QueryAxis> VisitedQueryAxis; public override Node VisitQueryAxis(QueryAxis axis) { if (VisitedQueryAxis != null) VisitedQueryAxis(axis); return base.VisitQueryAxis(axis); }