Returning information saved to the bank

1

I have a system that is installed on an unstable network, my question is the following, if at some point in my recording I lose the connection to the database, how do I undo what was done in the database ? If I put:

try
 ....
 query1.post;
 query2.post;
 commit;
except
 rollback;

Would that work? I think not, because if in the second Post, I lose the connection to the database, the rollback will not work either?

    
asked by anonymous 29.06.2017 / 19:33

3 answers

5

Yes you will, you have to be in a transaction for this, of course. Even if you can not execute rollback , commit will not run, and it is only in commit that information is saved. Since the connection was interrupted without informing the bank, it will probably hold the connection and the transaction until the timeout is over, so it will discard everything.

This is the principle of Atomicity that should exist in the database engines: link

    
29.06.2017 / 19:42
2

You must initiate a transaction

Considering

dbConnection - the name of the connection component to the bank query1 and query 2 - query with instructions in sql.

dbConexao.starttransaction;
Try
  Query1.execsql;
  Query2.execsql;

  dbConexao.commit;
except
  dbconexao.rollback;
end;

There can be variation of the commands if it is dbexpress, firedac or other. But this is the correct sequence of commands.

    
30.06.2017 / 05:21
0

I have not been programming in Delhi for some time, but I think it would look something like this:

qry1.post
qry2.post
...
qryN.post

try:
   commit
except
   Implmentação
    
29.06.2017 / 19:43