Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. How not to do transaction processing

How not to do transaction processing

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasehelptutorialcareer
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    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.

    D C B 3 Replies Last reply
    0
    • R Rob Grainger

      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.

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      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...)

      R 1 Reply Last reply
      0
      • R Rob Grainger

        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.

        C Offline
        C Offline
        clawton
        wrote on last edited by
        #3

        And its always good to keep that transaction locked while waiting for the user to dismiss the message box. :)

        1 Reply Last reply
        0
        • R Rob Grainger

          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.

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          :omg: How do you even know enough to know you should use transactions and not realise that this code is a massive WTF?

          R 1 Reply Last reply
          0
          • D Duncan Edwards Jones

            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...)

            R Offline
            R Offline
            Rob Grainger
            wrote on last edited by
            #5

            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.

            W 1 Reply Last reply
            0
            • B BobJanova

              :omg: How do you even know enough to know you should use transactions and not realise that this code is a massive WTF?

              R Offline
              R Offline
              Rob Grainger
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • R Rob Grainger

                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.

                W Offline
                W Offline
                W Balboos GHB
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups