diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-15 16:24:04 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-26 13:44:10 -0700 |
commit | 9d46e0d012e5c4687af4d14584f1230e71d7d654 (patch) | |
tree | 1cceb5d1951e872dc7f5f8759b08031496cdfb1b | |
parent | e2813479f96e6dbfcfcde667797298611a9c9311 (diff) | |
download | rails-9d46e0d012e5c4687af4d14584f1230e71d7d654.tar.gz rails-9d46e0d012e5c4687af4d14584f1230e71d7d654.tar.bz2 rails-9d46e0d012e5c4687af4d14584f1230e71d7d654.zip |
bind parameters are now typecast
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 80b987fb89..46c3486be6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -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)) diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 0b295c9613..70de8c5e6c 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -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 |