TylerBrinks / SqlParser-cs

A Friendly SQL Parser for .NET
MIT License
108 stars 19 forks source link

Error parsing insert statement #5

Closed lamg closed 11 months ago

lamg commented 11 months ago

Steps to reproduce

INSERT INTO table0(col0)
VALUES ('value0'),
       ('value1'),
       ('value2'),
       ('value3'),
       ('value4'),
       ('value5'),
       ('value6'),
       ('value7');

Result

SqlParser.ParserException: Recursion limit exceeded.

SqlParser.ParserException
Recursion limit exceeded.
   at SqlParser.DepthGuard.Decrease() in ~/src/SqlParser-cs/src/SqlParser/DepthGuard.cs:line 21
   at SqlParser.Parser.ParseExpr() in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 410
   at SqlParser.Parser.ParseCommaSeparated[T](Func`1 action) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 2117
   at SqlParser.Parser.<>c__DisplayClass184_0.<ParseValues>b__0() in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 6613
   at SqlParser.Parser.ParseCommaSeparated[T](Func`1 action) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 2117
   at SqlParser.Parser.ParseValues(Boolean allowEmpty) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 6598
   at SqlParser.Parser.ParseQueryBody(Int32 precedence) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 5229
   at SqlParser.Parser.ParseQuery(Boolean rewind) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 5058
   at SqlParser.Parser.ParseInsert() in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 6188
   at SqlParser.Parser.ParseKeywordStatement(Word word) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 203
   at SqlParser.Parser.ParseStatement() in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 175
   at SqlParser.Parser.ParseStatements() in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 150
   at SqlParser.Parser.ParseSql(ReadOnlySpan`1 sql, Dialect dialect, ParserOptions options) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 83
   at SqlParser.Parser.ParseSql(ReadOnlySpan`1 sql, ParserOptions options) in ~/src/SqlParser-cs/src/SqlParser/Parser.cs:line 54
   at SqlParser.Tests.ParserRegressionTests.Test_Query_Files(String sql) in ~/src/SqlParser-cs/src/SqlParser.Tests/ParserRegressionTests.cs:line 42
   at InvokeStub_ParserRegressionTests.Test_Query_Files(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
TylerBrinks commented 11 months ago

@lamg Your repro steps aren't clear. Your links point to a file and test that pass in the current unit test suite.

lamg commented 11 months ago

Sorry, forgot to include the actual insert statement. It's fixed now.

TylerBrinks commented 11 months ago

This was a fantastic catch. My implementation didn't re-increment the recursion guard when the expression scope exited where the Rust version did. The fix has been pushed and a new nuget package deployed to nuget.org.