diff options
author | Jamis Buck <jamis@37signals.com> | 2007-01-15 17:23:01 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2007-01-15 17:23:01 +0000 |
commit | 521ca37c3e6c453f48ab1dd9225bde6ea3a0c9d6 (patch) | |
tree | e4be317f29eb9251f6f613c940b6cca2e056bd26 /activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb | |
parent | 5314960d8b27957c01ad1a6cf3ef5a5624cef713 (diff) | |
download | rails-521ca37c3e6c453f48ab1dd9225bde6ea3a0c9d6.tar.gz rails-521ca37c3e6c453f48ab1dd9225bde6ea3a0c9d6.tar.bz2 rails-521ca37c3e6c453f48ab1dd9225bde6ea3a0c9d6.zip |
be like a duck. Let's not rely on explicit classes, so we can pass proxy objects around and have them interpreted correctly by ActiveRecord's serialization routines
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5953 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb b/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb index a6df79ad0d..415e15a588 100644 --- a/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb @@ -375,31 +375,33 @@ module ActiveRecord (column && column.type == :integer ? '0' : quoted_false) when Float, Fixnum, Bignum, BigDecimal value.to_s - when Time, Date, DateTime - if column - case column.type - when :date + else + if value.acts_like?(:time) || value.acts_like?(:date) + if column + case column.type + when :date + "DATE '#{value.strftime("%Y-%m-%d")}'" + when :time + "TIME '#{value.strftime("%H:%M:%S")}'" + when :timestamp + "TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'" + else + raise NotImplementedError, "Unknown column type!" + end # case + else # Column wasn't passed in, so try to guess the right type + if value.acts_like?(:date) "DATE '#{value.strftime("%Y-%m-%d")}'" - when :time - "TIME '#{value.strftime("%H:%M:%S")}'" - when :timestamp - "TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'" - else - raise NotImplementedError, "Unknown column type!" - end # case - else # Column wasn't passed in, so try to guess the right type - if value.kind_of? Date - "DATE '#{value.strftime("%Y-%m-%d")}'" - else - if [:hour, :min, :sec].all? {|part| value.send(:part).zero? } - "TIME '#{value.strftime("%H:%M:%S")}'" else - "TIMESTAMP '#{quoted_date(value)}'" - end - end - end #if column - else - "'#{quote_string(value.to_yaml)}'" + if [:hour, :min, :sec].all? {|part| value.send(:part).zero? } + "TIME '#{value.strftime("%H:%M:%S")}'" + else + "TIMESTAMP '#{quoted_date(value)}'" + end + end + end #if column + else + "'#{quote_string(value.to_yaml)}'" + end end #case end else |