Esempio n. 1
0
 /// <summary>
 /// Reads the current node in the abstract syntax tree.
 /// </summary>
 /// <param name="node">The current node in the abstract syntax tree.</param>
 /// <param name="plan">The <see cref="QueryExecutionPlan"/> currently being built.</param>
 private void ReadClause(ParseTreeNode node, QueryExecutionPlan plan)
 {
     foreach (var builder in this.builders)
     {
         builder.BuildOperation(scope, node, plan);
     }
 }
 /// <summary>
 /// Reads the current node in the abstract syntax tree.
 /// </summary>
 /// <param name="node">The current node in the abstract syntax tree.</param>
 /// <param name="plan">The <see cref="QueryExecutionPlan"/> currently being built.</param>
 private void ReadClause(ParseTreeNode node, QueryExecutionPlan plan)
 {
     foreach (var builder in this.builders)
     {
         if (scope.Count >= 2 && scope.ElementAt(scope.Count - 2) == builder.OperationName)
         {
             builder.BuildOperation(scope, node, plan);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Builds the <see cref="QueryExecutionPlan"/> by parsing the abstract syntax tree generated by the <see cref="DqlQueryGrammar"/>.
        /// </summary>
        /// <param name="node">Current node in the abstract syntax tree.</param>
        /// <param name="plan">The <see cref="QueryExecutionPlan"/> currently being built.</param>
        /// <returns><see cref="QueryExecutionPlan"/> that is prepared for execution against the database.</returns>
        public QueryExecutionPlan BuildQueryExecutionPlan(ParseTreeNode node, QueryExecutionPlan plan)
        {
            scope.Push(node.Term.Name);
            this.ReadClause(node, plan);

            foreach (ParseTreeNode child in node.ChildNodes)
            {
                this.BuildQueryExecutionPlan(child, plan);
            }

            scope.Pop();
            return plan;
        }
        /// <summary>
        /// Builds the <see cref="QueryExecutionPlan"/> by parsing the abstract syntax tree generated by the <see cref="DqlQueryGrammar"/>.
        /// </summary>
        /// <param name="node">Current node in the abstract syntax tree.</param>
        /// <param name="plan">The <see cref="QueryExecutionPlan"/> currently being built.</param>
        /// <returns><see cref="QueryExecutionPlan"/> that is prepared for execution against the database.</returns>
        public QueryExecutionPlan BuildQueryExecutionPlan(ParseTreeNode node, QueryExecutionPlan plan)
        {
            scope.Push(node.Term.Name);
            this.ReadClause(node, plan);

            foreach (ParseTreeNode child in node.ChildNodes)
            {
                this.BuildQueryExecutionPlan(child, plan);
            }

            scope.Pop();
            return(plan);
        }
        /// <summary>
        /// Build the current operation in the <see cref="QueryExecutionPlan"/> by reading the abstract syntax tree.
        /// </summary>
        /// <param name="scope">Scope of the current <see cref="ParseTreeNode"/>.</param>
        /// <param name="node">Current <see cref="ParseTreeNode"/> in the abstract syntax tree.</param>
        /// <param name="plan">The current <see cref="QueryExecutionPlan"/> being built.</param>
        public void BuildOperation(Stack<string> scope, ParseTreeNode node, QueryExecutionPlan plan)
        {
            if (node.Term.Name == this.OperationName)
            {
                // Select clause
                plan.Operations.Add(new SelectOperation());
            }

            var operation = (SelectOperation)plan.Current;

            if (scope.Contains("selList") && node.Term.Name == "id_simple")
            {
                // Select column list
                operation.ColumnNames.Add(node.Token.ValueString);
            }
            else if (scope.Contains("selList") && node.Term.Name == "*")
            {
                // Select column list
                operation.ColumnNames.Add(node.Token.ValueString);
            }
            else if (scope.Contains("fromClauseOpt") && node.Term.Name == "id_simple")
            {
                // From clause
                operation.TableName = node.Token.ValueString;
            }
            else if (scope.Contains("whereClauseOpt") && node.Term.Name == "binExpr")
            {
                // Where clause
                if (node.ChildNodes[0].Term.Name == "binExpr")
                {
                    // Handle multiple where clauses.
                    foreach (var child in node.ChildNodes)
                    {
                        if (child.Term.Name == "binExpr")
                        {
                            var column = child.ChildNodes[0].ChildNodes[0].Token.ValueString;
                            var val = child.ChildNodes[2].Token.ValueString;
                            operation.WhereClauses.Add(column, val);
                        }
                    }
                }
                else if (node.Term.Name == "binExpr" && operation.WhereClauses.Count == 0)
                {
                    // Handle a single where clause.
                    var column = node.ChildNodes[0].ChildNodes[0].Token.ValueString;
                    var val = node.ChildNodes[2].Token.ValueString;
                    operation.WhereClauses.Add(column, val);
                }
            }
        }
        /// <summary>
        /// Build the current operation in the <see cref="QueryExecutionPlan"/> by reading the abstract syntax tree.
        /// </summary>
        /// <param name="scope">Scope of the current <see cref="ParseTreeNode"/>.</param>
        /// <param name="node">Current <see cref="ParseTreeNode"/> in the abstract syntax tree.</param>
        /// <param name="plan">The current <see cref="QueryExecutionPlan"/> being built.</param>
        public void BuildOperation(Stack<string> scope, ParseTreeNode node, QueryExecutionPlan plan)
        {
            UpdateOperation operation;

            if (node.Term.Name == this.OperationName)
            {
                // Update statement
                operation = new UpdateOperation();
                operation.TableName = node.ChildNodes[1].ChildNodes[0].Token.ValueString;
                plan.Operations.Add(operation);
                
            }

            operation = (UpdateOperation) plan.Current;

            if (node.Term.Name == "assignment")
            {
                operation.Assignments.Add(node.ChildNodes[0].ChildNodes[0].Token.ValueString, node.ChildNodes[2].Token.ValueString);
            }
            else if (scope.Contains("whereClauseOpt") && node.Term.Name == "binExpr")
            {
                // Where clause
                if (node.ChildNodes[0].Term.Name == "binExpr")
                {
                    // Handle multiple where clauses.
                    foreach (var child in node.ChildNodes)
                    {
                        if (child.Term.Name == "binExpr")
                        {
                            var column = child.ChildNodes[0].ChildNodes[0].Token.ValueString;
                            var val = child.ChildNodes[2].Token.ValueString;
                            operation.WhereClauses.Add(column, val);
                        }
                    }
                }
                else if (node.Term.Name == "binExpr" && operation.WhereClauses.Count == 0)
                {
                    // Handle a single where clause.
                    var column = node.ChildNodes[0].ChildNodes[0].Token.ValueString;
                    var val = node.ChildNodes[2].Token.ValueString;
                    operation.WhereClauses.Add(column, val);
                }
            }
        }