Returning information recorded in the bank

Asked

Viewed 50 times

1

I have a system that is installed on an unstable network, my doubt 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 don’t think so, because if in the second Post, I lose the connection to the bank the rollback will also not work?

3 answers

5


Yes you will, you have to be in a transaction for that, of course. Even if you cannot execute the rollback, the commit will also not be executed and is only in commit that the 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 exceeded, so it will discard everything itself.

That is the principle of Atomicity that must exist in the database mechanisms: https://technet.microsoft.com/pt-br/library/ms190612%28v=sql.105%29.aspx? f=255&Mspperror=-2147217396

2

You must start a transaction

Considering

dbConacted - the name of the connection component to the database Query1 and query 2 - query with sql statements.

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

  dbConexao.commit;
except
  dbconexao.rollback;
end;

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

0

It’s been a while since I’ve programmed in Delhi, but I think it would look something like this:

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

try:
   commit
except
   Implmentação

Browser other questions tagged

You are not signed in. Login or sign up in order to post.