示例#1
0
        private List <DataObject> ExecuteOneQuery(JObject jsonQuery)
        {
            QueryBase queryBase;
            string    command = ((string)jsonQuery.GetProperty("cmd").Value).Trim();

            if (command == "select")
            {
                queryBase = new QuerySelect(this, jsonQuery);
            }
            else if (command == "insert")
            {
                queryBase = new QueryInsert(this, jsonQuery);
            }
            else if (command == "update")
            {
                queryBase = new QueryUpdate(this, jsonQuery);
            }
            else if (command == "delete")
            {
                queryBase = new QueryDelete(this, jsonQuery);
            }
            else
            {
                throw new AegisException(RoseResult.UnknownCommand);
            }


            var ret = queryBase.Execute();

            return(ret);
        }
示例#2
0
        public override Node VisitQueryDelete(QueryDelete delete)
        {
            delete.Source = this.VisitExpression(delete.Source);
            Composer save    = this.contextComposer;
            Composer c       = this.contextComposer = this.GetComposer(delete.Source);
            bool     savehcr = this.hasContextReference;

            this.hasContextReference = false;
            this.VisitExpression(delete.Target);
            this.hasContextReference = savehcr;
            this.contextComposer     = save;
            return(this.Compose(delete, c));
        }
示例#3
0
 public virtual Node VisitQueryDelete(QueryDelete delete, QueryDelete changes, QueryDelete deletions, QueryDelete insertions){
   this.UpdateSourceContext(delete, changes);
   if (delete == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return delete;
 }
    public virtual Differences VisitQueryDelete(QueryDelete delete1, QueryDelete delete2){
      Differences differences = new Differences(delete1, delete2);
      if (delete1 == null || delete2 == null){
        if (delete1 != delete2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryDelete changes = (QueryDelete)delete2.Clone();
      QueryDelete deletions = (QueryDelete)delete2.Clone();
      QueryDelete insertions = (QueryDelete)delete2.Clone();

      //      delete1.Context;
      //      delete1.Source;
      //      delete1.Target;

      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;
    }
示例#5
0
 public virtual Node VisitQueryDelete(QueryDelete delete){
   if (delete == null) return null;
   delete.Source = this.VisitExpression(delete.Source);
   /*delete.Target =*/ this.VisitExpression(delete.Target); //REVIEW: why should this not be updated?
   return delete;
 }
示例#6
0
    public override Node VisitQueryDelete(QueryDelete qd) {
      if (qd == null) return null;
      qd.Source = this.VisitExpression(qd.Source);
      if (qd.Source == null || qd.Source.Type == null) return null;
      Cardinality card = this.typeSystem.GetCardinality(qd.Source, this.TypeViewer);
      if (card != Cardinality.OneOrMore && card != Cardinality.ZeroOrMore) {
        this.HandleError(qd.Source, Error.QueryNotStream);
        return null;
      }
      qd.Target = this.VisitExpression(qd.Target);

      // Target can not be null if there is more than one source
      QueryFilter qf = qd.Source as QueryFilter;
      Expression source = (qf != null) ? qf.Source : qd.Source;
      QueryJoin qj = source as QueryJoin;
      if (qj != null && qd.Target == null) {
        this.HandleError(qd.Source, Error.QueryBadDeleteTarget);
        return null;
      }
      Expression collection = qd.SourceEnumerable = (qd.Target == null) ? ((QueryIterator)source).Expression : 
        GetSourceCollection(source, qd.Target.Type);
      TypeNode elementType = this.typeSystem.GetStreamElementType(collection, this.TypeViewer);

      if (elementType == null) return null;
      if (collection == null || collection.Type == null) return null;
      Method mRemove = this.GetTypeView(collection.Type).GetMethod(StandardIds.Remove, elementType);
      if (mRemove == null) mRemove = this.GetTypeView(collection.Type).GetMethod(StandardIds.Remove, SystemTypes.Object);
      Method mRemoveAt = this.GetTypeView(source.Type).GetMethod(idRemoveAt, SystemTypes.Int32);
      if (mRemoveAt == null) mRemoveAt = this.GetTypeView(collection.Type).GetMethod(idRemoveAt, SystemTypes.Int32);
      if (mRemove == null && mRemoveAt == null) {
        this.HandleError(collection, Error.QueryNotDeleteStream, this.GetTypeName(collection.Type), this.GetTypeName(elementType));
        return null;
      }
      if (qd.Type == null) return null;
      return qd;
    }
示例#7
0
 public override Node VisitQueryDelete(QueryDelete delete){
   if (delete == null) return null;
   delete.Source = this.VisitExpression(delete.Source);
   if (delete.Source == null || delete.Source.Type == null) return delete;
   TypeNode sourceElementType = this.typeSystem.GetStreamElementType(delete.Source, this.TypeViewer);
   delete.Context = this.contextScope = new ContextScope(this.contextScope, sourceElementType);
   delete.Target = this.VisitExpression(delete.Target);
   this.contextScope = this.contextScope.Previous;
   delete.Type = SystemTypes.Int32;
   return delete;
 }
示例#8
0
 public override Node VisitQueryDelete(QueryDelete delete){
   if (delete == null) return null;
   return base.VisitQueryDelete((QueryDelete)delete.Clone());
 }
示例#9
0
 public virtual Node VisitQueryDelete(QueryDelete delete1, QueryDelete delete2){
   if (delete1 == null) return null;
   if (delete2 == null){
     delete1.Source = this.VisitExpression(delete1.Source, null);
     /*delete1.Target =*/ this.VisitExpression(delete1.Target, null); //REVIEW: why should this not be updated?
   }else{
     delete1.Source = this.VisitExpression(delete1.Source, delete2.Source);
     /*delete1.Target =*/ this.VisitExpression(delete1.Target, delete2.Target); //REVIEW: why should this not be updated?
   }
   return delete1;
 }
示例#10
0
    public override Node VisitQueryDelete(QueryDelete qd) {
      if (qd.Type == null || qd.Source == null || qd.Source.Type == null) return null;
      Block block = new Block(new StatementList(10));
      
      // get elementType
      QueryFilter qf = qd.Source as QueryFilter;
      Expression source = (qf != null) ? qf.Source : qd.Source;
      Expression collection = qd.SourceEnumerable;   
      TypeNode elementType = this.typeSystem.GetStreamElementType(collection, this.TypeViewer);

      if (qd.Source is QueryFilter) {        
        // Target can not be null if there is more than one source                
        qf = qd.Source as QueryFilter;
        Local locSource = new Local(collection.Type);
        block.Statements.Add(new AssignmentStatement(locSource, collection));
        collection = locSource;

        Method mRemoveAt = this.GetTypeView(locSource.Type).GetMethod(idRemoveAt, SystemTypes.Int32);
        Method mRemove = this.GetTypeView(locSource.Type).GetMethod(StandardIds.Remove, elementType);
        if (mRemove == null) mRemove = this.GetTypeView(locSource.Type).GetMethod(StandardIds.Remove, SystemTypes.Object);

        // need to create a list of matches to delete, since you can't normally delete from a
        // collection while you are iterating it
        Expression locList = new Local(SystemTypes.ArrayList);
        Construct cons = new Construct();
        cons.Constructor = new MemberBinding(null, SystemTypes.ArrayList.GetConstructor());
        block.Statements.Add(new AssignmentStatement(locList, cons));

        if (mRemoveAt != null) {
          // iterate source and find all items to be deleted, add position to list
          Expression locTarget = new Local(elementType);
          Expression locPos = new Local(SystemTypes.Int32);
          Block inner = null;
          // pre-prepare position info for filter
          qf.Context.Position = locPos;
          qf.Context.PreFilter = new Block(new StatementList(1));
          qf.Context.PreFilter.Statements.Add(new AssignmentStatement(locPos, Literal.Int32Zero));
          qf.Context.PostFilter = new Block(new StatementList(1));
          qf.Context.PostFilter.Statements.Add(new AssignmentStatement(locPos, new BinaryExpression(locPos, Literal.Int32One, NodeType.Add)));
          // iterate over filtered items
          block.Statements.Add(this.BuildClosureForEach(qd.Source, ref locTarget, out inner, this.currentMethod.Body.Scope));
          // add position to list
          Method madd = SystemTypes.ArrayList.GetMethod(StandardIds.Add, SystemTypes.Object);
          MethodCall mcAdd = new MethodCall(new MemberBinding(locList, madd), new ExpressionList(this.Box(locPos)));
          mcAdd.Type = madd.ReturnType;
          inner.Statements.Add(new ExpressionStatement(mcAdd));
          // reverse the positions, so we do last to first
          Method mReverse = SystemTypes.ArrayList.GetMethod(idReverse);
          MethodCall mcReverse = new MethodCall(new MemberBinding(locList, mReverse), null);
          mcReverse.Type = mReverse.ReturnType;
          block.Statements.Add(new ExpressionStatement(mcReverse));
          // loop over items in the list, and remove each by its original position
          block.Statements.Add(this.BuildClosureForEach(locList, ref locPos, out inner, this.currentMethod.Body.Scope));
          MethodCall mcRemoveAt = new MethodCall(new MemberBinding(locSource, mRemoveAt), new ExpressionList(locPos));
          mcRemoveAt.Type = mRemoveAt.ReturnType;
          if ((mRemoveAt.Flags & MethodFlags.Virtual) != 0)
            mcRemoveAt.NodeType = NodeType.Callvirt;
          inner.Statements.Add(new ExpressionStatement(mcRemoveAt));
          // return the number of deletes
          Method mGetCount = SystemTypes.ArrayList.GetMethod(idGetCount);
          MethodCall mcGetCount = new MethodCall(new MemberBinding(locList, mGetCount), null);
          mcGetCount.Type = mGetCount.ReturnType;
          block.Statements.Add(new ExpressionStatement(mcGetCount));
        }
        else if (mRemove != null) {
          // iterate source and find all items to be deleted
          Expression locTarget = new Local(elementType);
          Block inner = null;
          block.Statements.Add(this.BuildClosureForEach(qd.Source, ref locTarget, out inner, this.currentMethod.Body.Scope));
          Method madd = SystemTypes.ArrayList.GetMethod(StandardIds.Add, SystemTypes.Object);
          MethodCall mcAdd = new MethodCall(new MemberBinding(locList, madd), new ExpressionList(this.Box(locTarget)));
          mcAdd.Type = madd.ReturnType;
          inner.Statements.Add(new ExpressionStatement(mcAdd));
          // loop over items in the list
          block.Statements.Add(this.BuildClosureForEach(locList, ref locTarget, out inner, this.currentMethod.Body.Scope));
          MethodCall mcRemove = new MethodCall(new MemberBinding(locSource, mRemove), new ExpressionList(this.Box(locTarget)));
          mcRemove.Type = mRemove.ReturnType;
          if ((mRemove.Flags & MethodFlags.Virtual) != 0)
            mcRemove.NodeType = NodeType.Callvirt;
          inner.Statements.Add(new ExpressionStatement(mcRemove));
          // return the number of deletes
          Method mGetCount = SystemTypes.ArrayList.GetMethod(idGetCount);
          MethodCall mcGetCount = new MethodCall(new MemberBinding(locList, mGetCount), null);
          mcGetCount.Type = mGetCount.ReturnType;
          block.Statements.Add(new ExpressionStatement(mcGetCount));
        }
        else {
          return null;
        }
      }
      else {
        Local locSource = new Local(collection.Type);
        Method mRemove = this.GetTypeView(locSource.Type).GetMethod(StandardIds.Remove, elementType);
        if (mRemove == null) mRemove = this.GetTypeView(locSource.Type).GetMethod(StandardIds.Remove, SystemTypes.Object);
        if (mRemove == null) return null;
        block.Statements.Add(new AssignmentStatement(locSource, collection));        
        if (qd.Target != null && qd.Target.Type != null) {
          MethodCall mcRemove = new MethodCall(new MemberBinding(locSource, mRemove), new ExpressionList(this.typeSystem.ImplicitCoercion(qd.Target, mRemove.Parameters[0].Type, this.TypeViewer)));
          mcRemove.Type = mRemove.ReturnType;
          if ((mRemove.Flags & MethodFlags.Virtual) != 0)
            mcRemove.NodeType = NodeType.Callvirt;
          block.Statements.Add(new ExpressionStatement(mcRemove));
        }
        block.Statements.Add(new ExpressionStatement(new Literal(qd.Target == null ? 0 : 1)));
      }
      return this.VisitBlockExpression(new BlockExpression(block, SystemTypes.Int32));
    }
示例#11
0
 public override Node VisitQueryDelete( QueryDelete delete ){
   Scope savedScope = this.scope;
   Scope scope = this.scope = new QueryScope(savedScope);
   this.AddToAllScopes(this.scope);
   delete.Source = (Expression)this.Visit(delete.Source);
   delete.Target = this.VisitExpression( delete.Target );
   this.scope = savedScope;
   return delete;
 }
示例#12
0
 public override Node VisitQueryDelete(QueryDelete delete) {
   delete.Source = this.VisitExpression(delete.Source);
   Composer save = this.contextComposer;
   Composer c = this.contextComposer = this.GetComposer(delete.Source);
   bool savehcr = this.hasContextReference;
   this.hasContextReference = false;
   this.VisitExpression(delete.Target);
   this.hasContextReference = savehcr;
   this.contextComposer = save;
   return this.Compose(delete, c);
 }
 public EventingVisitor(Action<QueryDelete> visitQueryDelete) { VisitedQueryDelete += visitQueryDelete; } public event Action<QueryDelete> VisitedQueryDelete; public override Node VisitQueryDelete(QueryDelete delete) { if (VisitedQueryDelete != null) VisitedQueryDelete(delete); return base.VisitQueryDelete(delete); }