aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorWill Bryant <will.bryant@gmail.com>2009-02-04 13:01:03 +1300
committerMichael Koziarski <michael@koziarski.com>2009-02-06 13:43:02 +1300
commit9991868d85b25da672bf119bfcbff22a4bb6e8f1 (patch)
tree7f956a6f83d9b0aca69e84b712a3c83fb677c6b7 /activerecord/lib/active_record/base.rb
parentba146a84d0ed8a886fdc6b6794ce99a9d37c0190 (diff)
downloadrails-9991868d85b25da672bf119bfcbff22a4bb6e8f1.tar.gz
rails-9991868d85b25da672bf119bfcbff22a4bb6e8f1.tar.bz2
rails-9991868d85b25da672bf119bfcbff22a4bb6e8f1.zip
support end-exclusive ... Ranges in SQL hash condition sanitization properly
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1865 state:committed]
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 9f9fbd8b37..78c6ac2ba8 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1992,12 +1992,16 @@ module ActiveRecord #:nodoc:
attribute_names.all? { |name| column_methods_hash.include?(name.to_sym) }
end
- def attribute_condition(argument)
+ def attribute_condition(quoted_column_name, argument)
case argument
- when nil then "IS ?"
- when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "IN (?)"
- when Range then "BETWEEN ? AND ?"
- else "= ?"
+ when nil then "#{quoted_column_name} IS ?"
+ when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "#{quoted_column_name} IN (?)"
+ when Range then if argument.exclude_end?
+ "#{quoted_column_name} >= ? AND #{quoted_column_name} < ?"
+ else
+ "#{quoted_column_name} BETWEEN ? AND ?"
+ end
+ else "#{quoted_column_name} = ?"
end
end
@@ -2307,7 +2311,7 @@ module ActiveRecord #:nodoc:
table_name = connection.quote_table_name(table_name)
end
- "#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}"
+ attribute_condition("#{table_name}.#{connection.quote_column_name(attr)}", value)
else
sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s))
end