From 4f3638b24fd4d614eb54333fc15fd922b937b70d Mon Sep 17 00:00:00 2001 From: cpfarher Date: Thu, 1 Sep 2016 17:57:53 -0300 Subject: [PATCH 1/5] approximation to rails 5.0.0.1 and activerecord 5.0.0.1 compatibility --- bulk_data_methods.gemspec | 4 ++-- lib/bulk_data_methods/mixin.rb | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bulk_data_methods.gemspec b/bulk_data_methods.gemspec index a3004a9..d86de5d 100644 --- a/bulk_data_methods.gemspec +++ b/bulk_data_methods.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.homepage = 'http://github.com/fiksu/bulk_data_methods' s.add_dependency "pg" - s.add_dependency "activerecord", '>= 3.0', '< 5.0' - s.add_development_dependency "rails", '>= 3.0', '< 5.0' + s.add_dependency "activerecord", '>= 3.0'#, '< 5.0' + s.add_development_dependency "rails", '>= 3.0' s.add_development_dependency "rspec-rails" s.add_development_dependency "activeresource", '>= 3.0.0' end diff --git a/lib/bulk_data_methods/mixin.rb b/lib/bulk_data_methods/mixin.rb index eb813d6..2df2725 100644 --- a/lib/bulk_data_methods/mixin.rb +++ b/lib/bulk_data_methods/mixin.rb @@ -105,7 +105,7 @@ def create_many(rows, options = {}) end end column_values = column_names.map do |column_name| - quote_value(row[column_name], columns_hash[column_name.to_s]) + connection.quote(row[column_name], columns_hash[column_name.to_s]) end.join(',') "(#{column_values})" end.each_slice(options[:slice_size]) do |insert_slice| @@ -236,9 +236,9 @@ def update_many(rows, options = {}) column_name = column_name.to_s columns_hash_value = columns_hash[column_name] if i == 0 - "#{quote_value(column_value, columns_hash_value)}::#{columns_hash_value.sql_type} as #{column_name}" + "#{connection.quote(column_value,columns_hash_value)}::#{columns_hash_value.sql_type} as #{column_name}" else - quote_value(column_value, columns_hash_value) + connection.quote(column_value,columns_hash_value) end end.join(',') end @@ -257,7 +257,8 @@ def update_many(rows, options = {}) #{eval(returning_clause)} SQL sql = sql_update_string -#puts "SQL> #{sql}" +#binding.pry +#puts "SQL> #{sql}" returning += find_by_sql(sql_update_string) end end From ffe64244fc086b352adc341f2fa5c9e70c43d203 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Tue, 6 Sep 2016 16:19:21 -0300 Subject: [PATCH 2/5] pass object for compatibility with quote in activerecord 5 --- lib/bulk_data_methods/mixin.rb | 5 ++--- lib/bulk_data_methods/version.rb | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/bulk_data_methods/mixin.rb b/lib/bulk_data_methods/mixin.rb index 2df2725..84caa78 100644 --- a/lib/bulk_data_methods/mixin.rb +++ b/lib/bulk_data_methods/mixin.rb @@ -1,4 +1,3 @@ - module BulkDataMethods # exception thrown when row data structures are inconsistent between rows in single call to {#create_many} or {#update_many} @@ -236,9 +235,9 @@ def update_many(rows, options = {}) column_name = column_name.to_s columns_hash_value = columns_hash[column_name] if i == 0 - "#{connection.quote(column_value,columns_hash_value)}::#{columns_hash_value.sql_type} as #{column_name}" + "#{connection.quote(column_value)}::#{columns_hash_value.sql_type} as #{column_name}" else - connection.quote(column_value,columns_hash_value) + connection.quote(column_value) end end.join(',') end diff --git a/lib/bulk_data_methods/version.rb b/lib/bulk_data_methods/version.rb index 21c55d6..bcc5700 100644 --- a/lib/bulk_data_methods/version.rb +++ b/lib/bulk_data_methods/version.rb @@ -1,3 +1,3 @@ module BulkDataMethods - VERSION = "3.0.1" + VERSION = "3.0.2" end From 242343288c8cca2d00ff83c964765e912bbca0fc Mon Sep 17 00:00:00 2001 From: cpfarher Date: Wed, 7 Sep 2016 11:07:48 -0300 Subject: [PATCH 3/5] quoting for array values --- .../connection_adapters/postgresql/quoting.rb | 21 +++++++++++++++++++ lib/bulk_data_methods/version.rb | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb diff --git a/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb new file mode 100644 index 0000000..9be4bf5 --- /dev/null +++ b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb @@ -0,0 +1,21 @@ +module ActiveRecord + module ConnectionAdapters + module PostgreSQL + module Quoting + + private + # ****** BEGIN PATCH ****** + # when column of postgresql is an array, call super and fail. for example with [2] or ["2"]. + # add condition for array elswhere call super + # @param [Value] + def _quote(value) + case value + when Array then "'{#{value.join(',')}}'" + else + super + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/bulk_data_methods/version.rb b/lib/bulk_data_methods/version.rb index bcc5700..57c8176 100644 --- a/lib/bulk_data_methods/version.rb +++ b/lib/bulk_data_methods/version.rb @@ -1,3 +1,3 @@ module BulkDataMethods - VERSION = "3.0.2" + VERSION = "3.0.3" end From 6a8b20377c8144e6c562a018c62d30c82a80c2f5 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Wed, 7 Sep 2016 11:35:05 -0300 Subject: [PATCH 4/5] change quoting method order --- .../connection_adapters/postgresql/quoting.rb | 42 +++++++++---------- .../connection_adapters/postgresql_adapter.rb | 19 ++++++++- lib/bulk_data_methods/version.rb | 2 +- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb index 9be4bf5..86132d3 100644 --- a/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb +++ b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql/quoting.rb @@ -1,21 +1,21 @@ -module ActiveRecord - module ConnectionAdapters - module PostgreSQL - module Quoting - - private - # ****** BEGIN PATCH ****** - # when column of postgresql is an array, call super and fail. for example with [2] or ["2"]. - # add condition for array elswhere call super - # @param [Value] - def _quote(value) - case value - when Array then "'{#{value.join(',')}}'" - else - super - end - end - end - end - end -end \ No newline at end of file +# module ActiveRecord +# module ConnectionAdapters +# module PostgreSQL +# module Quoting +# +# private +# # ****** BEGIN PATCH ****** +# # when column of postgresql is an array, call super and fail. for example with [2] or ["2"]. +# # add condition for array elswhere call super +# # @param [Value] +# def _quote(value) +# case value +# when Array then "'{#{value.join(',')}}'" +# else +# super +# end +# end +# end +# end +# end +# end \ No newline at end of file diff --git a/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql_adapter.rb b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql_adapter.rb index 4864cc0..e2aa765 100644 --- a/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql_adapter.rb +++ b/lib/bulk_data_methods/patches/active_record/connection_adapters/postgresql_adapter.rb @@ -1,11 +1,28 @@ require 'active_record' require 'active_record/connection_adapters/abstract_adapter' require 'active_record/connection_adapters/postgresql_adapter' +require 'active_record/connection_adapters/postgresql/quoting' module ActiveRecord module ConnectionAdapters - + module PostgreSQL + module Quoting + + private + # ****** BEGIN PATCH ****** + # when column of postgresql is an array, call super and fail. for example with [2] or ["2"]. + # add condition for array elswhere call super + # @param [Value] + def _quote(value) + case value + when Array then "'{#{value.join(',')}}'" + else + super + end + end + end + end # Patches extending the postgres adapter with new operations for managing # sequences (and sets of sequence values). # diff --git a/lib/bulk_data_methods/version.rb b/lib/bulk_data_methods/version.rb index 57c8176..f43caa3 100644 --- a/lib/bulk_data_methods/version.rb +++ b/lib/bulk_data_methods/version.rb @@ -1,3 +1,3 @@ module BulkDataMethods - VERSION = "3.0.3" + VERSION = "3.0.4" end From 08ae3836ec9a4478e1bbff15735fe3f2f7a34063 Mon Sep 17 00:00:00 2001 From: cpfarher Date: Thu, 3 Nov 2016 18:27:00 -0300 Subject: [PATCH 5/5] soporte para jsonb --- lib/bulk_data_methods/mixin.rb | 12 ++++++++++-- lib/bulk_data_methods/version.rb | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/bulk_data_methods/mixin.rb b/lib/bulk_data_methods/mixin.rb index 84caa78..4ee83a9 100644 --- a/lib/bulk_data_methods/mixin.rb +++ b/lib/bulk_data_methods/mixin.rb @@ -235,9 +235,17 @@ def update_many(rows, options = {}) column_name = column_name.to_s columns_hash_value = columns_hash[column_name] if i == 0 - "#{connection.quote(column_value)}::#{columns_hash_value.sql_type} as #{column_name}" + if columns_hash_value.sql_type=="jsonb" && !column_value.nil? && !column_value!='NULL' + "'#{connection.quote(column_value)}'::#{columns_hash_value.sql_type} as #{column_name}" + else + "#{connection.quote(column_value)}::#{columns_hash_value.sql_type} as #{column_name}" + end else - connection.quote(column_value) + if columns_hash_value.sql_type=="jsonb" && !column_value.nil? && !column_value!='NULL' + "'#{connection.quote(column_value)}'" + else + connection.quote(column_value) + end end end.join(',') end diff --git a/lib/bulk_data_methods/version.rb b/lib/bulk_data_methods/version.rb index f43caa3..e3d88fa 100644 --- a/lib/bulk_data_methods/version.rb +++ b/lib/bulk_data_methods/version.rb @@ -1,3 +1,3 @@ module BulkDataMethods - VERSION = "3.0.4" + VERSION = "3.0.5" end