Consider nested transactions .
Most RDBMS do not support nested transactions or try to mimic them in a very limited way.
For example, in MS SQL Server, rollback in an internal transaction (which is not a real transaction, MS SQL Server simply counts transaction levels!) Will roll back everything that happened in an outmost transaction (which is a real transaction).
Some database wrappers may consider rollback in an internal transaction as an indication that an error has occurred, and rollback of everything in the external transaction itself, regardless of whether the transaction was completed or the most recent transaction was completed.
Thus, COMMIT is a safe way when you cannot rule out that your component is being used by some software module.
Please note that this is a general answer to the question. The sample code skilfully works around a problem with an external transaction, opening up a new connection to the database.
Regarding performance: depending on isolation level, SELECTs may require varying degrees of LOCK and temporal data (snapshots). This is cleared when the transaction is closed. It doesn’t matter if this is done through COMMIT or ROLLBACK. There may be a slight difference in the processor time spent - COMMIT is probably faster to understand than ROLLBACK (two less characters) and other minor differences. Obviously, this is true only for read-only operations!
Not completely requested: another programmer who can read the code may suggest that ROLLBACK implies an error condition.
Klaws May 05 '17 at 14:04 2017-05-05 14:04
source share