提交 fc343d26 编写于 作者: A Aaron Patterson

clearing statement from cache on exception in order to support older versions of mysql

上级 bf50222b
......@@ -413,9 +413,19 @@ def exec_query(sql, name = 'SQL', binds = [])
stmt = cache[:stmt]
end
stmt.execute(*binds.map { |col, val|
type_cast(val, col)
})
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
cols = cache[:cols] ||= metadata.fetch_fields.map { |field|
field.name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册