예제 #1
0
        private SqlCodeExpr AlterStoreProcedure(TextSpan storeProcedureSpan, IParser parser)
        {
            var createExpr = (CreateProcedureSqlCodeExpr)parser.ConsumeCreateProcedure(storeProcedureSpan);

            return(new AlterProcedureSqlCodeExpr
            {
                Name = createExpr.Name,
                Arguments = createExpr.Arguments,
                Body = createExpr.Body,
                Comments = createExpr.Comments,
                WithExecuteAs = createExpr.WithExecuteAs
            });
        }
예제 #2
0
        public IExpression Parse(TextSpan token, IParser parser)
        {
            if (parser.IsToken(SqlToken.USER))
            {
                return(ParseCreateUser(parser));
            }

            if (parser.IsToken(SqlToken.ROLE))
            {
                return(ParseCreateRole(parser));
            }

            if (parser.IsToken(SqlToken.LOGIN))
            {
                return(ParseCreateLogin(parser));
            }

            if (parser.TryConsumeToken(out var viewSpan, SqlToken.VIEW))
            {
                return(ParseCreateView(viewSpan, parser));
            }

            if (parser.TryConsumeToken(out var typeSpan, SqlToken.TYPE))
            {
                return(ParseCreateType(typeSpan, parser));
            }

            if (parser.TryConsumeTokenList(out var spanList, SqlToken.UNIQUE, SqlToken.NONCLUSTERED))
            {
                var createNonClusteredIndexExpr = CreateNonClusteredIndex(spanList[1], parser);
                createNonClusteredIndexExpr.IsUnique = true;
                return(createNonClusteredIndexExpr);
            }

            if (parser.TryConsumeToken(out var nonclusteredSpan, SqlToken.NONCLUSTERED))
            {
                return(CreateNonClusteredIndex(nonclusteredSpan, parser));
            }

            if (parser.TryConsumeToken(out var synonymSpan, SqlToken.SYNONYM))
            {
                return(CreateSynonym(synonymSpan, parser));
            }

            if (parser.Scanner.TryConsume(SqlToken.CLUSTERED, out var clusteredSpan))
            {
                return(CreateClusteredIndex(clusteredSpan, parser));
            }

            if (parser.Scanner.TryConsume(SqlToken.Index, out var indexSpan))
            {
                return(CreateIndex(indexSpan, parser));
            }

            if (parser.TryConsumeTokenList(out var uniqueSpan, SqlToken.UNIQUE, SqlToken.Index))
            {
                var createIndexExpr = CreateIndex(uniqueSpan[1], parser);
                return(new CreateUniqueIndexSqlCodeExpr
                {
                    IndexName = createIndexExpr.IndexName,
                    TableName = createIndexExpr.TableName,
                    OnColumns = createIndexExpr.OnColumns,
                    Comments = createIndexExpr.Comments
                });
            }

            if (parser.Scanner.TryConsume(SqlToken.TABLE, out var tableSpan))
            {
                return(parser.CreateTable(tableSpan));
            }

            if (parser.Scanner.Match(SqlToken.Procedure))
            {
                return(parser.ConsumeCreateProcedure(token));
            }

            if (parser.Scanner.Match(SqlToken.Function))
            {
                return(CreateFunction(token, parser));
            }

            if (parser.Scanner.Match(SqlToken.Partition))
            {
                return(CreatePartitionFunction(token, parser));
            }

            if (parser.IsToken(SqlToken.TRIGGER))
            {
                return(ConsumeCreateTrigger(parser));
            }

            var helpMessage = parser.Scanner.GetHelpMessage();

            throw new ParseException($"Parse CREATE Error, {helpMessage}");
        }