0

I am doing test with Delphi DataSnap REST application. I have tried this tutorial from Embarcadero and it works for simple table and one join SQL query.

// simple table sample

V001.SQL.Text := 'Select * from T001 where K010=:XK010';

// one join query

V001.SQL.Text := 
    'SELECT T001.K001 AS K001, T001.K010 AS K010, '
+ 'T001.F001 AS F001, T010.F001 AS F002 '

+ 'T001.F001 AS F001, T010.F001 AS F002 '

+ 'FROM T001 LEFT JOIN T010 ON T001.K010 = T010.K010 '

+ 'WHERE T001.K010=:XK010 '

+ 'ORDER BY T001.F001';

Now I start to try this sample with two joins query and get error at ApplyUpdates procedure.

// two joins query
V001.SQL.Text :=
'SELECT T001.K001 AS K001, T010.F002 AS T010F002, '
+ 'T016.F002 AS T016F002, '
+ 'T001.F001 AS F001, T001.K010 AS K010, T001.K016 AS K016 '
+ 'FROM ((T001 LEFT JOIN T010 ON T001.K010 = T010.K010) '
+ '     LEFT JOIN T016 ON T001.K016 = T016.K016) '
+ 'WHERE T001.K010=:XK010 '
+ 'ORDER BY T001.F001';


procedure TServerMethods1.ApplyChangesSupplierProduct(const ADeltaList: TFDJSONDeltas);
var
LApply: IFDJSONDeltasApplyUpdates;
sText: String;
begin
// Create the apply object
LApply := TFDJSONDeltasApplyUpdates.Create(ADeltaList);
// Apply the supplier delta
LApply.ApplyUpdates(myJoinQuery, V001.Command);
if LApply.Errors.Count > 0 then
    // Raise an exception if any errors.
raise Exception.Create(LApply.Errors.Strings.Text);
end;

As my SQL example with two joins shown above, error happens at the line of LApply.ApplyUpdates(myJoinQuery, V001.Command).

Please anyone show me some advice about how to get this work or if I need to prepare V001.Command by myself and how.

Thanks in advance.

abpatil
  • 916
  • 16
  • 20
James
  • 71
  • 1
  • 8
  • What error are you getting? – John Easley Sep 23 '17 at 19:15
  • Let me get this error. – James Sep 27 '17 at 06:36
  • Thanks for your help, John. Error message is: [FireDAC][Phys]-330. Cannot generate update query. Update table undefined. – James Sep 27 '17 at 06:47
  • See this question https://stackoverflow.com/questions/24497288/anydac-aka-firedac-cannot-generate-update-query It seems it's caused by using Alias fields, but there's an answer.. use CnPack to set the aliased fields to the real field names.. – John Easley Sep 27 '17 at 14:02
  • Thanks John. I will study this case and find if I can solve my problem. – James Sep 28 '17 at 12:28
  • Problem solved. Just add one line before ApplyUpdates: V001.UpdateOptions.UpdateTableName := 'T001'; This solution is referred to https://stackoverflow.com/questions/31163136/applyupdates-on-rest-with-firedac. Thanks for Cesar Romero's answer in that topic. – James Sep 28 '17 at 13:17

0 Answers0