public override SqlObject VisitLimit_count([NotNull] sqlParser.Limit_countContext context)
        {
            Contract.Requires(context != null);

            SqlLimitSpec sqlLimitSpec;

            if (context.NUMERIC_LITERAL() != null)
            {
                sqlLimitSpec = SqlLimitSpec.Create(
                    SqlNumberLiteral.Create(
                        CstToAstVisitor.GetNumber64ValueFromNode(
                            context.NUMERIC_LITERAL())));
            }
            else if (context.PARAMETER() != null)
            {
                sqlLimitSpec = SqlLimitSpec.Create(
                    SqlParameter.Create(
                        context.PARAMETER().GetText()));
            }
            else
            {
                throw new NotImplementedException();
            }

            return(sqlLimitSpec);
        }
Beispiel #2
0
        public override SqlObject VisitTop_spec(sqlParser.Top_specContext context)
        {
            Contract.Requires(context != null);

            Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL());

            return(SqlTopSpec.Create(SqlNumberLiteral.Create(topCount)));
        }
        public override SqlObject VisitStringPathExpression([NotNull] sqlParser.StringPathExpressionContext context)
        {
            Contract.Requires(context != null);

            SqlPathExpression pathExpression = (SqlPathExpression)this.Visit(context.path_expression());
            SqlStringLiteral  stringIndex    = SqlStringLiteral.Create(CstToAstVisitor.GetStringValueFromNode(context.STRING_LITERAL()));

            return(SqlStringPathExpression.Create(pathExpression, stringIndex));
        }
        public override SqlObject VisitNumberPathExpression([NotNull] sqlParser.NumberPathExpressionContext context)
        {
            Contract.Requires(context != null);

            SqlPathExpression pathExpression = (SqlPathExpression)this.Visit(context.path_expression());
            SqlNumberLiteral  number         = SqlNumberLiteral.Create(CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL()));

            return(SqlNumberPathExpression.Create(pathExpression, number));
        }
Beispiel #5
0
        public override SqlObject VisitLike_scalar_expression([NotNull] sqlParser.Like_scalar_expressionContext context)
        {
            Contract.Requires(context != null);

            SqlScalarExpression expression  = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[0]);
            SqlScalarExpression pattern     = (SqlScalarExpression)this.Visit(context.binary_scalar_expression()[1]);
            bool             not            = context.K_NOT() != null;
            SqlStringLiteral escapeSequence = (context.escape_expression() != null)
                                                ? SqlStringLiteral.Create(CstToAstVisitor.GetStringValueFromNode(context.escape_expression().STRING_LITERAL()))
                                                : null;

            return(SqlLikeScalarExpression.Create(expression, pattern, not, escapeSequence));
        }
        public override SqlObject VisitObject_property([NotNull] sqlParser.Object_propertyContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.STRING_LITERAL() != null);
            Contract.Requires(context.scalar_expression() != null);

            string name = CstToAstVisitor.GetStringValueFromNode(context.STRING_LITERAL());
            SqlScalarExpression value = (SqlScalarExpression)this.Visit(context.scalar_expression());

            SqlObjectProperty property = SqlObjectProperty.Create(
                SqlPropertyName.Create(name),
                value);

            return(property);
        }
Beispiel #7
0
        public override SqlObject VisitOffset_limit_clause(sqlParser.Offset_limit_clauseContext context)
        {
            Contract.Requires(context != null);

            SqlOffsetSpec sqlOffsetSpec = SqlOffsetSpec.Create(
                SqlNumberLiteral.Create(
                    CstToAstVisitor.GetNumber64ValueFromNode(
                        context.offset_count().NUMERIC_LITERAL())));

            SqlLimitSpec sqlLimitSpec = SqlLimitSpec.Create(
                SqlNumberLiteral.Create(
                    CstToAstVisitor.GetNumber64ValueFromNode(
                        context.limit_count().NUMERIC_LITERAL())));

            return(SqlOffsetLimitClause.Create(sqlOffsetSpec, sqlLimitSpec));
        }
Beispiel #8
0
        public override SqlObject VisitLiteralScalarExpression(sqlParser.LiteralScalarExpressionContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.ChildCount == 1);
            Contract.Requires(context.children[0].ChildCount == 1);

            TerminalNodeImpl terminalNode = (TerminalNodeImpl)context.children[0].GetChild(0);

            SqlLiteralScalarExpression sqlLiteralScalarExpression;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(value));
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(number64));
                break;

            case sqlParser.K_TRUE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(true));
                break;

            case sqlParser.K_FALSE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(false));
                break;

            case sqlParser.K_NULL:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNullLiteral.Create());
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteralScalarExpression);
        }
        public override SqlObject VisitLiteral([NotNull] sqlParser.LiteralContext context)
        {
            TerminalNodeImpl terminalNode = (TerminalNodeImpl)context.children[0];

            SqlLiteral sqlLiteral;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteral = SqlStringLiteral.Create(value);
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteral = SqlNumberLiteral.Create(number64);
                break;

            case sqlParser.K_TRUE:
                sqlLiteral = SqlBooleanLiteral.Create(true);
                break;

            case sqlParser.K_FALSE:
                sqlLiteral = SqlBooleanLiteral.Create(false);
                break;

            case sqlParser.K_NULL:
                sqlLiteral = SqlNullLiteral.Create();
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteral = SqlUndefinedLiteral.Create();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteral);
        }
        public override SqlObject VisitTop_spec([NotNull] sqlParser.Top_specContext context)
        {
            Contract.Requires(context != null);

            SqlTopSpec sqlTopSpec;

            if (context.NUMERIC_LITERAL() != null)
            {
                Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL());
                sqlTopSpec = SqlTopSpec.Create(SqlNumberLiteral.Create(topCount));
            }
            else if (context.PARAMETER() != null)
            {
                sqlTopSpec = SqlTopSpec.Create(SqlParameter.Create(context.PARAMETER().GetText()));
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(sqlTopSpec);
        }
Beispiel #11
0
        public override SqlObject VisitObjectCreateScalarExpression(sqlParser.ObjectCreateScalarExpressionContext context)
        {
            Contract.Requires(context != null);
            // '{' object_propertty_list? '}'

            List <SqlObjectProperty> properties = new List <SqlObjectProperty>();

            if (context.object_propertty_list() != null)
            {
                sqlParser.Object_propertyContext[] propertyContexts = context.object_propertty_list().object_property();
                foreach (sqlParser.Object_propertyContext objectPropertyContext in propertyContexts)
                {
                    string name = CstToAstVisitor.GetStringValueFromNode(objectPropertyContext.STRING_LITERAL());
                    SqlScalarExpression value = (SqlScalarExpression)this.Visit(objectPropertyContext.scalar_expression());

                    SqlObjectProperty property = SqlObjectProperty.Create(
                        SqlPropertyName.Create(name),
                        value);
                    properties.Add(property);
                }
            }

            return(SqlObjectCreateScalarExpression.Create(properties));
        }