DataSnap应用UniDac处理惩罚自增长字段

    添加时间:2013-7-18 点击量:

    本来应用ado来接见数据库,用在DataSnap中也很便利。后来便一向应用UniDac,可发明UniDac若是用在DataSnap中要比ado麻烦很多,尤其对自增长字段、缺省值的处理惩罚上,感触感染对DataSnap支撑不好(通俗C/S应用还是很是好的)。


    在Unidac官网上看到一个关于处理惩罚DataSnap中的AutoInc字段题目,记录鄙人面,我没有验证。


    I use DataSnap delphi 2010.


    UniQuery Component DMLRefresh Can fetch autoinc value,


    but I cannot use it with datasnap.


    I use Follow Code.


    procedure TForm.dspDataAfterUpdateRecord(Sender: TObject; SourceDS: TDataSet; DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind); begin if UpdateKind = ukInsert then quData.Fields[0].NewValue := GetLastID; end;


    GetLastID function is fetch autoinc value.


    the code works grate with DBExpress. But not UniDac.



    Answer:



    To solve this problem, its needed to set the following options:
    Code: Select all
    TDataSetProvider.ResolveToDataSet := True;
    TUniQuery.RequiredFields := False;
    TUniQuery.SetFieldsReadOnly := False;In this case UniDAC will generate the SQL code, and the identity field value will be set automatically to the TUniQuery component. To the identity field value in the TClientDataSet, component its needed to use the following code:
    Code: Select all
    procedure TForm1.DataSetProvider1AfterUpdateRecord(Sender: TObject; SourceDS: TDataSet; DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind);
    begin
      if UpdateKind = ukInsert then
        DeltaDS.Fields[0].NewValue := UniQuery1.Fields[0].AsInteger;
    end;


    原来,再大的房子,再大的床,没有相爱的人陪伴,都只是冰冷的物质。而如果身边有爱人陪伴,即使房子小,床小,也觉得无关紧要,因为这些物质上面有了爱的温度,成了家的元素。—— 何珞《婚房》#书摘#
    分享到: