diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-08-27 23:49:25 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-08-31 13:51:01 -0300 |
commit | 71ff7d9c6592b93e2c810a1f464943dd7bd02c7f (patch) | |
tree | 38e27c3380f59d5a32c2a097f08ad29b9fe20d9d | |
parent | 2b3a8063ad862b3cdf129bd24b786f5eeadcc935 (diff) | |
download | rails-71ff7d9c6592b93e2c810a1f464943dd7bd02c7f.tar.gz rails-71ff7d9c6592b93e2c810a1f464943dd7bd02c7f.tar.bz2 rails-71ff7d9c6592b93e2c810a1f464943dd7bd02c7f.zip |
Do not dup the binds when visiting the AST
The visitor have to consume the bind parameters to make the statements
work when the prepared statement option is disabled.
Fixes #12023
3 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 32244b1755..ce63b5b4df 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -9,7 +9,6 @@ module ActiveRecord # Converts an arel AST to SQL def to_sql(arel, binds = []) if arel.respond_to?(:ast) - binds = binds.dup visitor.accept(arel.ast) do quote(*binds.shift.reverse) end @@ -377,7 +376,7 @@ module ActiveRecord def sql_for_insert(sql, pk, id_value, sequence_name, binds) [sql, binds] end - + def last_inserted_id(result) row = result.rows.first row && row.first diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 92796c996e..e790f731ea 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -229,7 +229,7 @@ module ActiveRecord alias exec_without_stmt exec_query - # Returns an ActiveRecord::Result instance. + # Returns an ActiveRecord::Result instance. def select(sql, name = nil, binds = []) exec_query(sql, name) end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 6fb046a44e..aa9f21ef36 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -329,6 +329,14 @@ class BasicsTest < ActiveRecord::TestCase assert !cbs[1].frickinawesome end + def test_create_without_prepared_statement + cb = CustomBulb.connection.unprepared_statement do + CustomBulb.create(name: 'Dude') + end + + assert_equal('Dude', cb.name) + end + def test_load topics = Topic.all.merge!(:order => 'id').to_a assert_equal(4, topics.size) |