Permalink
Browse files

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
  • Loading branch information...
1 parent 2b3a806 commit 71ff7d9c6592b93e2c810a1f464943dd7bd02c7f @rafaelfranca rafaelfranca committed Aug 28, 2013
@@ -9,7 +9,6 @@ def initialize
# 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 @@ def delete_sql(sql, name = nil)
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
@@ -229,7 +229,7 @@ def exec_query(sql, name = 'SQL', binds = [])
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
@@ -329,6 +329,14 @@ def test_create_after_initialize_with_array_param
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)

0 comments on commit 71ff7d9

Please sign in to comment.