예제 #1
0
        protected override void EmitSelectStatement(SQL.SelectStatement selectStatement)
        {
            var topStatement = selectStatement as SelectStatement;

            _topClauses.Push(topStatement != null ? topStatement.TopClause : null);
            try
            {
                base.EmitSelectStatement(selectStatement);
            }
            finally
            {
                _topClauses.Pop();
            }

            if ((selectStatement.Modifiers != null) && selectStatement.Modifiers.Contains("OptimizerHints"))
            {
                NewLine();
                Indent();
                Append(selectStatement.Modifiers["OptimizerHints"].Value);
            }
        }
예제 #2
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var selectExpression = new SQLModel.SelectExpression();

            var fromClause = new SQLModel.CalculusFromClause();
            selectExpression.FromClause = fromClause;

            var queryExpression = new SQLModel.QueryExpression();
            queryExpression.SelectExpression = selectExpression;

            var selectStatement = new SQLModel.SelectStatement();
            selectStatement.QueryExpression = queryExpression;

            // 1..* source: AliasedQuerySource
            foreach (var child in ((Node)node).Children.Where(n => n.Name == "source"))
            {
                var tableSpecifier = TranslateAliasedQuerySource(context, child);
                fromClause.TableSpecifiers.Add(tableSpecifier);
            }

            // 0..* define: DefineClause
            foreach (var child in ((Node)node).Children.Where(n => n.Name == "define"))
            {
                // TODO: This would need to be nested to be accessible within context in the SQL query
                throw new NotImplementedException("Define clause translation is not yet implemented");
            }

            // 0..* relationship: With | Without
            Model.Expression relationshipConditions = null;
            foreach (var child in ((Node)node).Children.Where(n => n.Name == "relationship"))
            {
                var relationshipCondition = TranslateRelationshipClause(context, child);
                if (relationshipConditions != null)
                {
                    relationshipConditions = new Model.BinaryExpression(relationshipConditions, "iAnd", relationshipCondition);
                }
                else
                {
                    relationshipConditions = relationshipCondition;
                }
            }

            // 0..1 where: Expression
            Model.Expression whereCondition = null;
            var whereConditionNode = node.Children.SingleOrDefault(n => n.Name == "where");
            if (whereConditionNode != null)
            {
                whereCondition = (Model.Expression)context.TranslateNode(whereConditionNode);
            }

            // 0..1 return: ReturnClause
            var returnClause = ((Node)node).Children.SingleOrDefault(n => n.Name == "return");
            if (returnClause != null)
            {
                var selectClause = TranslateReturnClause(context, returnClause);
                selectExpression.SelectClause = selectClause;
            }

            if (selectExpression.SelectClause == null)
            {
                selectExpression.SelectClause = new SQLModel.SelectClause();
                selectExpression.SelectClause.NonProject = true;
            }

            // 0..1 sort: SortClause
            var sortClause = ((Node)node).Children.SingleOrDefault(n => n.Name == "sort");
            if (sortClause != null)
            {
                var orderClause = TranslateSortClause(context, sortClause);
                selectStatement.OrderClause = orderClause;
            }

            return selectStatement;
        }
예제 #3
0
        // ServerName

        public override SelectStatement TranslateOrder(DevicePlan devicePlan, TableNode node, SelectStatement statement, bool inContextOrderBy)
        {
            if (statement.Modifiers == null)
            {
                statement.Modifiers = new LanguageModifiers();
            }
            statement.Modifiers.Add(new LanguageModifier("OptimizerHints", "option (fast 1)"));
            return(base.TranslateOrder(devicePlan, node, statement, inContextOrderBy));
        }