activerecord-import 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,16 @@
2
2
 
3
3
  activerecord-import is a library for bulk inserting data using ActiveRecord.
4
4
 
5
+ ### Rails 3.1.x and higher
6
+
7
+ Use the latest activerecord-import.
8
+
9
+ ### Rails 3.0.x up to, but not including 3.1
10
+
11
+ Use activerecord-import 0.2.11. As of activerecord-import 0.3.0 we are relying on functionality that was introduced in Rails 3.1. Since Rails 3.0.x is no longer a supported version of Rails we have decided to drop support as well.
12
+
13
+ ### For More Information
14
+
5
15
  For more information on activerecord-import please see its wiki: https://github.com/zdennis/activerecord-import/wiki
6
16
 
7
17
  # License
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -8,7 +8,7 @@ module ActiveRecord::Import::AbstractAdapter
8
8
  arr, current_arr_values_size, current_size = [], 0, 0
9
9
  values.each_with_index do |val,i|
10
10
  comma_bytes = arr.size
11
- sql_size_thus_far = sql_size + current_size + val.size + comma_bytes
11
+ sql_size_thus_far = sql_size + current_size + val.bytesize + comma_bytes
12
12
  if NO_MAX_PACKET == max_bytes or sql_size_thus_far <= max_bytes
13
13
  current_size += val.bytesize
14
14
  arr << val
@@ -1,4 +1,18 @@
1
1
  module ActiveRecord::Import::SQLite3Adapter
2
+ include ActiveRecord::Import::ImportSupport
3
+
4
+ # Override our conformance to ActiveRecord::Import::ImportSupport interface
5
+ # to ensure that we only support import in supported version of SQLite.
6
+ # Which INSERT statements with multiple value sets was introduced in 3.2.11.
7
+ def supports_import?(current_version=self.sqlite_version)
8
+ minimum_supported_version = "3.2.11"
9
+ if current_version >= minimum_supported_version
10
+ true
11
+ else
12
+ false
13
+ end
14
+ end
15
+
2
16
  def next_value_for_sequence(sequence_name)
3
17
  %{nextval('#{sequence_name}')}
4
18
  end
@@ -43,8 +43,8 @@ class ActiveRecord::Base
43
43
 
44
44
  # Returns true if the current database connection adapter
45
45
  # supports import functionality, otherwise returns false.
46
- def supports_import?
47
- connection.supports_import?
46
+ def supports_import?(*args)
47
+ connection.supports_import?(*args)
48
48
  rescue NoMethodError
49
49
  false
50
50
  end
@@ -205,7 +205,7 @@ class ActiveRecord::Base
205
205
  # Force the primary key col into the insert if it's not
206
206
  # on the list and we are using a sequence and stuff a nil
207
207
  # value for it into each row so the sequencer will fire later
208
- if !column_names.include?(primary_key) && sequence_name && connection.prefetch_primary_key?
208
+ if !column_names.include?(primary_key) && connection.prefetch_primary_key? && sequence_name
209
209
  column_names << primary_key
210
210
  array_of_attributes.each { |a| a << nil }
211
211
  end
@@ -276,11 +276,15 @@ class ActiveRecord::Base
276
276
  # information on +column_names+, +array_of_attributes_ and
277
277
  # +options+.
278
278
  def import_without_validations_or_callbacks( column_names, array_of_attributes, options={} )
279
+ column_names = column_names.map(&:to_sym)
279
280
  scope_columns, scope_values = scope_attributes.to_a.transpose
280
281
 
281
282
  unless scope_columns.blank?
282
- column_names.concat scope_columns
283
- array_of_attributes.each { |a| a.concat scope_values }
283
+ scope_columns.zip(scope_values).each do |name, value|
284
+ next if column_names.include?(name.to_sym)
285
+ column_names << name
286
+ array_of_attributes.each { |attrs| attrs << value }
287
+ end
284
288
  end
285
289
 
286
290
  columns = column_names.each_with_index.map do |name, i|
@@ -303,7 +307,7 @@ class ActiveRecord::Base
303
307
  else
304
308
  # generate the sql
305
309
  post_sql_statements = connection.post_sql_statements( quoted_table_name, options )
306
-
310
+
307
311
  # perform the inserts
308
312
  number_inserted = connection.insert_many( [ insert_sql, post_sql_statements ].flatten,
309
313
  values_sql,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-25 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: -2739522167439917244
123
+ hash: -1608822567820744483
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements: