TSqlParser.Core/SqlScriptAnalyzer.cs
/// <summary>
/// Analyzes the SQL text asynchronously.
/// </summary>
/// <param name="inputScript">The input script.</param>
/// <returns></returns>
Analyzes the SQL text asynchronously.
Analyzes the SQL text asynchronously .
public async Task<ParserResults> AnalyzeSqlTextAsync(string inputScript)
        {
            ParserResults results = new ParserResults();
            _sqlParser = CreateSqlParser();
            Sql120ScriptGenerator _scriptGen;
            SqlScriptGeneratorOptions options = new SqlScriptGeneratorOptions();
            options.SqlVersion = _sqlVersion;
            options.KeywordCasing = KeywordCasing.Uppercase;
            _scriptGen = new Sql120ScriptGenerator(options);
            TSqlFragment fragment;
            IList<ParseError> errors;
            using (StringReader sr = new StringReader(inputScript))
            {
                fragment = _sqlParser.Parse(sr, out errors);
            }
            if (errors.Count > 0)
            {
                results.ParsingExceptionDetail = string.Join(",", errors.Select(x => x.Message));
            }
            else
            {
                TSqlScript sqlScript = fragment as TSqlScript;
                if (sqlScript != null)
                {
                    foreach (TSqlBatch batch in sqlScript.Batches)
                    {
                        foreach (TSqlStatement statement in batch.Statements)
                        {
                            AnalyzeTsqlStatement(results, statement);
                        }
                    }
                }
            }
            return await Task.FromResult(results);
        }
public async Task < ParserResults > AnalyzeSqlTextAsync ( string inputScript ) { ParserResults results = new ParserResults ( ) ; _sqlParser = CreateSqlParser ( ) ; Sql120ScriptGenerator _scriptGen ; SqlScriptGeneratorOptions options = new SqlScriptGeneratorOptions ( ) ; options . SqlVersion = _sqlVersion ; options . KeywordCasing = KeywordCasing . Uppercase ; _scriptGen = new Sql120ScriptGenerator ( options ) ; TSqlFragment fragment ; IList < ParseError > errors ; using ( StringReader sr = new StringReader ( inputScript ) ) { fragment = _sqlParser . Parse ( sr , out errors ) ; } if ( errors . Count > 0 ) { results . ParsingExceptionDetail = string . Join ( " " , errors . Select ( x => x . Message ) ) ; } else { TSqlScript sqlScript = fragment as TSqlScript ; if ( sqlScript != null ) { foreach ( TSqlBatch batch in sqlScript . Batches ) { foreach ( TSqlStatement statement in batch . Statements ) { AnalyzeTsqlStatement ( results , statement ) ; } } } } return await Task . FromResult ( results ) ; }
Analyzes the SQL text asynchronously.
Analyzes the SQL text asynchronously .
None
inputScript
string
The input script.
The input script .