DataSnap UniDac self growth field

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

The original use of ADO to access the database, used in DataSnap is also very convenient. But it has been using UniDac, which can be found on UniDac if used in the DataSnap ADO than a lot of trouble, especially for self growth field, processing default values, feelings for DataSnap support is not good (common C/S application is very good).

See a processing in DataSnap AutoInc field in the Unidac website, documented below, I did not verify.

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, it's 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 update the identity field value in the TClientDataSet, component it's 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;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Jimmy at November 24, 2013 - 9:17 AM