From e2813479f96e6dbfcfcde667797298611a9c9311 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 15 Oct 2010 16:15:58 -0700 Subject: basic bind parameters are working --- .../active_record/connection_adapters/postgresql_adapter.rb | 2 +- .../cases/adapters/postgresql/postgresql_adapter_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 75b4c1e653..80b987fb89 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -532,7 +532,7 @@ module ActiveRecord # Clear the queue @connection.get_last_result - @connection.send_query_prepared(key, []) + @connection.send_query_prepared(key, binds.map { |col, 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 a61482256a..0b295c9613 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -29,6 +29,18 @@ module ActiveRecord assert_equal [['1', 'foo']], result.rows end + + def test_exec_with_binds + string = @connection.quote('foo') + @connection.exec("INSERT INTO ex (id, data) VALUES (1, #{string})") + result = @connection.exec( + 'SELECT id, data FROM ex WHERE id = $1', nil, [[nil, 1]]) + + assert_equal 1, result.rows.length + assert_equal 2, result.columns.length + + assert_equal [['1', 'foo']], result.rows + end end end end -- cgit v1.2.3