1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

bind substitution is working properly

This commit is contained in:
Aaron Patterson 2010-10-15 16:41:44 -07:00
parent 9d46e0d012
commit 43bbb25ddd
2 changed files with 19 additions and 7 deletions

View file

@ -228,7 +228,7 @@ module ActiveRecord
def clear_cache! def clear_cache!
@statements.each_value do |value| @statements.each_value do |value|
exec "DEALLOCATE #{value}" @connection.query "DEALLOCATE #{value}"
end end
@statements.clear @statements.clear
end end
@ -251,6 +251,7 @@ module ActiveRecord
def reconnect! def reconnect!
if @connection.respond_to?(:reset) if @connection.respond_to?(:reset)
@connection.reset @connection.reset
clear_cache!
configure_connection configure_connection
else else
disconnect! disconnect!
@ -515,6 +516,10 @@ module ActiveRecord
end end
end end
def substitute_for(column, current_values)
Arel.sql("$#{current_values.length + 1}")
end
def exec(sql, name = 'SQL', binds = []) def exec(sql, name = 'SQL', binds = [])
return async_exec(sql, name, binds) if @async return async_exec(sql, name, binds) if @async
@ -537,7 +542,9 @@ module ActiveRecord
}) })
@connection.block @connection.block
result = @connection.get_last_result result = @connection.get_last_result
ActiveRecord::Result.new(result.fields, result_as_array(result)) ret = ActiveRecord::Result.new(result.fields, result_as_array(result))
result.clear
return ret
end end
end end
@ -1014,11 +1021,8 @@ module ActiveRecord
# Executes a SELECT query and returns the results, performing any data type # Executes a SELECT query and returns the results, performing any data type
# conversions that are required to be performed here instead of in PostgreSQLColumn. # conversions that are required to be performed here instead of in PostgreSQLColumn.
def select(sql, name = nil) def select(sql, name = nil, binds = [])
fields, rows = select_raw(sql, name) exec(sql, name, binds).to_a
rows.map do |row|
Hash[fields.zip(row)]
end
end end
def select_raw(sql, name = nil) def select_raw(sql, name = nil)

View file

@ -55,6 +55,14 @@ module ActiveRecord
assert_equal [['1', 'foo']], result.rows assert_equal [['1', 'foo']], result.rows
end end
def test_substitute_for
bind = @connection.substitute_for(nil, [])
assert_equal Arel.sql('$1'), bind
bind = @connection.substitute_for(nil, [nil])
assert_equal Arel.sql('$2'), bind
end
end end
end end
end end