Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Sql150ScriptGenerator.GenerateScript ignores WHERE statement

オープン
#79 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, sql
領域
databases

調査の方向性

issue本文にある TSql150Parser、QuerySpecification、Sql150ScriptGenerator.GenerateScript を使った再現から始めます。解析された QuerySpecification と生成された出力を比較し、その後で例を実行して、フォーマットされた SQL に WHERE 句が保持されていることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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();
主要言語
GAP
スター
277
フォーク
43
平均マージ
6日 17時間
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/SqlScriptDOM のほかの issue

microsoft/SqlScriptDOM の issue をすべて見る

似ている issue

Databases の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。