diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-12 18:40:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-12 18:40:29 -0700 |
commit | 09608ce9d236c6a9439cf011a3442e1492d0732e (patch) | |
tree | e9615e935056b770268e1b1e2949713d2bc10a64 /activerecord/lib/active_record/statement_cache.rb | |
parent | 85f3a57a57b3c6d105e35936bf3ee972dc652902 (diff) | |
download | rails-09608ce9d236c6a9439cf011a3442e1492d0732e.tar.gz rails-09608ce9d236c6a9439cf011a3442e1492d0732e.tar.bz2 rails-09608ce9d236c6a9439cf011a3442e1492d0732e.zip |
use an array for bind params to simplify substitution
Diffstat (limited to 'activerecord/lib/active_record/statement_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index d6c48125f4..aece446384 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -14,7 +14,7 @@ module ActiveRecord # The relation returned by the block is cached, and for each +execute+ call the cached relation gets duped. # Database is queried when +to_a+ is called on the relation. class StatementCache - Substitute = Struct.new :name + class Substitute; end class Query def initialize(sql) @@ -52,24 +52,24 @@ module ActiveRecord end class Params - def [](name); Substitute.new name; end + def bind; Substitute.new; end end class BindMap def initialize(bind_values) - @value_map = {} + @indexes = [] @bind_values = bind_values bind_values.each_with_index do |(_, value), i| if Substitute === value - @value_map[value.name] = i + @indexes << i end end end def bind(values) bvs = @bind_values.map { |pair| pair.dup } - values.each { |k,v| bvs[@value_map[k]][1] = v } + @indexes.each_with_index { |offset,i| bvs[offset][1] = values[i] } bvs end end |