diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 16:14:02 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 16:14:02 -0700 |
commit | af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5 (patch) | |
tree | c3eaf1cfdc0ed1f1d977937fb04848566e964c32 /lib | |
parent | ed9c8d4d828fe4e28c1e37ed8921acbee54450f2 (diff) | |
download | rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.tar.gz rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.tar.bz2 rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.zip |
formatting insert and update statements
- values need to be coerced to the type corresponding to the column
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/extensions/array.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/extensions/hash.rb | 8 | ||||
-rw-r--r-- | lib/active_relation/relations/insertion.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/update.rb | 6 |
4 files changed, 6 insertions, 14 deletions
diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb index 5e2981a4c5..c07819d35f 100644 --- a/lib/active_relation/extensions/array.rb +++ b/lib/active_relation/extensions/array.rb @@ -3,7 +3,7 @@ class Array Hash[*flatten] end - def to_sql(formatter = Sql::SelectExpression.new) - formatter.array self + def to_sql(formatter = nil) + "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")" end end
\ No newline at end of file diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb index 133eab1026..a33ace5738 100644 --- a/lib/active_relation/extensions/hash.rb +++ b/lib/active_relation/extensions/hash.rb @@ -8,12 +8,4 @@ class Hash descendent.merge(yield(key) => yield(value)) end end - - def to_sql(formatter = nil) - '(' + - inject([]) do |values, (key, value)| - values << key.format(value) - end.join(', ') + - ')' - end end
\ No newline at end of file diff --git a/lib/active_relation/relations/insertion.rb b/lib/active_relation/relations/insertion.rb index bcf8e33e0a..901ff6eb70 100644 --- a/lib/active_relation/relations/insertion.rb +++ b/lib/active_relation/relations/insertion.rb @@ -11,7 +11,7 @@ module ActiveRelation "INSERT", "INTO #{table_sql}", "(#{record.keys.collect(&:to_sql)})", - "VALUES #{record.to_sql}" + "VALUES (#{record.collect { |key, value| key.format(value) }})" ].join("\n") end diff --git a/lib/active_relation/relations/update.rb b/lib/active_relation/relations/update.rb index dc88ea0362..7eb78d5473 100644 --- a/lib/active_relation/relations/update.rb +++ b/lib/active_relation/relations/update.rb @@ -9,9 +9,9 @@ module ActiveRelation def to_sql(formatter = nil) [ "UPDATE #{table_sql} SET", - assignments.inject("") do |assignments, (attribute, value)| - assignments << " #{attribute.to_sql} = #{value.to_sql}" - end, + assignments.collect do |attribute, value| + "#{value.format(attribute)} = #{attribute.format(value)}" + end.join("\n"), ("WHERE #{selects.collect(&:to_sql).join('\n\tAND ')}" unless selects.blank?) ].join("\n") end |