ScriptDom interprets ambiguously the next word right after transaction control statement
还没有人认领这个 Issue。
评估
调研方向
首先使用 ScriptDom 兼容级别 150 和 160 重现 BEGIN、SAVE、COMMIT 和 ROLLBACK 示例。检查事务名称和后续单词语句的分类方式,然后定义 THROW 和 CONTINUE 等情况下的预期行为;当歧义得到解决或始终如一地提供警告时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
描述
- 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:
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
THROWor 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 小时
- 30 天内合并 PR
- 3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/SqlScriptDOM 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/SqlScriptDOM#228 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
microsoft/SqlScriptDOM#183 ·
-
难度 4/5 3-5 天 新手友好度 56/100
microsoft/SqlScriptDOM#226 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 48/100
microsoft/SqlScriptDOM#225 ·
-
难度 3/5 1-2 天 新手友好度 58/100
microsoft/SqlScriptDOM#224 ·
查看 microsoft/SqlScriptDOM 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100
oxc-project/oxc#26944 ·