德尔福FireDaC语言 覆盖更新后获得自动递增的值



我将FireDac与Oracle 12c数据库和Delphi Seattle一起使用。

我有一张桌子 员工

EmployeeID - NUMBER GENERATED ALWAYS AS IDENTITY
HireDate - Date

在我的表格上,我有一个带有以下语句的 FDQuery:

select * from Employee

在FDQuery1.Insert和 FDQuery1.Post 之后,我可以使用以下代码获取生成的EmployeeID:

  FDQuery1.Insert;
  ...
  FDQuery1.Post;
  ShowMessage(IntToStr(FDQuery1.FieldByName('EMPLOYEEID').AsInteger));

这工作得很好。

问题:

我现在想覆盖FDQuery发布更新,如下所述:http://docwiki.embarcadero.com/RADStudio/XE8/en/Overriding_Posting_Updates_%28FireDAC%29

所以我覆盖了发布更新:

procedure TForm3.FDQuery1UpdateRecord(ASender: TDataSet;
  ARequest: TFDUpdateRequest; var AAction: TFDErrorAction;
  AOptions: TFDUpdateRowOptions);
begin
  FDUpdateSQL1.ConnectionName := FDQuery1.ConnectionName;
  FDUpdateSQL1.DataSet := FDQuery1;
  FDUpdateSQL1.Apply(ARequest, AAction, AOptions);
  AAction := eaApplied;
end;

但现在 EMPLOYEEID 显示为 -1 :(

  ShowMessage(IntToStr(FDQuery1.FieldByName('EMPLOYEEID').AsInteger));

我在FDUpdateSQL1.InsertSQL中输入什么语句并不重要。我什至可以将其留空。结果总是相同的。

(这也是在 https://forums.embarcadero.com/thread.jspa?messageID=778896&#778896 上问的)

作者:Dmitry Arefiev,来自Embarcadero论坛:

尝试使用插入...将员工 ID 返回到 :NEW_EmployeeID in你的FDUpdateSQL1.InsertSQL.您还需要设置:NEW_EmployeeID参数如下:

with FDUpdateSQL1.Commands[arInsert].ParamByName('NEW_EmployeeID') do begin
  ParamType := ptOutput;
  DataType := ftInteger;
end;

最新更新