예제 #1
0
        public IExpression Parse(TextSpan token, IParser parser)
        {
            var parametersList = new List <SqlCodeExpr>();

            parser.Scanner.Consume(SqlToken.LParen);

            var dataType = parser.ConsumeDataType();

            parametersList.Add(dataType);

            parser.Scanner.Consume(SqlToken.Comma);

            var expr = parser.ParseExpIgnoreComment();

            parametersList.Add(expr);

            if (parser.Scanner.Match(SqlToken.Comma))
            {
                var styleSpan = parser.Scanner.Consume();
                var style     = parser.PrefixParse(styleSpan) as SqlCodeExpr;
                parametersList.Add(style);
            }

            parser.Scanner.Consume(SqlToken.RParen);
            var funcName = new ObjectIdSqlCodeExpr
            {
                ObjectName = "CONVERT"
            };

            return(new FuncSqlCodeExpr
            {
                Name = funcName,
                Parameters = parametersList
            });
        }
예제 #2
0
        public IExpression Parse(TextSpan token, IParser parser)
        {
            parser.Scanner.Consume(SqlToken.LParen);

            var expr = parser.ParseExp() as SqlCodeExpr;

            parser.Scanner.Consume(SqlToken.As);

            var datetype = parser.ConsumeDataType();

            parser.Scanner.Consume(SqlToken.RParen);

            var asExpr = new AsSqlCodeExpr
            {
                Left  = expr,
                Right = datetype,
            };

            var parameters = new List <SqlCodeExpr>();

            parameters.Add(asExpr);

            return(new FuncSqlCodeExpr
            {
                Name = new ObjectIdSqlCodeExpr
                {
                    ObjectName = "CAST"
                },
                Parameters = parameters
            });
        }
예제 #3
0
        private IExpression CreateFunction(TextSpan token, IParser parser)
        {
            var nameExpr = parser.ConsumeObjectId();

            parser.Scanner.Consume(SqlToken.LParen);
            var arguments = parser.ConsumeArgumentList();

            parser.Scanner.Consume(SqlToken.RParen);

            parser.Scanner.Consume(SqlToken.Returns);

            parser.Scanner.TryConsumeVariable(out var returnVariableExpr);


            var returnTypeExpr = parser.ConsumeDataType();

            parser.Scanner.Consume(SqlToken.As);

            var body = parser.ConsumeBeginBody();

            return(new CreateFunctionSqlCodeExpr
            {
                Name = nameExpr,
                Arguments = arguments,
                ReturnVariable = returnVariableExpr,
                ReturnType = returnTypeExpr,
                Body = body
            });
        }
예제 #4
0
        private IExpression CreatePartitionFunction(TextSpan token, IParser parser)
        {
            if (parser.Scanner.IsToken(SqlToken.Scheme))
            {
                return(CreatePartitionScheme(token, parser));
            }

            parser.Scanner.Consume(SqlToken.Function);

            var name = parser.ConsumeObjectId();

            parser.Scanner.Consume(SqlToken.LParen);
            var dataType = parser.ConsumeDataType();

            parser.Scanner.Consume(SqlToken.RParen);

            parser.Scanner.Consume(SqlToken.As);
            parser.Scanner.Consume(SqlToken.Range);

            var rangeType = string.Empty;

            if (parser.Scanner.TryConsumeAny(out var rangeTypeSpan, SqlToken.Left, SqlToken.Right))
            {
                rangeType = parser.Scanner.GetSpanString(rangeTypeSpan);
            }

            parser.Scanner.Consume(SqlToken.FOR);
            parser.Scanner.Consume(SqlToken.Values);

            var boundaryValueList = new List <SqlCodeExpr>();

            parser.Scanner.Consume(SqlToken.LParen);
            do
            {
                var boundaryValue = parser.ParseExpIgnoreComment();
                boundaryValueList.Add(boundaryValue);
            } while (parser.Scanner.Match(SqlToken.Comma));

            parser.Scanner.Consume(SqlToken.RParen);

            return(new CreatePartitionFunctionSqlCodeExpr
            {
                Name = name,
                DataType = dataType,
                RangeType = rangeType,
                BoundaryValueList = boundaryValueList,
            });
        }
예제 #5
0
        public IExpression Parse(TextSpan token, IParser parser)
        {
            var variableList = new List <SqlCodeExpr>();

            do
            {
                var varName = parser.ParseExpIgnoreComment(int.MaxValue);

                parser.Scanner.Match(SqlToken.As);

                SqlCodeExpr dataTypeExpr = ParseCursorFor(parser);
                if (dataTypeExpr == null)
                {
                    dataTypeExpr = parser.ConsumeDataType();
                }

                SqlCodeExpr variableDataType = new DeclareSqlCodeExpr
                {
                    Name     = varName as SqlCodeExpr,
                    DataType = dataTypeExpr,
                };

                if (parser.Scanner.Match(SqlToken.Equal))
                {
                    var valueExpr = parser.ParseExpIgnoreComment();
                    variableDataType = new AssignSqlCodeExpr
                    {
                        Left  = variableDataType,
                        Oper  = "=",
                        Right = valueExpr
                    };
                }

                variableList.Add(variableDataType);
            } while (parser.Scanner.Match(SqlToken.Comma));

            return(new ExprListSqlCodeExpr
            {
                IsComma = false,
                Items = variableList
            });
        }
예제 #6
0
        private ExprListSqlCodeExpr ParseColumnDataTypeList(IParser parser)
        {
            var startIndex = parser.Scanner.GetOffset();

            if (!parser.TryConsumeObjectId(out _))
            {
                return(null);
            }

            var dataType = parser.ConsumeTokenString().ToUpper();

            if (!IsDataTypeToken(dataType))
            {
                parser.Scanner.SetOffset(startIndex);
                return(null);
            }

            parser.Scanner.SetOffset(startIndex);
            var columnList = new List <SqlCodeExpr>();

            do
            {
                var field        = parser.ConsumeObjectId();
                var dataTypeExpr = parser.ConsumeDataType();
                columnList.Add(
                    new ColumnDataTypeSqlCodeExpr
                {
                    Name     = field,
                    DataType = dataTypeExpr
                });
            } while (parser.MatchToken(SqlToken.Comma));

            return(new ExprListSqlCodeExpr
            {
                Items = columnList
            });
        }