module SerializationHelper
class Load
def self.load_records(table, column_names, records)
if column_names.nil?
return
end
columns = column_names.map{|cn| ActiveRecord::Base.connection.columns(table).detect{|c| c.name == cn}}
quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
quoted_table_name = SerializationHelper::Utils.quote_table(table)
(records || []).each do |record|
quoted_values = record.zip(columns).map{|c| ActiveRecord::Base.connection.quote(c.first, c.last)}.join(',')
ActiveRecord::Base.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
end
end
end
class Dump
def self.dump_table(io, table)
dump_table_columns(io, table)
dump_table_records(io, table)
end
end
end