type casting bound value based on column associated with value

This commit is contained in:
Aaron Patterson
2010-10-12 16:39:29 -07:00
parent 76d0805786
commit d7207cf504
2 changed files with 21 additions and 1 deletions

View File

@@ -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)

View File

@@ -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