Example #1
0
        public TSQLInsertStatement Parse()
        {
            TSQLInsertClause insertClause = new TSQLInsertClauseParser().Parse(Tokenizer);

            Statement.Insert = insertClause;

            Statement.Tokens.AddRange(insertClause.Tokens);

            if (Tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.OUTPUT))
            {
                TSQLOutputClause outputClause = new TSQLOutputClauseParser().Parse(Tokenizer);

                Statement.Output = outputClause;

                Statement.Tokens.AddRange(outputClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.VALUES))
            {
                TSQLValuesExpression values = new TSQLValuesExpressionParser().Parse(Tokenizer);

                Statement.Values = values;

                Statement.Tokens.AddRange(values.Tokens);
            }
            else if (Tokenizer.Current.IsKeyword(TSQLKeywords.SELECT))
            {
                TSQLSelectStatement select = new TSQLSelectStatementParser(Tokenizer).Parse();

                Statement.Select = select;

                Statement.Tokens.AddRange(select.Tokens);
            }
            else if (Tokenizer.Current.IsKeyword(TSQLKeywords.DEFAULT))
            {
                TSQLDefaultValuesExpression defaultValues = new TSQLDefaultValuesExpressionParser().Parse(Tokenizer);

                Statement.Default = defaultValues;

                Statement.Tokens.AddRange(defaultValues.Tokens);
            }
            else if (Tokenizer.Current.IsKeyword(TSQLKeywords.EXECUTE))
            {
                TSQLExecuteStatement exec = new TSQLExecuteStatementParser(Tokenizer).Parse();

                Statement.Execute = exec;

                Statement.Tokens.AddRange(exec.Tokens);
            }

            if (
                Tokenizer.Current?.AsKeyword != null &&
                Tokenizer.Current.AsKeyword.Keyword.IsStatementStart())
            {
                Tokenizer.Putback();
            }

            return(Statement);
        }
        public TSQLUpdateStatement Parse()
        {
            TSQLUpdateClause updateClause = new TSQLUpdateClauseParser().Parse(Tokenizer);

            Statement.Update = updateClause;

            Statement.Tokens.AddRange(updateClause.Tokens);

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.SET))
            {
                TSQLSetClause setClause = new TSQLSetClauseParser().Parse(Tokenizer);

                Statement.Set = setClause;

                Statement.Tokens.AddRange(setClause.Tokens);
            }

            if (Tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.OUTPUT))
            {
                TSQLOutputClause outputClause = new TSQLOutputClauseParser().Parse(Tokenizer);

                Statement.Output = outputClause;

                Statement.Tokens.AddRange(outputClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.FROM))
            {
                TSQLFromClause fromClause = new TSQLFromClauseParser().Parse(Tokenizer);

                Statement.From = fromClause;

                Statement.Tokens.AddRange(fromClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.WHERE))
            {
                TSQLWhereClause whereClause = new TSQLWhereClauseParser().Parse(Tokenizer);

                Statement.Where = whereClause;

                Statement.Tokens.AddRange(whereClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.OPTION))
            {
                TSQLOptionClause optionClause = new TSQLOptionClauseParser().Parse(Tokenizer);

                Statement.Option = optionClause;

                Statement.Tokens.AddRange(optionClause.Tokens);
            }

            return(Statement);
        }
        public TSQLDeleteStatement Parse()
        {
            TSQLDeleteClause deleteClause = new TSQLDeleteClauseParser().Parse(Tokenizer);

            Statement.Delete = deleteClause;

            Statement.Tokens.AddRange(deleteClause.Tokens);

            if (Tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.OUTPUT))
            {
                TSQLOutputClause outputClause = new TSQLOutputClauseParser().Parse(Tokenizer);

                Statement.Output = outputClause;

                Statement.Tokens.AddRange(outputClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.FROM))
            {
                TSQLFromClause fromClause = new TSQLFromClauseParser().Parse(Tokenizer);

                Statement.From = fromClause;

                Statement.Tokens.AddRange(fromClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.WHERE))
            {
                TSQLWhereClause whereClause = new TSQLWhereClauseParser().Parse(Tokenizer);

                Statement.Where = whereClause;

                Statement.Tokens.AddRange(whereClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.OPTION))
            {
                TSQLOptionClause optionClause = new TSQLOptionClauseParser().Parse(Tokenizer);

                Statement.Option = optionClause;

                Statement.Tokens.AddRange(optionClause.Tokens);
            }

            if (
                Tokenizer.Current?.AsKeyword != null &&
                Tokenizer.Current.AsKeyword.Keyword.IsStatementStart())
            {
                Tokenizer.Putback();
            }

            return(Statement);
        }
Example #4
0
        public TSQLMergeStatement Parse()
        {
            TSQLMergeClause mergeClause = new TSQLMergeClauseParser().Parse(Tokenizer);

            Statement.Merge = mergeClause;

            Statement.Tokens.AddRange(mergeClause.Tokens);

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.INTO))
            {
                TSQLIntoClause intoClause = new TSQLMergeIntoClauseParser().Parse(Tokenizer);

                Statement.Into = intoClause;

                Statement.Tokens.AddRange(intoClause.Tokens);
            }

            if (Tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.USING))
            {
                TSQLUsingClause usingClause = new TSQLUsingClauseParser().Parse(Tokenizer);

                Statement.Using = usingClause;

                Statement.Tokens.AddRange(usingClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.ON))
            {
                TSQLOnClause onClause = new TSQLOnClauseParser().Parse(Tokenizer);

                Statement.On = onClause;

                Statement.Tokens.AddRange(onClause.Tokens);
            }

            while (Tokenizer.Current.IsKeyword(TSQLKeywords.WHEN))
            {
                TSQLWhenClause whenClause = new TSQLWhenClauseParser().Parse(Tokenizer);

                Statement.When.Add(whenClause);

                Statement.Tokens.AddRange(whenClause.Tokens);
            }

            if (Tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.OUTPUT))
            {
                TSQLOutputClause outputClause = new TSQLOutputClauseParser().Parse(Tokenizer);

                Statement.Output = outputClause;

                Statement.Tokens.AddRange(outputClause.Tokens);
            }

            if (Tokenizer.Current.IsKeyword(TSQLKeywords.OPTION))
            {
                TSQLOptionClause optionClause = new TSQLOptionClauseParser().Parse(Tokenizer);

                Statement.Option = optionClause;

                Statement.Tokens.AddRange(optionClause.Tokens);
            }

            return(Statement);
        }