提交 4c41be9b 编写于 作者: A Aaron Patterson

statement cache for deletes working on mysql

上级 453bd2f3
...@@ -490,6 +490,45 @@ def update_sql(sql, name = nil) #:nodoc: ...@@ -490,6 +490,45 @@ def update_sql(sql, name = nil) #:nodoc:
@connection.affected_rows @connection.affected_rows
end end
def exec_delete(sql, name, binds)
log(sql, name, binds) do
result = nil
cache = {}
if binds.empty?
stmt = @connection.prepare(sql)
else
cache = @statements[sql] ||= {
:stmt => @connection.prepare(sql)
}
stmt = cache[:stmt]
end
begin
stmt.execute(*binds.map { |col, val| type_cast(val, col) })
rescue Mysql::Error => e
# Older versions of MySQL leave the prepared statement in a bad
# place when an error occurs. To support older mysql versions, we
# need to close the statement and delete the statement from the
# cache.
stmt.close
@statements.delete sql
raise e
end
if metadata = stmt.result_metadata
metadata.free
end
result = stmt.affected_rows
stmt.free_result
stmt.close if binds.empty?
result
end
end
def begin_db_transaction #:nodoc: def begin_db_transaction #:nodoc:
exec_without_stmt "BEGIN" exec_without_stmt "BEGIN"
rescue Mysql::Error rescue Mysql::Error
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册