【问题标题】:How exclude primary key field from FDbatchmove append?如何从 FDbatchmove 追加中排除主键字段?
【发布时间】:2022-06-21 17:32:49
【问题描述】:

当我想通过 FDbatchMove 组件将源表附加到目标表时,Delphi 会出现此异常: “[FireDac][Phys][SQLite] 错误:唯一约束失败:AG2.M_key。” AG2.M_Key 是我的表的主键。 如果我可以从 batchmove 中排除主键,也许可以解决问题。 我该怎么做?

【问题讨论】:

  • 看起来源表中的某些键与目标表中的键相同。在这种情况下,由于您使用的是唯一主键,因此不能简单地追加。此外,由于您需要一个主键,根据定义,您不能省略它。我认为,您需要决定如何处理重复键并重新定义您在做什么。

标签: database delphi


【解决方案1】:

通过这个 cod,我可以从 FDbatchmove 追加中排除“m_key”字段:

var ind:integer;
begin
 FDBatchMove1.Mappings.Clear;
 FDBatchMove1.Mappings.AddAll;
 ind:=FDBatchMove1.Mappings.IndexOfName('m_key');
 if ind<>-1 then
  FDBatchMove1.Mappings.Delete(ind);
 FDBatchMove1.Execute;
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 2018-08-22
    • 1970-01-01
    • 2021-02-02
    相关资源
    最近更新 更多