MergeActionClause object has wrong FirstTokenIndex value
还没有人认领这个 Issue。
评估
调研方向
首先重现提供的 MERGE 语句,并定位 MergeActionClause 的 token 索引在哪里被分配。比较前两个子句,然后添加一个回归测试,证明每个 MergeActionClause.FirstTokenIndex 都指向其 WHEN 关键字;当报告的值反映这些位置时,修复就完成了。
由索引模型根据 Issue 内容生成。
描述
ScriptDom version: 161.9142.1
Compatibility level: 150
After parsing a MERGE statement MergeActionClause instance has the same FirstTokenIndex as it's property - Action (for example, ValuesInsertSource instance); in case if there is a SearchCondition then the clause's FirstTokenIndex will equal to SearchCondition.FirstTokenIndex value. This seems to be inaccurate. MergeActionClause is the object containing Condition, SearchCondition and Action properties which makes me believe that the MergeActionClause instance is supposed to match the whole clause starting with WHEN keyword which occurs way earlier in a script than the merge action (or search condition).
Here is a sample script:
MERGE t WITH (HOLDLOCK) AS trg
USING (SELECT * FROM @src) AS src
ON trg.id = src.id
WHEN NOT MATCHED AND (1=1) THEN
INSERT (title)
VALUES (src.title)
WHEN NOT MATCHED BY SOURCE THEN
DELETE
WHEN MATCHED THEN
UPDATE SET
title = src.title,
lastmod = SYSDATETIME()
OUTPUT DELETED.title AS old_title, $action AS act
INTO @log(old_title, act);
for the first clause WHEN NOT MATCHED AND (1=1) THEN INSERT clause:
MergeActionClause.SearchCondition.FirstTokenIndex = 50
MergeActionClause.Action.FirstTokenIndex = 59
MergeActionClause.FirstTokenIndex = 50 (same as for SearchCondition)
for the second clause WHEN NOT MATCHED BY SOURCE THEN DELETE without SearchCondition:
MergeActionClause.Action.FirstTokenIndex = 87
MergeActionClause.FirstTokenIndex = 87 (same as for Action)
and this makes it hard to work with such clauses in code - the beginning of each WHEN has to be located manually by iterating tokens backwards.
MergeActionClause.FirstTokenIndex should always point to the WHEN keyword.
See also token-index related bug-reports: #90 , #91
- 主要语言
- 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 ·