Form() public static method

public static Form ( PlSqlParser context ) : ElementNode
context PlSqlParser
return ElementNode
Beispiel #1
0
        public static SqlStatement Statement(PlSqlParser.AssignmentStatementContext context)
        {
            SqlExpression varRef;

            if (context.general_element() != null)
            {
                var element = ElementNode.Form(context.general_element());
                if (element.Argument != null &&
                    element.Argument.Length > 0)
                {
                    throw new ParseCanceledException("Invalid assignment: cannot assign a function");
                }

                var name = element.Id;
                if (name.Parent != null)
                {
                    throw new ParseCanceledException("Invalid assignment.");
                }

                varRef = SqlExpression.VariableReference(name.ToString());
            }
            else if (context.bind_variable() != null)
            {
                var varName = Name.Variable(context.bind_variable());
                varRef = SqlExpression.VariableReference(varName);
            }
            else
            {
                throw new ParseCanceledException("Invalid assignment syntax");
            }

            var valueExp = Expression.Build(context.expression());

            return(new AssignVariableStatement(varRef, valueExp));
        }
        public override SqlExpression VisitGeneral_element(PlSqlParser.General_elementContext context)
        {
            var element = ElementNode.Form(context);
            var name    = element.Id;

            if (element.Argument == null ||
                element.Argument.Length == 0)
            {
                return(SqlExpression.Reference(name));
            }

            // TODO: support argument naming in DeveelDB
            var funcArgs = element.Argument.Select(x => x.Expression).ToArray();

            return(SqlExpression.FunctionCall(name, funcArgs));
        }