microsoft / SqlScriptDOM

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

SqlScriptGenerator does not account for BinaryQueryExpressions #22

Open richardgavel opened 2 years ago

richardgavel commented 2 years ago

When I parse a query which has a UNION statement, I get a SelectStatement with a QueryExpression that is a BinaryQueryExpression. However, when I try to use the SqlScriptGenerator to regenerate the SQL from the object tree, it stops at the FirstExpression + BinaryQueryExpressionType.

eg. => SELECT x FROM FOO UNION SELECT x FROM BAR turns into SELECT x FROM FOO UNION

llali commented 2 years ago

@richardgavel can you please add more info? Are you using sqlpackage.exe or DacFx framework?

richardgavel commented 2 years ago

DacFx framework, This is basically the result of sql -> syntax tree -> sql

string sql = "...";
var parser = new TSql150Parser(true, SqlEngineType.All);
var tree = parser.Parse(new StringReader(sql), out _);

var generator = new Sql150ScriptGenerator();
generator.GenerateScript(tree, out string script);

sql: Has the second part of the union script: Missing the second part of the union.

arvindshmicrosoft commented 1 year ago

@richardgavel - this does not reproduce with current ScriptDom nuget 161.8812.0.

image

Could you please re-visit your repro and let us know if there is any other issue?