diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-11 11:04:10 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-11 11:04:10 -0700 |
commit | 407540e6df50ce2343097858e9eabe2896bb66e1 (patch) | |
tree | 122eea9ea7abcc216462263a2bc2826517a7bf24 /activerecord | |
parent | 6961afefd2f163f30b9ae3aacb74b290287f9a80 (diff) | |
parent | cb07e63ba8d2d6a5aa13ce4799544fd5b413d9ff (diff) | |
download | rails-407540e6df50ce2343097858e9eabe2896bb66e1.tar.gz rails-407540e6df50ce2343097858e9eabe2896bb66e1.tar.bz2 rails-407540e6df50ce2343097858e9eabe2896bb66e1.zip |
Merge pull request #17998 from kamipo/refactor_quoted_date
Refactor `quoted_date`
Diffstat (limited to 'activerecord')
4 files changed, 13 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index e0a4af5359..c4506885ed 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -263,6 +263,16 @@ module ActiveRecord # QUOTING ================================================== + # Quote date/time values for use in SQL input. Includes microseconds + # if the value is a Time responding to usec. + def quoted_date(value) #:nodoc: + if value.acts_like?(:time) && value.respond_to?(:usec) + "#{super}.#{sprintf("%06d", value.usec)}" + else + super + end + end + # Returns a bind substitution value given a bind +column+ # NOTE: The column param is currently being used by the sqlserver-adapter def substitute_at(column, _unused = 0) diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index d19bd80576..75f244b3f3 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -74,14 +74,6 @@ module ActiveRecord @connection.escape(string) end - def quoted_date(value) - if value.acts_like?(:time) && value.respond_to?(:usec) - "#{super}.#{sprintf("%06d", value.usec)}" - else - super - end - end - #-- # CONNECTION MANAGEMENT ==================================== #++ diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 991c41327f..607848884b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -43,16 +43,12 @@ module ActiveRecord # Quote date/time values for use in SQL input. Includes microseconds # if the value is a Time responding to usec. def quoted_date(value) #:nodoc: - result = super - if value.acts_like?(:time) && value.respond_to?(:usec) - result = "#{result}.#{sprintf("%06d", value.usec)}" - end - if value.year <= 0 bce_year = format("%04d", -value.year + 1) - result = result.sub(/^-?\d+/, bce_year) + " BC" + super.sub(/^-?\d+/, bce_year) + " BC" + else + super end - result end # Does not quote function default values for UUID columns diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index c3865a8fdd..0f7e0fac01 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -256,16 +256,6 @@ module ActiveRecord %Q("#{name.to_s.gsub('"', '""')}") end - # Quote date/time values for use in SQL input. Includes microseconds - # if the value is a Time responding to usec. - def quoted_date(value) #:nodoc: - if value.respond_to?(:usec) - "#{super}.#{sprintf("%06d", value.usec)}" - else - super - end - end - #-- # DATABASE STATEMENTS ====================================== #++ |