Page 1 of 1

DataSnap + UniDac + AutoInc

Posted: Wed 23 Mar 2011 13:48
by wbjsoft
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.

Posted: Wed 23 Mar 2011 15:48
by AlexP
Hello,

Please specify the following information:
- the exact version of UniDAC;
- the name of your database.
Also please send a complete small sample to alexp*devart*com to demonstrate the problem.

Posted: Wed 23 Mar 2011 18:26
by wbjsoft
I sent you sample program.

It works SQLite well.

But not work SQL Server.

I use unidac to build multi DB - SQLite,MySQL,SQL Server,Oracle.Etc.

Check the sample program and please answer me ASAP.

Thank you.

Posted: Thu 24 Mar 2011 11:20
by AndreyZ
We have answered you by e-mail.

Posted: Fri 25 Mar 2011 01:33
by TinTin
AndreyZ wrote:We have answered you by e-mail.
May I know the answer?

Posted: Fri 25 Mar 2011 09:45
by AndreyZ
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;