lib/lhm/sql_helper.rb in lhm-1.0.3 vs lib/lhm/sql_helper.rb in lhm-1.1.0

- old
+ new

@@ -26,30 +26,60 @@ def sql(statements) [statements].flatten.each do |statement| connection.execute(tagged(statement)) end - rescue ActiveRecord::StatementInvalid, Mysql::Error => e + rescue ActiveRecord::StatementInvalid => e error e.message end def update(statements) [statements].flatten.inject(0) do |memo, statement| memo += connection.update(tagged(statement)) end - rescue ActiveRecord::StatementInvalid, Mysql::Error => e + rescue ActiveRecord::StatementInvalid => e error e.message end + def version_string + connection.select_one("show variables like 'version'")["Value"] + end + private def tagged(statement) "#{ statement } #{ SqlHelper.annotation }" end def column_definition(cols) Array(cols).map do |column| column.to_s.match(/`?([^\(]+)`?(\([^\)]+\))?/).captures end + end + + # Older versions of MySQL contain an atomic rename bug affecting bin + # log order. Affected versions extracted from bug report: + # + # http://bugs.mysql.com/bug.php?id=39675 + # + # More Info: http://dev.mysql.com/doc/refman/5.5/en/metadata-locking.html + def supports_atomic_switch? + major, minor, tiny = version_string.split('.').map(&:to_i) + + case major + when 4 then return false if minor and minor < 2 + when 5 + case minor + when 0 then return false if tiny and tiny < 52 + when 1 then return false + when 4 then return false if tiny and tiny < 4 + when 5 then return false if tiny and tiny < 3 + end + when 6 + case minor + when 0 then return false if tiny and tiny < 11 + end + end + return true end end end