Esempio n. 1
0
        internal void AnalyzeTSQLContentString(string tsqlContent, CompilerContext context)
        {
            List <TSQLToken>         tokensWithComments = TSQLTokenizer.ParseTokens(tsqlContent);
            ReadOnlySpan <TSQLToken> tokens             = FormatTokenList(tokensWithComments);

            int fileIndex = 0;

            while (fileIndex < tokens.Length)
            {
                IDataManipulationResolver manipulationResolver;
                DataManipulation          manipulation;

                switch (tokens[fileIndex].Text.ToLower())
                {
                case "use":
                    new UseStatementResolver().ResolveUseStatement(tokens, ref fileIndex, context);
                    break;

                //case "declare":
                //    new VariableDeclarationResolver().Resolve(tokens, ref fileIndex, context);
                //    break;
                //case "set":
                //    gic.AssignVariableValue(tokens, ref fileIndex);
                //    break;
                case "with":
                    var withResolver = new WithStatementResolver();
                    withResolver.Resolve(tokens, ref fileIndex, context);
                    break;

                case "merge":
                    manipulationResolver = new MergeStatementResolver();
                    manipulation         = manipulationResolver.Resolve(tokens, ref fileIndex, context);
                    context.DataManipulations.Add(manipulation);
                    context.DropCommonTableExpressions();
                    break;

                case "bulk":
                    var bulkStatementResolver = new BulkInsertStatementResolver();
                    bulkStatementResolver.Resolve(tokens, ref fileIndex, context);
                    break;

                case "insert":
                    manipulationResolver = new InsertStatementResolver();
                    manipulation         = manipulationResolver.Resolve(tokens, ref fileIndex, context);
                    context.DataManipulations.Add(manipulation);
                    context.DropCommonTableExpressions();
                    break;

                case "update":
                    manipulationResolver = new UpdateStatementResolver();
                    manipulation         = manipulationResolver.Resolve(tokens, ref fileIndex, context);
                    context.DataManipulations.Add(manipulation);
                    context.DropCommonTableExpressions();
                    break;

                case "select":
                    SelectStatementResolver selectResolver = new SelectStatementResolver();
                    SelectStatement         statement      = selectResolver.ResolveTopLevel(tokens, ref fileIndex, context);
                    if (statement.TargetObject == null)
                    {
                        if (context.ConsiderQueries)
                        {
                            context.DataQueries.Add(statement.Expression);
                        }
                    }
                    else
                    {
                        context.AddSelectWithIntoClause(statement);
                    }

                    context.DropCommonTableExpressions();
                    break;

                //case "drop":
                //    gic.ResolveDropStatement(tokens, ref fileIndex, causer);
                //    break;
                case "create":
                    new CreateStatementResolver().Resolve(tokens, ref fileIndex, context);
                    break;

                //case "exec":*
                //case "execute": throw new NotImplementedException("Execute statements are no supported yet");
                default:
                    fileIndex++;
                    break;
                }
            }

            result.DataQueries       = context.DataQueries;
            result.DataManipulations = context.DataManipulations;
        }