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

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias +# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias # Schmidt module Lhm module SqlHelper extend self @@ -18,32 +18,14 @@ column_definition(cols).map do |name, length| "`#{ name }`#{ length }" end.join(', ') end - def table?(table_name) - connection.table_exists?(table_name) - end - - def sql(statements) - [statements].flatten.each do |statement| - connection.execute(tagged(statement)) - end - 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 => e - error e.message - end - def version_string - connection.select_one("show variables like 'version'")["Value"] + row = connection.select_one("show variables like 'version'") + value = struct_key(row, "Value") + row[value] end private def tagged(statement) @@ -78,8 +60,18 @@ case minor when 0 then return false if tiny and tiny < 11 end end return true + end + + def struct_key(struct, key) + keys = if struct.is_a? Hash + struct.keys + else + struct.members + end + + keys.find {|k| k.to_s.downcase == key.to_s.downcase } end end end