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

ScriptDom interprets ambiguously the next word right after transaction control statement

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
sql
領域
compilers

調査の方向性

まず、ScriptDom の互換性レベル 150 と 160 で BEGIN、SAVE、COMMIT、ROLLBACK の例を再現します。トランザクション名と、それに続く 1 語のステートメントがどのように分類されるかを確認し、THROW や CONTINUE などのケースで期待される動作を定義します。曖昧さが解消されるか、一貫して警告が提供されれば、issue は完了です。

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

説明

bug
  • ScriptDom Version: 161.8910.0
  • CompatibilityLevel used for parsing: 150, 160

Some keywords written right next to the transaction control statement are treated as transaction name and some as a separate command/next statement. This may lead to significant misunderstanding of what the code will actually do.

Statements:

  • BEGIN TRAN
  • SAVE TRAN
  • COMMIT TRAN
  • ROLLBACK TRAN

Examples of keywords/statements treated as valid identifier for transaction name:

  • THROW
  • RECEIVE
  • SEND

Steps to Reproduce:

If you write BEGIN TRAN THROW - here THROW will be treated as a valid transaction name. However in BEGIN TRAN CONTINUE the CONTINUE will be treated as a separate command. BEGIN/COMMIT/ROLLBACK behave similarly - they can take modern keywords/commands as a valid tran name but "ignore" "oldschool" keywords/commands and treat them as a separate statement even if no statement terminator is present between them. SAVE TRAN unlikely mentioned statements requires transaction name to be provided and if the next word is parsed as an invalid tran identifier candidate the parsing fails with syntax error.

Examples of ambiguity:

COMMIT TRAN CONTINUE
COMMIT TRAN BREAK
COMMIT TRAN THROW     -- tran name
COMMIT TRAN RECEIVE   -- tran name
COMMIT TRAN SEND      -- tran name
COMMIT TRAN RETURN
COMMIT TRAN COMMIT
COMMIT TRAN ROLLBACK

in all lines not marked with comment the last word is treated as a separate statement.
SAVE TRAN requires third word in statement and in all lines except marked with comment parser would say that syntax is broken:
image

The most ambiguous case to me is this one:

BEGIN TRY
    BEGIN TRAN

    SELECT 1 / 0

    COMMIT TRAN
END TRY
BEGIN CATCH
    ROLLBACK TRAN
    THROW -- "Divide by zero" error will not be rethrown here
          -- new error will be generated:
          -- Cannot roll back THROW. No transaction or savepoint of that name was found
END CATCH

On ROLLBACK TRAN docs page it is said that transaction name must be a valid identifier, identifier is valid if it does not match any of reserved words and THROW is not listed there. On THROW docs page it is said that preceding statement must end with semicolon. Thus ROLLBACK TRAN THROW in the example above behaves expectedly speaking of the docs. But it is an error so easy to make and you need so much to remember to avoid it while coding.

It would be great if

  • all one-word statements were included into reserved keywords (especially THROW); maybe in future compatibility levels
  • SSDT/DacFx would show at least a warning in such cases and recommend to put semicolon before THROW or choose another identifier for transaction name

As a workaround I'm developing another rule for our custom linter which would detect such suspicious cases.

(DacFx/SqlPackage/SSMS/Azure Data Studio)

主要言語
GAP
スター
277
フォーク
43
平均マージ
6日 17時間
マージ済み PR(30日)
3

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

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

はじめの一歩

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

microsoft/SqlScriptDOM のほかの issue

microsoft/SqlScriptDOM の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

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

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