ERP system documents, always some master-slave table structure, there is a main table, n sub-table, sub-table and child table, the formation of n-level, document data submitted, master and slave table data to be submitted, in order to ensure the integrity of the data, must provide transaction control, or all submitted successfully, there is a commit failure all the commits to rollback It may seem a bit difficult, but we have olevariant arrays that can be used, and it's easier to solve them. The code.
Service side:
function Tservermethods1.savedatas (tablenames, deltas:olevariant;
Tablecount:integer): Boolean;
Var
I, Errcnt:integer;
D:tfrmdb;
Begin
D: = Dbpool.lock;
Try
If not d.con.intransaction then
D.con.starttransaction; Open transaction
Try
For I: = 0 to TableCount-1 do
Begin
D.qry.close;
D.qry.sql.clear;
D.qry.sql.text: = ' select * from ' + tablenames[i] + ' where 1=2 ';
D.qry.open;
D.dsp.applyupdates (Deltas[i], 0, errcnt);
End
D.con.commit; Commit a transaction
Result: = True;
Except
D.con.rollback; Rolling back a transaction
Result: = False;
End
Finally
Dbpool.unlock (d);
End
End
Client:
Savedatas (vararrayof ([' Table1 ', ' table2 ']), vararrayof ([Clientdataset1.delta,clientdataset2.delta]), 2);
A general method for transaction control DATASNAP multiple table submissions