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

bind parameters are now typecast

This commit is contained in:
Aaron Patterson 2010-10-15 16:24:04 -07:00
parent e2813479f9
commit 9d46e0d012
2 changed files with 17 additions and 1 deletions

View file

@ -532,7 +532,9 @@ module ActiveRecord
# Clear the queue
@connection.get_last_result
@connection.send_query_prepared(key, binds.map { |col, val| val })
@connection.send_query_prepared(key, binds.map { |col, val|
col ? col.type_cast(val) : val
})
@connection.block
result = @connection.get_last_result
ActiveRecord::Result.new(result.fields, result_as_array(result))

View file

@ -41,6 +41,20 @@ module ActiveRecord
assert_equal [['1', 'foo']], result.rows
end
def test_exec_typecasts_bind_vals
string = @connection.quote('foo')
@connection.exec("INSERT INTO ex (id, data) VALUES (1, #{string})")
column = @connection.columns('ex').find { |col| col.name == 'id' }
result = @connection.exec(
'SELECT id, data FROM ex WHERE id = $1', nil, [[column, '1-fuu']])
assert_equal 1, result.rows.length
assert_equal 2, result.columns.length
assert_equal [['1', 'foo']], result.rows
end
end
end
end