How not to do transaction processing
-
Yet another disastrous example from the VB6 project I'm porting. In many ways this one is truly eye-popping... (Note, the code is paraphrased to avoid spilling "secrets" (like anyone would steal this carp)).
Dim con As ADODB.Connection
Sub DoSomething()
...
con.BeginTrans
...
On Error GoTo MyRollback... Various statements that insert records ... con.CommitTrans ... Exit Sub
MyRollback:
MsgBox Err.Description con.RollbackTrans Resume Next ' WTF!!!!
End Sub
So, if an error is detected, the current transaction is aborted but the code then attempts to write the remaining inserts anyway - only not outside of a transaction. Of course it all goes pear-shaped when the Commit is attempted, but by that stage a whole bunch of detritus will have accumulated in the database. And as there are pretty well no relationships in this DB, there's nothing preventing those records being utterly invalid (and they will be). I predict a monumental data cleanup task approaching!
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
Yet another disastrous example from the VB6 project I'm porting. In many ways this one is truly eye-popping... (Note, the code is paraphrased to avoid spilling "secrets" (like anyone would steal this carp)).
Dim con As ADODB.Connection
Sub DoSomething()
...
con.BeginTrans
...
On Error GoTo MyRollback... Various statements that insert records ... con.CommitTrans ... Exit Sub
MyRollback:
MsgBox Err.Description con.RollbackTrans Resume Next ' WTF!!!!
End Sub
So, if an error is detected, the current transaction is aborted but the code then attempts to write the remaining inserts anyway - only not outside of a transaction. Of course it all goes pear-shaped when the Commit is attempted, but by that stage a whole bunch of detritus will have accumulated in the database. And as there are pretty well no relationships in this DB, there's nothing preventing those records being utterly invalid (and they will be). I predict a monumental data cleanup task approaching!
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Whoah - are we working on the same system? :omg: (I saw a bit of code that detects is a record exists by attempting to insert it and trapping the error - of course, it traps any SQL error so if the record doesn't exist but you haven't passed in the mandatory fields we just assume it does...)
-
Yet another disastrous example from the VB6 project I'm porting. In many ways this one is truly eye-popping... (Note, the code is paraphrased to avoid spilling "secrets" (like anyone would steal this carp)).
Dim con As ADODB.Connection
Sub DoSomething()
...
con.BeginTrans
...
On Error GoTo MyRollback... Various statements that insert records ... con.CommitTrans ... Exit Sub
MyRollback:
MsgBox Err.Description con.RollbackTrans Resume Next ' WTF!!!!
End Sub
So, if an error is detected, the current transaction is aborted but the code then attempts to write the remaining inserts anyway - only not outside of a transaction. Of course it all goes pear-shaped when the Commit is attempted, but by that stage a whole bunch of detritus will have accumulated in the database. And as there are pretty well no relationships in this DB, there's nothing preventing those records being utterly invalid (and they will be). I predict a monumental data cleanup task approaching!
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
Yet another disastrous example from the VB6 project I'm porting. In many ways this one is truly eye-popping... (Note, the code is paraphrased to avoid spilling "secrets" (like anyone would steal this carp)).
Dim con As ADODB.Connection
Sub DoSomething()
...
con.BeginTrans
...
On Error GoTo MyRollback... Various statements that insert records ... con.CommitTrans ... Exit Sub
MyRollback:
MsgBox Err.Description con.RollbackTrans Resume Next ' WTF!!!!
End Sub
So, if an error is detected, the current transaction is aborted but the code then attempts to write the remaining inserts anyway - only not outside of a transaction. Of course it all goes pear-shaped when the Commit is attempted, but by that stage a whole bunch of detritus will have accumulated in the database. And as there are pretty well no relationships in this DB, there's nothing preventing those records being utterly invalid (and they will be). I predict a monumental data cleanup task approaching!
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
Whoah - are we working on the same system? :omg: (I saw a bit of code that detects is a record exists by attempting to insert it and trapping the error - of course, it traps any SQL error so if the record doesn't exist but you haven't passed in the mandatory fields we just assume it does...)
That sounds like the same culprits. I wonder if there's a "special" team of programmers who travel the world sabotaging projects.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
:omg: How do you even know enough to know you should use transactions and not realise that this code is a massive WTF?
I know. Your emotion may be even worse if you got to see some of the code I've substituted with ... It's a shame I cannot use the old Asterix code: @%*%£&$!!!
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
That sounds like the same culprits. I wonder if there's a "special" team of programmers who travel the world sabotaging projects.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Guild of Master Underground Programmers (GUMP) They're actually part of small group (paid for by a hidden tax in you pay) that goes out to deliberately code to make large amounts of guaranteed employment for other coders. [Applications for membership have been outsource]
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010