Renamed #values_sql_for_column_names_and_attributes to #values_sql_for_columns_and_attributes and cleaned up how it dealt with columns.

* added back in the support for type-casting based on the database column
* removed unused method in ActiveRecord::Import::AbstractAdapter

https://github.com/zdennis/activerecord-import/issues#issue/5
This commit is contained in:
Zach Dennis 2011-01-10 22:36:52 -05:00
parent 1a8082444b
commit 161cf017f9
2 changed files with 5 additions and 17 deletions

View file

@ -116,17 +116,6 @@ module ActiveRecord::Import::AbstractAdapter
post_sql_statements
end
# Returns SQL the VALUES for an INSERT statement given the passed in +columns+
# and +array_of_attributes+.
def values_sql_for_column_names_and_attributes( columns, array_of_attributes ) # :nodoc:
array_of_attributes.map do |arr|
my_values = arr.each_with_index.map do |val,j|
quote( columns[j].type_cast(val), columns[j] )
end
"(#{my_values.join(',')})"
end
end
# Returns the maximum number of bytes that the server will allow
# in a single packet
def max_allowed_packet

View file

@ -259,7 +259,7 @@ class ActiveRecord::Base
columns_sql = "(#{column_names.map{|name| connection.quote_column_name(name) }.join(',')})"
insert_sql = "INSERT #{options[:ignore] ? 'IGNORE ':''}INTO #{quoted_table_name} #{columns_sql} VALUES "
values_sql = values_sql_for_column_names_and_attributes(column_names, array_of_attributes)
values_sql = values_sql_for_columns_and_attributes(columns, array_of_attributes)
if not supports_import?
number_inserted = 0
values_sql.each do |values|
@ -282,15 +282,14 @@ class ActiveRecord::Base
# Returns SQL the VALUES for an INSERT statement given the passed in +columns+
# and +array_of_attributes+.
def values_sql_for_column_names_and_attributes(column_names, array_of_attributes) # :nodoc:
columns = column_names.map { |name| columns_hash[name.to_s] }
def values_sql_for_columns_and_attributes(columns, array_of_attributes) # :nodoc:
array_of_attributes.map do |arr|
my_values = arr.each_with_index.map do |val,j|
if !sequence_name.blank? && column_names[j] == primary_key && val.nil?
column = columns[j]
if !sequence_name.blank? && column.name == primary_key && val.nil?
connection.next_value_for_sequence(sequence_name)
else
connection.quote(val, columns[j])
connection.quote(column.type_cast(val), column)
end
end
"(#{my_values.join(',')})"