Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

MergeActionClause object has wrong FirstTokenIndex value

未关闭
#118 0 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
sql

调研方向

首先重现提供的 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)

Image

for the second clause WHEN NOT MATCHED BY SOURCE THEN DELETE without SearchCondition:

MergeActionClause.Action.FirstTokenIndex = 87
MergeActionClause.FirstTokenIndex = 87 (same as for Action)

Image

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/SqlScriptDOM 的其他 Issue

查看 microsoft/SqlScriptDOM 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。