aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2007-01-15 17:23:01 +0000
committerJamis Buck <jamis@37signals.com>2007-01-15 17:23:01 +0000
commit521ca37c3e6c453f48ab1dd9225bde6ea3a0c9d6 (patch)
treee4be317f29eb9251f6f613c940b6cca2e056bd26 /activerecord
parent5314960d8b27957c01ad1a6cf3ef5a5624cef713 (diff)
downloadrails-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')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb11
-rw-r--r--activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb48
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb11
-rw-r--r--activerecord/lib/active_record/connection_adapters/sybase_adapter.rb8
4 files changed, 47 insertions, 31 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 0f2008deb5..ce9495a5d2 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -24,9 +24,14 @@ module ActiveRecord
when Float, Fixnum, Bignum then value.to_s
# BigDecimals need to be output in a non-normalized form and quoted.
when BigDecimal then value.to_s('F')
- when Date then "'#{value.to_s}'"
- when Time, DateTime then "'#{quoted_date(value)}'"
- else "'#{quote_string(value.to_yaml)}'"
+ else
+ if value.acts_like?(:date)
+ "'#{value.to_s}'"
+ elsif value.acts_like?(:time)
+ "'#{quoted_date(value)}'"
+ else
+ "'#{quote_string(value.to_yaml)}'"
+ end
end
end
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
diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
index 8a94e55e30..28936f8a89 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -347,9 +347,14 @@ module ActiveRecord
case value
when TrueClass then '1'
when FalseClass then '0'
- when Time, DateTime then "'#{value.strftime("%Y%m%d %H:%M:%S")}'"
- when Date then "'#{value.strftime("%Y%m%d")}'"
- else super
+ else
+ if value.acts_like?(:time)
+ "'#{value.strftime("%Y%m%d %H:%M:%S")}'"
+ elsif value.acts_like?(:date)
+ "'#{value.strftime("%Y%m%d")}'"
+ else
+ super
+ end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb b/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb
index 708a11b230..45b5d0bc96 100644
--- a/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb
@@ -292,8 +292,12 @@ SQLTEXT
when TrueClass then '1'
when FalseClass then '0'
when Float, Fixnum, Bignum then force_numeric?(column) ? value.to_s : "'#{value.to_s}'"
- when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
- else super
+ else
+ if value.acts_like?(:time)
+ "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
+ else
+ super
+ end
end
end