예제 #1
0
파일: Update.cs 프로젝트: iamr8/IoTGateway
 /// <summary>
 /// Executes an UPDATE statement against the object database.
 /// </summary>
 /// <param name="Source">Source to update objects from.</param>
 /// <param name="SetOperations">Set operations to perform.</param>
 /// <param name="Where">Optional where clause</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public Update(SourceDefinition Source, Assignment[] SetOperations, ScriptNode Where, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.source        = Source;
     this.setOperations = SetOperations;
     this.where         = Where;
 }
예제 #2
0
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            ScriptNode Node = this.source;

            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node != this.source)
            {
                if (Node is SourceDefinition Source2)
                {
                    this.source = Source2;
                }
                else
                {
                    return(false);
                }
            }

            if (!(this.where is null) && !Callback(ref this.where, State))
            {
                return(false);
            }

            if (!DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Executes an INSERT ... VALUES ... statement against the object database.
        /// </summary>
        /// <param name="Source">Source to update objects from.</param>
        /// <param name="Columns">Columns</param>
        /// <param name="Values">Values</param>
        /// <param name="Start">Start position in script expression.</param>
        /// <param name="Length">Length of expression covered by node.</param>
        /// <param name="Expression">Expression containing script.</param>
        public InsertValues(SourceDefinition Source, ElementList Columns, ElementList Values, int Start, int Length, Expression Expression)
            : base(Start, Length, Expression)
        {
            if ((this.nrFields = Columns.Elements.Length) != Values.Elements.Length)
            {
                throw new ArgumentException("Column and Value lists must have the same lengths.", nameof(Values));
            }

            this.source  = Source;
            this.columns = Columns;
            this.values  = Values;
        }
예제 #4
0
        /// <summary>
        /// Executes an CREATE INDEX ... ON ... (...) statement against the object database.
        /// </summary>
        /// <param name="Name">Name of index.</param>
        /// <param name="Source">Source to create index in.</param>
        /// <param name="Columns">Columns</param>
        /// <param name="Ascending">If columns are escending (true) or descending (false).</param>
        /// <param name="Start">Start position in script expression.</param>
        /// <param name="Length">Length of expression covered by node.</param>
        /// <param name="Expression">Expression containing script.</param>
        public CreateIndex(ScriptNode Name, SourceDefinition Source, ScriptNode[] Columns, bool[] Ascending,
                           int Start, int Length, Expression Expression)
            : base(Start, Length, Expression)
        {
            this.nrColumns = Columns.Length;
            if (Ascending.Length != this.nrColumns)
            {
                throw new ArgumentException("Number of columns does not match number of ascending argument values.", nameof(Ascending));
            }

            this.name      = Name;
            this.source    = Source;
            this.columns   = Columns;
            this.ascending = Ascending;
        }
예제 #5
0
        /// <summary>
        /// Executes a SELECT statement against the object database.
        /// </summary>
        /// <param name="Columns">Columns to select. If null, all columns are selected.</param>
        /// <param name="ColumnNames">Optional renaming of columns.</param>
        /// <param name="Source">Source(s) to select from.</param>
        /// <param name="Where">Optional where clause</param>
        /// <param name="GroupBy">Optional grouping</param>
        /// <param name="GroupByNames">Optional renaming of groups</param>
        /// <param name="Having">Optional Having clause</param>
        /// <param name="OrderBy">Optional ordering</param>
        /// <param name="Top">Optional limit on number of records to return</param>
        /// <param name="Offset">Optional offset into result set where reporting begins</param>
        /// <param name="Distinct">If only distinct (unique) rows are to be returned.</param>
        /// <param name="Start">Start position in script expression.</param>
        /// <param name="Length">Length of expression covered by node.</param>
        /// <param name="Expression">Expression containing script.</param>
        public Select(ScriptNode[] Columns, ScriptNode[] ColumnNames, SourceDefinition Source, ScriptNode Where, ScriptNode[] GroupBy,
                      ScriptNode[] GroupByNames, ScriptNode Having, KeyValuePair <ScriptNode, bool>[] OrderBy, ScriptNode Top, ScriptNode Offset,
                      bool Distinct, int Start, int Length, Expression Expression)
            : base(Start, Length, Expression)
        {
            this.columns      = Columns;
            this.columnNames  = ColumnNames;
            this.top          = Top;
            this.source       = Source;
            this.where        = Where;
            this.groupBy      = GroupBy;
            this.groupByNames = GroupByNames;
            this.having       = Having;
            this.orderBy      = OrderBy;
            this.offset       = Offset;
            this.distinct     = Distinct;

            if (this.columnNames is null ^ this.columns is null)
            {
                throw new ArgumentException("Columns and ColumnNames must both be null or not null.", nameof(ColumnNames));
            }

            if (!(this.columns is null) && this.columns.Length != this.columnNames.Length)
            {
                throw new ArgumentException("Columns and ColumnNames must be of equal length.", nameof(ColumnNames));
            }

            if (this.columnNames is null ^ this.columns is null)
            {
                throw new ArgumentException("GroupBy and GroupByNames must both be null or not null.", nameof(GroupByNames));
            }

            if (!(this.columns is null) && this.columns.Length != this.columnNames.Length)
            {
                throw new ArgumentException("GroupBy and GroupByNames must be of equal length.", nameof(GroupByNames));
            }
        }
예제 #6
0
파일: Update.cs 프로젝트: iamr8/IoTGateway
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!(SetOperation?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                    {
                        return(false);
                    }
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            ScriptNode Node = this.source;

            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node != this.source)
            {
                if (Node is SourceDefinition Source2)
                {
                    this.source = Source2;
                }
                else
                {
                    return(false);
                }
            }

            int i, c = this.setOperations.Length;

            for (i = 0; i < c; i++)
            {
                ScriptNode SetOperation = this.setOperations[i];

                if (!(SetOperation is null))
                {
                    if (!Callback(ref SetOperation, State))
                    {
                        return(false);
                    }

                    if (SetOperation is Assignment Assignment)
                    {
                        this.setOperations[i] = Assignment;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (!(this.where is null) && !Callback(ref this.where, State))
            {
                return(false);
            }

            if (!DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!(SetOperation?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                    {
                        return(false);
                    }
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.columns?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.values?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            ScriptNode Node = this.source;

            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node is SourceDefinition Source2)
            {
                this.source = Source2;
            }
            else
            {
                return(false);
            }

            Node = this.columns;
            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node is ElementList List1)
            {
                this.columns = List1;
            }
            else
            {
                return(false);
            }

            Node = this.values;
            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node is ElementList List2)
            {
                this.values = List2;
            }
            else
            {
                return(false);
            }

            if (!DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.columns?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.values?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #8
0
 /// <summary>
 /// Executes a DELETE statement against the object database.
 /// </summary>
 /// <param name="Source">Source to delete from.</param>
 /// <param name="Where">Optional where clause</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public Delete(SourceDefinition Source, ScriptNode Where, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.source = Source;
     this.where  = Where;
 }
예제 #9
0
 /// <summary>
 /// Executes an DROP COLLECTION|TABLE ... statement against the object database.
 /// </summary>
 /// <param name="Source">Source to create index in.</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public DropCollection(SourceDefinition Source, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.source = Source;
 }
예제 #10
0
 /// <summary>
 /// Executes an DROP INDEX ... ON ... statement against the object database.
 /// </summary>
 /// <param name="Name">Name of index.</param>
 /// <param name="Source">Source to create index in.</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public DropIndex(ScriptNode Name, SourceDefinition Source, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.name   = Name;
     this.source = Source;
 }
예제 #11
0
 /// <summary>
 /// Executes an INSERT SELECT statement against the object database.
 /// </summary>
 /// <param name="Source">Source to update objects from.</param>
 /// <param name="Select">SELECT statement.</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public InsertSelect(SourceDefinition Source, Select Select, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.source = Source;
     this.select = Select;
 }
예제 #12
0
 /// <summary>
 /// Executes an INSERT ... OBJECT[S] ... statement against the object database.
 /// </summary>
 /// <param name="Source">Source to update objects from.</param>
 /// <param name="Objects">Objects</param>
 /// <param name="Start">Start position in script expression.</param>
 /// <param name="Length">Length of expression covered by node.</param>
 /// <param name="Expression">Expression containing script.</param>
 public InsertObjects(SourceDefinition Source, ElementList Objects, int Start, int Length, Expression Expression)
     : base(Start, Length, Expression)
 {
     this.source  = Source;
     this.objects = Objects;
 }
예제 #13
0
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!(this.name?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!ForAllChildNodes(Callback, this.columns, State, DepthFirst))
                {
                    return(false);
                }
            }

            if (!(this.name is null) && !Callback(ref this.name, State))
            {
                return(false);
            }

            ScriptNode Node = this.source;

            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node is SourceDefinition Source2)
            {
                this.source = Source2;
            }
            else
            {
                return(false);
            }

            int i;

            for (i = 0; i < this.nrColumns; i++)
            {
                if (!(this.columns[i] is null) && !Callback(ref this.columns[i], State))
                {
                    return(false);
                }
            }

            if (!DepthFirst)
            {
                if (!(this.name?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                if (!ForAllChildNodes(Callback, this.columns, State, DepthFirst))
                {
                    return(false);
                }
            }

            return(true);
        }