Skip to content
Browse files

use index based substitution for bind parameters

  • Loading branch information...
1 parent 48fb6b3 commit eebb19c954d64760c232cda10263200f32fcf036 @tenderlove tenderlove committed Apr 13, 2011
View
2 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -105,7 +105,7 @@ def quote_table_name(name)
# Returns a bind substitution value given a +column+ and list of current
# +binds+
- def substitute_for(column, binds)
+ def substitute_at(column, index)
Arel.sql '?'
end
View
4 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -511,8 +511,8 @@ def execute(sql, name = nil)
end
end
- def substitute_for(column, current_values)
- Arel.sql("$#{current_values.length + 1}")
+ def substitute_at(column, index)
+ Arel.sql("$#{index + 1}")
end
def exec_query(sql, name = 'SQL', binds = [])
View
2 activerecord/lib/active_record/relation/finder_methods.rb
@@ -320,7 +320,7 @@ def find_one(id)
column = columns_hash[primary_key]
- substitute = connection.substitute_for(column, @bind_values)
+ substitute = connection.substitute_at(column, @bind_values.length)
relation = where(table[primary_key].eq(substitute))
relation.bind_values = [[column, id]]
record = relation.first
View
2 activerecord/test/cases/adapters/mysql/connection_test.rb
@@ -44,7 +44,7 @@ def test_successful_reconnection_after_timeout_with_verify
end
def test_bind_value_substitute
- bind_param = @connection.substitute_for('foo', [])
+ bind_param = @connection.substitute_at('foo', 0)
assert_equal Arel.sql('?'), bind_param
end
View
6 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -102,11 +102,11 @@ def test_exec_typecasts_bind_vals
assert_equal [['1', 'foo']], result.rows
end
- def test_substitute_for
- bind = @connection.substitute_for(nil, [])
+ def test_substitute_at
+ bind = @connection.substitute_at(nil, 0)
assert_equal Arel.sql('$1'), bind
- bind = @connection.substitute_for(nil, [nil])
+ bind = @connection.substitute_at(nil, 1)
assert_equal Arel.sql('$2'), bind
end
View
2 activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -80,7 +80,7 @@ def test_encoding
end
def test_bind_value_substitute
- bind_param = @conn.substitute_for('foo', [])
+ bind_param = @conn.substitute_at('foo', 0)
assert_equal Arel.sql('?'), bind_param
end
View
2 activerecord/test/cases/bind_parameter_test.rb
@@ -33,7 +33,7 @@ def test_binds_are_logged
# FIXME: use skip with minitest
return unless @connection.supports_statement_cache?
- sub = @connection.substitute_for(@pk, [])
+ sub = @connection.substitute_at(@pk, 0)
binds = [[@pk, 1]]
sql = "select * from topics where id = #{sub}"

0 comments on commit eebb19c

Please sign in to comment.
Something went wrong with that request. Please try again.