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

ArgumentOutOfRangeException when there is a string literal immediately after SELECT keyword #132

Open
svartak-cl opened this issue Jun 13, 2024 · 1 comment
Assignees
Labels

Comments

@svartak-cl
Copy link

Hello,

TSQLStatementReader.ParseStatements throws ArgumentOutOfRangeException exception when there is a string literal immediately after SELECT keyword like SELECT' '+item

Error Details:
ArgumentOutOfRangeException -> Non-negative number required. Parameter name: count

   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.GetRange(Int32 index, Int32 count)
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.ParseNext(ITSQLTokenizer tokenizer)
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.Parse(ITSQLTokenizer tokenizer)
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.ParseNext(ITSQLTokenizer tokenizer)
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.Parse(ITSQLTokenizer tokenizer)
   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)
   at Demo.ParseQuery(String query)

For example, the below lines of code (containing valid TSQL statement) throw this exception

string query = "SELECT STUFF((SELECT' '+item FROM pqr), 2, 3, 'ijklmn') FROM abc";
var statements = TSQLStatementReader.ParseStatements(query, useQuotedIdentifiers: true, includeWhitespace: false);

Please let me know what you think about this exception for valid TSQL statement.

Best regards

@bruce-dunwiddie
Copy link
Owner

Thank you for reporting this issue. I'll take a look.

@bruce-dunwiddie bruce-dunwiddie self-assigned this Jun 13, 2024
@bruce-dunwiddie bruce-dunwiddie added under review Attempting to verify and confirm bug bug and removed under review Attempting to verify and confirm bug labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants