Method: WIKK::SQL#transaction

Defined in:
lib/wikk_sql.rb

#transaction {|[]| ... } ⇒ Object

Perform a transaction in the passed block. RollBACK on error, otherwise COMMIT

Yield Parameters:

  • []

    yields to block, where the queries are performed.

Raises:

  • (Mysql)

    passes on Mysql errors, freeing the result.



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/wikk_sql.rb', line 92

def transaction
  puts "transaction"
  if block_given?
    begin
      @my.query("START TRANSACTION WITH CONSISTENT SNAPSHOT")
      yield #Start executing the query black.
      @my.query("COMMIT")
    rescue Mysql::Error => e
      @my.query("ROLLBACK")
      raise e
    end
  end
end