1

需要根据通过组件接口进入文件的数据来更新/插入和删除现有表中的数据。虽然我写了下面的代码但没有信心,如果有其他方法可以执行相同的操作,请告诉我。代码 -

&Osession = %session
&Ocipersonaldata = &osession.getcompintfc.(compintfc.ci_prsonal_data);
&Ocipersonaldata.interactivemode = true;
&Ocipersonaldata.gethistoryitems= false;
&Ocipersonaldata.edithistoryitems= false;

&Ocipersonaldata.keypropemplid= d_persnid_aet.emplid
&Opersnidcollection = Ocipersonaldata.coll_pers_nid;
&Found =false;

For &I = 1 to Opersnidcollection.count
  &Opersnid = Opersnidcollection.item(&I);

  If Opersnid.country= d_persnid_aet.country and &opersnid.nationalid_type =d_persnid_aet.nationalid_type then
    If d_persnid_aet.actn = 'delete'
      Sqlexec(delete from ps_persnid where emplid =:1 and country =:2 and nationalid_type =:3",d_persnid_aet.emplud,d_persnid_aet.country,d_persnid_aet.nationalid_type);
    Else 
      If d_persnid_aet.actn = 'insert' then
        &Pernid = &persnidcollection.item (persnidcollection.count);
        &Pernid.nationalid= d_persnid_aet.nationalid;
      Else
        &Persnid =persnidcollection.insertitem(persnidcollection.count);
        &Pernid.nationalid= d_persnid_aet.nationalid;
        &Pernid.country= d_persnid_aet.country;
        &Pernid.nationalid_type d_persnid_aet.nationalid_type
      End-if;
4

2 回答 2

1

组件接口 (CI) 的目的是确保您遵守业务逻辑。

我在您的代码中看到一条 SQL 删除语句,这可能违背了使用 CI 的目的。由于 PeopleSoft 与数据库无关,因此它没有利用内置数据库功能,例如外键和级联删除。相反,维护引用完整性的逻辑是在应用层实现的(即通过 PeopleCode、SQR 代码、COBOL 代码、应用引擎 SQL 等)。

如果您真的想要执行 SQL 更新/插入/删除操作(不鼓励这样做),那么您将承担以下研究负担:

  • 识别需要相应修改的外键和其他表,以及
  • 编写 sql 来修改所有其他表中的数据。

出于这个原因,最好使用组件接口来进行删除(例如,使用InsertItemorDeleteitem方法)。这取决于您使用的底层组件定义,因为并非所有组件都允许删除。

于 2021-11-21T02:56:14.363 回答
1

唯一主观上“更好”的方法是使用不使用 CI 的现有实体框架构造。CI 的加载和运行成本确实很高,因此如果可用,EF 选项会更快

始终使用 CI 或实体服务来更改业务数据。通过编写 SQL,您将立即对可能挂在该表上的所有下游更改负责。

除了@qyb2zm302 的好答案之外,当您直接操作数据时,从长远来看,您会帮自己一个忙,使用 PeopleCode API 来执行此操作。

Local Record &rPersnId;
&rPersnId= GetRecord(Record.PERSNID);
&rPersnId.EMPLID.Value = d_persnid_aet.emplid;
&rPersnId.COUNTRY.Value = d_persnid_aet.country;
&rPersnId.NATIONALID_TYPE.Value = d_persnid_aet.nationalid_type;
If &rPersnId.SelectByKey() then
   &ret = &rPersnId.Delete();
End-If;

这样做的原因有很多,即:

  1. 关心数据库模式;
  2. 帮助调试
  3. 搜索和引用记录很有帮助
  4. 从您的代码中删除“魔术”字符串
  5. 您不必制作/测试/调试 SQL 字符串。
  6. 您可以判断 SelectByKey 是否成功,以及 Delete 是否成功。用户反馈等中的更多选项。
  7. 除非您一次进行数百万次删除,否则开销不应该是可怕的,那么我会质疑更大的方法......
于 2021-12-03T17:38:27.047 回答