Hi again ... with regards to my FireDac / DataSnap / FireBird question from earlier, I've done some testing and found that the problem seems to be happening when the DataSnap server is applying the updates and that one is not sending back the new field values to the client.

Hi again ... with regards to my FireDac / DataSnap / FireBird question from earlier, I've done some testing and found that the problem seems to be happening when the DataSnap server is applying the updates and that one is not sending back the new field values to the client.

I did make a little sample project which shows 3 ways of working.

First one is a simple TFDQuery with Insert / Post. After every post the new values appear correctly in the DataSet.

Second one is a similar approach but this time we use Cached Updates on the TFDQuery. All records appear with a negative value for the ID field, but things get fixed when you ApplyUpdates. Once you do that ... all new records get their new values for the ID field automagically ...

Now the FireDac DataSnap way of working. Data is fetched into a TFDMemTable by calling a method on a Server Module. Updates are done in the TFDMemTable and applied back to the server using another method. In the database they appear correctly ... but my question is now ... is it possible to get the new values back to the client too?

Remember, I'm using the FireDAC / DataSnap approach, not the good old TClientDataSet / TDataSetProvider approach. I've been trying lots of things (RefreshRecord, playing with UpdateFlags, ...), but I have been unable to get this working. I'm really looking for a solution since this is now a blocking factor on the new project I'm working on.

If any of you want to see the sample / demo code, let me know and I'll have a look where I can upload that.

Comments

  1. The only way I can think of is writing an extra method on the client, that calls the generator. Then instead of the negative ID values, you put in the real ID straight away. You then also need to drop the AutoInc on the ID field on the table.

    ReplyDelete
  2. Hans Jakup Ellingsgaard I will try that ... the stupid thing is that on the DataSnap server, I think the TFDQuery does probably know the new values for the ID Fields, so I guess what I'm missing is just a way to bring those back down to the client.

    ReplyDelete
  3. Stefaan Lesage

    I often use a function like this to retrieve the generator ID:

    function TDataModule1.GetGenID (GeneratorName : string) : integer;
    begin
    with GenIBQuery do
    begin
    SQL.Clear;
    SQL.ADD('SELECT GEN_ID ('+GeneratorNavn+', 1) from rdb$database');
    Open;

    Result := Fields [0].AsInteger;

    if GenIBTransaction.Active then
    GenIBTransaction.commit;
    end;
    end;

    The example above is based on Interbase and an IBQuery.

    ReplyDelete

Post a Comment