Skip to content

Commit

Permalink
fixed a transactions issue
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmoe committed Sep 5, 2008
1 parent 62e9317 commit 8f75dff
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/never_block/db/pooled_fibered_mysql_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@ def initialize(size=4, &block)
end
end

# A proxy for the connection's exec method
# A proxy for the connection's query method
# quries the pool to get a connection first
def exec(query)
def query(query)
@pool.hold do |conn|
conn.query(query)
end
end

alias :query :exec
# This method must be called for transactions to work correctly.
# One cannot just send "begin" as you never know which connection
# will be available next. This method ensures you get the same connection
# while in a transaction.
def begin_db_transaction
@pool.hold(true) do |conn|
conn.exec("begin")
conn.query("begin")
end
end

# see =begin_db_transaction
def rollback_db_transaction
@pool.hold do |conn|
conn.exec("rollback")
conn.query("rollback")
@pool.release(Fiber.current,conn)
end
end

# see =begin_db_transaction
def commit_db_transaction
@pool.hold do |conn|
conn.exec("commit")
conn.query("commit")
@pool.release(Fiber.current,conn)
end
end
Expand Down

0 comments on commit 8f75dff

Please sign in to comment.