microsoft / SqlScriptDOM

ScriptDOM/SqlDOM is a .NET library for parsing T-SQL statements and interacting with its abstract syntax tree
MIT License
128 stars 13 forks source link

TSql160Parser fails to parse CREATE USER FROM EXTERNAL PROVIDER WITH OBJECT_ID #53

Closed holc-tkomp closed 9 months ago

holc-tkomp commented 11 months ago

Issue

Microsoft.SqlServer.TransactSql.ScriptDom.TSql160Parser fails to parse following sql:

CREATE USER xxxx FROM EXTERNAL PROVIDER WITH OBJECT_ID='xxx'

WITH OBJECT_ID syntax doesn't seem to be documented yet, however it's already available on (some?) Azure databases, see https://github.com/MicrosoftDocs/sql-docs/issues/7167.

Reproduction

Latest tested version of Microsoft.SqlServer.TransactSql.ScriptDom package: 161.8905.0

using Microsoft.SqlServer.TransactSql.ScriptDom;

var sql = "CREATE USER xxxx FROM EXTERNAL PROVIDER WITH OBJECT_ID='xxx'";
var parser = new TSql160Parser(true);
parser.Parse(new StringReader(sql), out var errors);

if (errors?.Count > 0)
    Console.WriteLine(errors[0].Message); // Expected PASSWORD but encountered OBJECT_ID instead.
ErikEJ commented 11 months ago

@holc-tkomp The syntax is neither released or supported.

holc-tkomp commented 11 months ago

Are you considering to add support for this in the future though? Or if we'd want to support this syntax in near future we would have to use a different parser?

arvindshmicrosoft commented 11 months ago

@holc-tkomp could you please help us by explaining your broader scenario? Are you trying to do this in the context of a DACPAC deployment as a post-deployment script, or such? Why is it necessary for you to specify the OID using this undocumented syntax?

holc-tkomp commented 11 months ago

The script is something used by one of our clients. Our tool (SSMS addin) allows formatting of script within SSMS query window and for that we use your parser, so we can analyze tokens/fragments to decide where to put newlines, semicolons, etc.