Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Reference Exception When Parsing Complicated FOR XML #125

Open
bruce-dunwiddie opened this issue Feb 7, 2023 Discussed in #124 · 0 comments
Open

Null Reference Exception When Parsing Complicated FOR XML #125

bruce-dunwiddie opened this issue Feb 7, 2023 Discussed in #124 · 0 comments
Assignees
Labels
under review Attempting to verify and confirm bug

Comments

@bruce-dunwiddie
Copy link
Owner

Discussed in #124

Originally posted by jim-gregorio February 7, 2023
Hello,

We are using tsql-parser as the foundation for SQL validation. When the following query is parsed it throws a null reference exception.

here is the call stack:

at TSQL.Expressions.Parsers.TSQLArgumentListParser.Parse(ITSQLTokenizer tokenizer)
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.ParseNext(ITSQLTokenizer tokenizer)
   at TSQL.Expressions.Parsers.TSQLSelectExpressionParser.Parse(ITSQLTokenizer tokenizer)
   at TSQL.Elements.Parsers.TSQLSelectColumnParser.Parse(ITSQLTokenizer tokenizer)
   at TSQL.Clauses.Parsers.TSQLSelectClauseParser.Parse(ITSQLTokenizer tokenizer)
   at TSQL.Statements.Parsers.TSQLSelectStatementParser.Parse()
   at TSQL.TSQLStatementReader.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

This can be reproduced using the following query:

select Stuff((Select ', ' + i.name from sysindexes i where i.id = sys.id order by i.name FOR XML PATH(''),TYPE).value('text()[1]','varchar(max)'),1,2,'') as 'indexes' from sysobjects sys where sys.name like 'DF%'

On SQL Server 2017 or later this can be rewritten to use the string_agg function instead of using for xml. However some servers are 2016 and cannot leverage this function.

Please let me know what you think this can and should be resolved.
Regards.

@bruce-dunwiddie bruce-dunwiddie added the under review Attempting to verify and confirm bug label Feb 7, 2023
@bruce-dunwiddie bruce-dunwiddie self-assigned this Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under review Attempting to verify and confirm bug
Projects
None yet
Development

No branches or pull requests

1 participant