Esempio n. 1
0
        public static PrimarSqlSetColumnExpressionNode VisitUpdatedElement(UpdatedElementContext context)
        {
            var column = IdentifierVisitor.VisitFullColumnName(context.fullColumnName());

            var assignNode = new PrimarSqlSetColumnExpressionNode
            {
                Target = column.Name,
            };

            assignNode.Accessors.AddRange(column.Accessors);

            QsiExpressionNode expression;

            if (context.expression() != null)
            {
                expression = VisitExpression(context.expression());
            }
            else if (context.arrayExpression() != null)
            {
                expression = VisitArrayExpression(context.arrayExpression());
            }
            else if (context.arrayAddExpression() != null)
            {
                expression = VisitArrayAddExpression(context.arrayAddExpression());
            }
            else
            {
                expression = TreeHelper.CreateNullLiteral();
            }

            assignNode.Value.SetValue(expression);

            PrimarSqlTree.PutContextSpan(assignNode, context);
            return(assignNode);
        }
Esempio n. 2
0
        public static QsiTableReferenceNode VisitTableName(TableNameContext context)
        {
            return(TreeHelper.Create <QsiTableReferenceNode>(n =>
            {
                n.Identifier = IdentifierVisitor.VisitFullId(context.fullId());

                PrimarSqlTree.PutContextSpan(n, context);
            }));
        }
Esempio n. 3
0
        private static QsiColumnExpressionNode VisitFullColumnName(FullColumnNameContext context)
        {
            return(TreeHelper.Create <QsiColumnExpressionNode>(n =>
            {
                n.Column.SetValue(IdentifierVisitor.VisitFullColumnName(context));

                PrimarSqlTree.PutContextSpan(n.Column.Value, context);
                PrimarSqlTree.PutContextSpan(n, context);
            }));
        }
Esempio n. 4
0
        public static QsiAliasNode CreateAliasNode(UidContext context)
        {
            var node = new QsiAliasNode
            {
                Name = IdentifierVisitor.VisitUid(context)
            };

            PrimarSqlTree.PutContextSpan(node, context);

            return(node);
        }
Esempio n. 5
0
        public static PrimarSqlSetColumnExpressionNode VisitRemovedElement(RemovedElementContext context)
        {
            var column = IdentifierVisitor.VisitFullColumnName(context.fullColumnName());

            var assignNode = new PrimarSqlSetColumnExpressionNode
            {
                Target = column.Name,
            };

            assignNode.Accessors.AddRange(column.Accessors);

            PrimarSqlTree.PutContextSpan(assignNode, context);
            return(assignNode);
        }
Esempio n. 6
0
        public static QsiColumnNode VisitSelectColumnElement(SelectColumnElementContext context)
        {
            var nameContext = context.fullColumnName();
            var column      = IdentifierVisitor.VisitFullColumnName(nameContext);

            if (context.alias == null)
            {
                return(column);
            }

            return(TreeHelper.Create <QsiDerivedColumnNode>(n =>
            {
                n.Column.SetValue(column);
                n.Alias.SetValue(CreateAliasNode(context.alias));
            }));
        }
Esempio n. 7
0
        public static QsiActionNode VisitInsertStatement(InsertStatementContext context)
        {
            var node = new QsiDataInsertActionNode
            {
                ConflictBehavior = context.IGNORE() != null ? QsiDataConflictBehavior.Ignore : QsiDataConflictBehavior.None
            };

            if (context.tableName() == null)
            {
                throw new QsiException(QsiError.Syntax);
            }

            node.Target.SetValue(TableVisitor.VisitTableName(context.tableName()));

            switch (context.insertStatementValue())
            {
            case SubqueryInsertStatementContext _:
            {
                throw TreeHelper.NotSupportedFeature("subquery insert");
            }

            case ExpressionInsertStatementContext expressionContext:
            {
                if (context.columns != null)
                {
                    node.Columns = context.columns.uid()
                                   .Select(i => new QsiQualifiedIdentifier(IdentifierVisitor.VisitUid(i)))
                                   .ToArray();
                }

                IEnumerable <QsiRowValueExpressionNode> rows = expressionContext
                                                               .expressionsWithDefaults()
                                                               .Select(ExpressionVisitor.VisitExpressionsWithDefaults);

                node.Values.AddRange(rows);
                break;
            }

            case JsonInsertStatementContext jsonContext:
            {
                (JObject, JsonObjectContext x)[] objects = jsonContext.jsonObject()