| View previous topic :: View next topic |
| Author |
Message |
Jed Nicolau Filho Guest
|
Posted: Fri Dec 10, 2004 8:41 pm Post subject: Verify Transaction |
|
|
Hello Dear Friends
Is it a good pratice to verify SQLConnection.InTransaction before Commit
and before RollBack with DBExpress ?
Or It is not necessary ?
************************
If Not SQLConnection.InTransaction then
Begin
TD.TransactionID := 1;
TD.IsolationLevel := xilREADCOMMITTED;
SQLConnection.StartTransaction(TD);
Try
Close;
SQL.Clear;
SQL.Add( SQLStatement );
ExecSql;
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Commit(TD); {on success, commit the changes}
Except
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Rollback(TD); {on failure, undo the changes}
End;
************************
Thanks in advance
Best Regards
Jed
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Fri Dec 10, 2004 9:41 pm Post subject: Re: Verify Transaction |
|
|
Jed Nicolau Filho wrote:
| Quote: |
Is it a good pratice to verify SQLConnection.InTransaction before
Commit and before RollBack with DBExpress ?
Or It is not necessary ?
************************
SQLConnection.StartTransaction(TD);
Try
Close;
SQL.Clear;
SQL.Add( SQLStatement );
ExecSql;
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Commit(TD); {on success, commit the changes}
Except
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Rollback(TD); {on failure, undo the changes}
End;
|
That should not be necessary. The transaction is under your control and will
not change arbitraily. Even if the call to ExecSQL were to raise an
exception (e.g. a bad SQL statement), the transaction would not be affected.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"Democracy, without the guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman
|
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Fri Dec 10, 2004 9:48 pm Post subject: Re: Verify Transaction |
|
|
The disadvantage of testing the InTransaction property is that you
probably want to know if you are not in a transaction when you should
be.
--
Bill Todd (TeamB)
TeamB cannot answer questions received via email
|
|
| Back to top |
|
 |
Jed Nicolau Filho Guest
|
Posted: Sat Dec 11, 2004 12:16 am Post subject: Re: Verify Transaction |
|
|
Thanks Wayne and Bill
Ok. That's it.
Best Regards
Jed
"Jed Nicolau Filho" <jed (AT) prouser (DOT) com.br> escreveu na mensagem
news:41ba0961 (AT) newsgroups (DOT) borland.com...
| Quote: | Hello Dear Friends
Is it a good pratice to verify SQLConnection.InTransaction before Commit
and before RollBack with DBExpress ?
Or It is not necessary ?
************************
If Not SQLConnection.InTransaction then
Begin
TD.TransactionID := 1;
TD.IsolationLevel := xilREADCOMMITTED;
SQLConnection.StartTransaction(TD);
Try
Close;
SQL.Clear;
SQL.Add( SQLStatement );
ExecSql;
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Commit(TD); {on success, commit the
changes}
Except
If SQLConnection.InTransaction then
//<-------------------------THIS
SQLConnection.Rollback(TD); {on failure, undo the
changes}
End;
************************
Thanks in advance
Best Regards
Jed
|
|
|
| Back to top |
|
 |
|