提交 a431df84 编写于 作者: S Sean Griffin

Merge pull request #17463 from mrgilman/remove-index-from-substitute-at

Remove redundant substitute index when constructing bind values
...@@ -267,7 +267,7 @@ def index_algorithms ...@@ -267,7 +267,7 @@ def index_algorithms
# Returns a bind substitution value given a bind +index+ and +column+ # Returns a bind substitution value given a bind +index+ and +column+
# NOTE: The column param is currently being used by the sqlserver-adapter # NOTE: The column param is currently being used by the sqlserver-adapter
def substitute_at(column, index) def substitute_at(column, index = 0)
Arel::Nodes::BindParam.new '?' Arel::Nodes::BindParam.new '?'
end end
......
...@@ -156,7 +156,7 @@ def execute(sql, name = nil) ...@@ -156,7 +156,7 @@ def execute(sql, name = nil)
end end
end end
def substitute_at(column, index) def substitute_at(column, index = 0)
Arel::Nodes::BindParam.new "$#{index + 1}" Arel::Nodes::BindParam.new "$#{index + 1}"
end end
......
...@@ -958,8 +958,7 @@ def build_where(opts, other = []) ...@@ -958,8 +958,7 @@ def build_where(opts, other = [])
when Hash when Hash
opts = PredicateBuilder.resolve_column_aliases(klass, opts) opts = PredicateBuilder.resolve_column_aliases(klass, opts)
bv_len = bind_values.length tmp_opts, bind_values = create_binds(opts)
tmp_opts, bind_values = create_binds(opts, bv_len)
self.bind_values += bind_values self.bind_values += bind_values
attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts) attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
...@@ -971,7 +970,7 @@ def build_where(opts, other = []) ...@@ -971,7 +970,7 @@ def build_where(opts, other = [])
end end
end end
def create_binds(opts, idx) def create_binds(opts)
bindable, non_binds = opts.partition do |column, value| bindable, non_binds = opts.partition do |column, value|
case value case value
when String, Integer, ActiveRecord::StatementCache::Substitute when String, Integer, ActiveRecord::StatementCache::Substitute
...@@ -984,9 +983,9 @@ def create_binds(opts, idx) ...@@ -984,9 +983,9 @@ def create_binds(opts, idx)
new_opts = {} new_opts = {}
binds = [] binds = []
bindable.each_with_index do |(column,value), index| bindable.each do |(column,value)|
binds.push [@klass.columns_hash[column.to_s], value] binds.push [@klass.columns_hash[column.to_s], value]
new_opts[column] = connection.substitute_at(column, index + idx) new_opts[column] = connection.substitute_at(column)
end end
non_binds.each { |column,value| new_opts[column] = value } non_binds.each { |column,value| new_opts[column] = value }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册