microsoft / SqlScriptDOM

ScriptDOM/SqlDOM is a .NET library for parsing T-SQL statements and interacting with its abstract syntax tree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ScriptDom.TSql160Parser fails to parse simple T-SQL expression

clement911 opened this issue · comments

  • Microsoft.SqlServer.DacFx Version 161.6374.0
  • Reproduced on both .NET 6.0 and .NET 7.0
  • Windows 11

The Microsoft.SqlServer.TransactSql.ScriptDom.TSql160Parser fails to parse the following expression.

We noticed the issue on a much more complicated and realistic expression but we simplified the repro to the following minimal expression.

Repro:

using Microsoft.SqlServer.TransactSql.ScriptDom;

var parser = new TSql160Parser(true); //sql server 2022 parser
IList<ParseError> errors;

var expr = @"
(
    SELECT 1
    WHERE (IIF(1 > 0 AND 2 > 1, 1, 0)) = 1
)";

var res = parser.ParseExpression(new StringReader(expr), out errors);

if (errors?.Count > 0)
    Console.WriteLine(errors.First().Message); //ERROR!!!!    Incorrect syntax near ).

To prove that the given expression is definitely a valid one, you can simply execute the following statement in SSMS and see that SQL SERVER executes the query succesfully.

SELECT
(
    SELECT 1
    WHERE (IIF(1 > 0 AND 2 > 1, 1, 0)) = 1
)

@llali Could this be addressed with the release of the sql server 2022 parser?

Hi @clement911, this expression worked
var expr = @"
(
SELECT 1
WHERE IIF(1 > 0 AND 2 > 1, 1, 0) = 1
)";

That's right. The parser gets confused by extra wrapping parentheses so hopefully the code fix is not too hard?

Of course we wouldn't write such a simple expression manually but our actual expression is much more complicated. Also, sql is sometimes autogenerated or provided by a user, in which case we have no control over it.

Could we please get an update on this bug?

@clement911 Apologies for the delay, would update you whether it would be included in the next release. Thank you

@SeenaAugusty we really look forward to it.

By the way, if you would open source the parser, we'd be happy to spend some time working on such issues

@clement911 we are planning to make it open source in near future :)

@SeenaAugusty this is great news that you will open source this project 😄

However, I was also told the same thing.... 2.5 years ago.

Could you share the (rough) time line of when you will be open sourcing this project?

Hi, any updates on this issue?

@SeenaAugusty any news on the open sourcing?
Bugs remain open for months or years so the only hope I see of them getting fixed is if you open source the code.

While the time it takes to bring ScriptDOM to open source may be frustrating, we'll keep those conversations primarily over at microsoft/DacFx#101

@dzsquared could you give a quick update there?
Are you still working towards open sourcing the ScriptDom?

Thank you to the team for open sourcing this wonderful library 😍

Any chance this bug could get looked at ?

@SeenaAugusty are you looking into this currently? If not, I can take a crack at this 😄

@chlafreniere sure, not yet though,