From c6b15dde1be9f93b77e9e33ee981124a1a49c6f8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 28 Jan 2007 07:58:02 +0000 Subject: Use Date#to_s(:db) for quoted dates. Closes #7411. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6061 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/connection_adapters/abstract/quoting.rb | 10 ++++------ .../active_record/connection_adapters/postgresql_adapter.rb | 7 ++++++- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index ce9495a5d2..aa405eb47c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -25,9 +25,7 @@ module ActiveRecord # BigDecimals need to be output in a non-normalized form and quoted. when BigDecimal then value.to_s('F') else - if value.acts_like?(:date) - "'#{value.to_s}'" - elsif value.acts_like?(:time) + if value.acts_like?(:date) || value.acts_like?(:time) "'#{quoted_date(value)}'" else "'#{quote_string(value.to_yaml)}'" @@ -50,13 +48,13 @@ module ActiveRecord def quoted_true "'t'" end - + def quoted_false "'f'" end - + def quoted_date(value) - value.strftime("%Y-%m-%d %H:%M:%S") + value.to_s(:db) end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index eb9d0e94df..2f4b2b9a3a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -125,8 +125,13 @@ module ActiveRecord %("#{name}") end + # Include microseconds if the value is a Time responding to usec. def quoted_date(value) - value.strftime("%Y-%m-%d %H:%M:%S.#{sprintf("%06d", value.usec)}") + if value.acts_like?(:time) && value.respond_to?(:usec) + "#{super}.#{sprintf("%06d", value.usec)}" + else + super + end end -- cgit v1.2.3