mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
type casting bound value based on column associated with value
This commit is contained in:
@@ -146,7 +146,9 @@ module ActiveRecord
|
||||
stmt = cache[:stmt]
|
||||
cols = cache[:cols] ||= stmt.columns
|
||||
stmt.reset!
|
||||
stmt.bind_params bind_values.map { |col, val| val }
|
||||
stmt.bind_params bind_values.map { |col, val|
|
||||
col ? col.type_cast(val) : val
|
||||
}
|
||||
end
|
||||
|
||||
ActiveRecord::Result.new(cols, stmt.to_a)
|
||||
|
||||
@@ -95,6 +95,24 @@ module ActiveRecord
|
||||
|
||||
assert_equal [[1, 'foo']], result.rows
|
||||
end
|
||||
|
||||
def test_exec_typecasts_bind_vals
|
||||
conn = Base.sqlite3_connection :database => ':memory:',
|
||||
:adapter => 'sqlite3',
|
||||
:timeout => 100
|
||||
|
||||
conn.exec('create table ex(id int, data string)')
|
||||
conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
|
||||
column = conn.columns('ex').find { |col| col.name == 'id' }
|
||||
|
||||
result = conn.exec(
|
||||
'SELECT id, data FROM ex WHERE id = ?', 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
|
||||
|
||||
Reference in New Issue
Block a user