aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-12 16:39:29 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:08 -0700
commitd7207cf504b67243c0b7debaff70d948bb8be7a8 (patch)
treec5c9fd9eff9c7c33fb97b114ed2ced9088fbc687 /activerecord
parent76d08057860d61cf16893bbfecbc7c7ccec74386 (diff)
downloadrails-d7207cf504b67243c0b7debaff70d948bb8be7a8.tar.gz
rails-d7207cf504b67243c0b7debaff70d948bb8be7a8.tar.bz2
rails-d7207cf504b67243c0b7debaff70d948bb8be7a8.zip
type casting bound value based on column associated with value
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb4
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb18
2 files changed, 21 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 0ea45dd61d..6598feec62 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -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)
diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
index 52630c5ad4..969029db51 100644
--- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -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