Example #1
0
 protected virtual void EmitCalculusFromClause(CalculusFromClause clause)
 {
     NewLine();
     Indent();
     AppendFormat("{0} ", Keywords.From);
     for (int index = 0; index < clause.TableSpecifiers.Count; index++)
     {
         if (index > 0)
         {
             EmitListSeparator();
         }
         EmitTableSpecifier(clause.TableSpecifiers[index]);
     }
 }
Example #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;
        }