Sql150ScriptGenerator.GenerateScript ignores WHERE statement
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start with the reproduction using TSql150Parser, QuerySpecification, and Sql150ScriptGenerator.GenerateScript in the issue body. Compare the parsed QuerySpecification with the generated output, then run the example and confirm that the WHERE clause is preserved in the formatted SQL.
Written by the indexing model from the issue text.
Description
I try to format my sql script using GenerateScript method but WHERE clause is missing from its output.
Nuget version Microsoft.SqlServer.TransactSql.ScriptDom 161.9109.0.
Under debug I see parsed WHERE statement.
input and output:
ORIGINAL:
SELECT
x2_0.KeyPowerPlantUnit
,x3_0.KeyEnergyPlantTypeParent
,x2_0.KeyEnergyPlantType
,x2_0.MostRecentSequence
FROM SNLEdit_new.dbo.PowerPlantUnitFuel x2_0
LEFT JOIN Lookup.dbo.EnergyPlantType x3_0
ON x2_0.KeyEnergyPlantType = x3_0.KeyEnergyPlantType
AND x3_0.updoperation < 2
WHERE x2_0.MostRecentSequence IN (1, 2, 3, 4, 5, 6);
FORMATTED:
SELECT x2_0.KeyPowerPlantUnit,
x3_0.KeyEnergyPlantTypeParent,
x2_0.KeyEnergyPlantType,
x2_0.MostRecentSequence
FROM SNLEdit_new.dbo.PowerPlantUnitFuel AS x2_0
LEFT OUTER JOIN
Lookup.dbo.EnergyPlantType AS x3_0
ON x2_0.KeyEnergyPlantType = x3_0.KeyEnergyPlantType
AND x3_0.updoperation < 2
Code to reproduce:
using Microsoft.SqlServer.TransactSql.ScriptDom;
using System.Diagnostics;
var sql = @"
SELECT
x2_0.KeyPowerPlantUnit
,x3_0.KeyEnergyPlantTypeParent
,x2_0.KeyEnergyPlantType
,x2_0.MostRecentSequence
FROM SNLEdit_new.dbo.PowerPlantUnitFuel x2_0
LEFT JOIN Lookup.dbo.EnergyPlantType x3_0
ON x2_0.KeyEnergyPlantType = x3_0.KeyEnergyPlantType
AND x3_0.updoperation < 2
WHERE x2_0.MostRecentSequence IN (1, 2, 3, 4, 5, 6);
";
Console.WriteLine("ORIGINAL:" + sql);
var reader = new StringReader(sql);
var parser = new TSql150Parser(true);
var fragment = (TSqlScript)parser.Parse(reader, out var errors);
if (errors.Count > 0)
{
Console.WriteLine("Failed to parse SQL script:");
foreach (var error in errors)
{
Console.WriteLine(error.Message);
}
Debugger.Break();
}
var options = new SqlScriptGeneratorOptions
{
IncludeSemicolons = true,
IndentationSize = 4
};
var generator = new Sql150ScriptGenerator(options);
var statement = (SelectStatement)fragment.Batches[0].Statements[0];
var expression = (QuerySpecification)statement.QueryExpression;
generator.GenerateScript(expression, out var formattedSql);
Console.WriteLine();
Console.WriteLine("FORMATTED:" + Environment.NewLine + formattedSql);
Console.ReadLine();
- Dominant language
- GAP
- Stars
- 277
- Forks
- 43
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/SqlScriptDOM
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/SqlScriptDOM#228 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/SqlScriptDOM#183 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 56/100
microsoft/SqlScriptDOM#226 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
microsoft/SqlScriptDOM#225 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
microsoft/SqlScriptDOM#224 ·
All issues in microsoft/SqlScriptDOM
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
splunk/token-meter#56 ·
-
Doc: Oppdater README Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100