Liste des Groupes | Revenir à cl python |
On 8/09/24 9:20 am, Karsten Hilbert wrote:try:>
do something
except:
log something
finally:
.commit()
>
cadence is fairly Pythonic and elegant in that it ensures the
the .commit() will always be reached regardless of exceptions
being thrown or not and them being handled or not.
That seems wrong to me. I would have thought the commit should only
be attempted if everything went right.
What if there's a problem in your code that causes a non-SQL-related
exception when some but not all of the SQL statements in the
transaction bave been [-- even successfully --] issued?
try:it doesn't technically matter whether I say .commit or .rollback here:
do something
.commit()
except:
log something
.rollback()
Doing an explicit rollback ensures that the transaction is always
rolled back if it is interrupted for any reason.
Les messages affichés proviennent d'usenet.