I need more information about locks and transactions.
I migrate my projects to PostgreSQL.
For example I have to tables: TM=master and TD=detail.
Here is a pseudo-code for modify data:
Code: Select all
SQL_Query.Execute; //Opens data set as Select * from TM
<here I chose a record to modify>
UQ_To_X_rec(SQL_Query, X_rec); <and store it into record variable>
try
try
SQL_Query.Lock;
SQL_Query_D.Execute; //Opens data set as Select * from TD
// where TD.Link=TM.Link
<detail data are stored in dynamic array>
<here on the form I change the Master and/or Detail data
stored in the record variable and the array for details>
if OK_1 then begin // if user click OK button on the form to accept changes
SQL_Query.Edit;
X_rec_To_UQ(SQL_Query, X_rec); <make changes in locked record in TM>
<here there are updates for details in TD table (SQL_Query_D) = OK_2>
if OK_2 // if update of details went OK
then SQL_Query.Post // for commit changes
else SQL_Query.Cancel; // for rollback changes
end;
finally
SQL_Query.UnLock;
end;
except
SQL_Query.Cancel;
MsgBox('Error .....',mfOK);
end;
1. Does SQL_Query.Lock make a global transaction for all changes till the Unlock command?
2. Is the update of details made under transaction ?
3. Will the SQL_Query.Cancel rollback all changes in TM and TD ?
4. If point 2=false, how to implement transaction for all changes and lock a record in TM?
5. In my old project I do these steps (Betrieve/Pervasive API):
Code: Select all
if <lock record in Master table to prevent it for edition by other users>
then begin
<read the record to record variable>
<Read detail data into an array>
<Modify data in memory>
if <user accepts changes>
then begin
<Begin Transaction>
if <update master record> and <update detail data>
then <End Transaction = Commit all changes>
else <Abort Transaction = cancel all changes>
end;
end
else begin
MsgBox('Record is Locked by other user');
end;
Regards
Michal