From b4fd431b973e7fc50d3cbf0432b3d8272ac65f0e Mon Sep 17 00:00:00 2001 From: Noemj Date: Mon, 4 Feb 2013 10:29:41 +0200 Subject: Fixed the bind param visiting for mysql2 prepared statements case --- lib/arel/visitors/bind_visitor.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/arel/visitors/bind_visitor.rb b/lib/arel/visitors/bind_visitor.rb index 0f1e38315b..77f91d9451 100644 --- a/lib/arel/visitors/bind_visitor.rb +++ b/lib/arel/visitors/bind_visitor.rb @@ -12,6 +12,15 @@ module Arel end private + + def visit_Arel_Nodes_Assignment o + if o.right.is_a? Arel::Nodes::BindParam + "#{visit o.left} = #{visit o.right}" + else + super + end + end + def visit_Arel_Nodes_BindParam o if @block @block.call @@ -19,6 +28,7 @@ module Arel super end end + end end end -- cgit v1.2.3 From 30a74c09e794a46eac6bd0719f1b0333704317b2 Mon Sep 17 00:00:00 2001 From: Noemj Date: Tue, 5 Feb 2013 15:06:04 +0200 Subject: Added unit test for the mysql2 bind substitution --- test/visitors/test_bind_visitor.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/visitors/test_bind_visitor.rb b/test/visitors/test_bind_visitor.rb index 92e5d1612c..dbcfb67df5 100644 --- a/test/visitors/test_bind_visitor.rb +++ b/test/visitors/test_bind_visitor.rb @@ -1,9 +1,28 @@ require 'helper' require 'arel/visitors/bind_visitor' +require 'support/fake_record' module Arel module Visitors - class TestBindVisitor < MiniTest::Unit::TestCase + class TestBindVisitor < MiniTest::Unit::TestCase + + ## + # Tests visit_Arel_Nodes_Assignment correctly + # substitutes binds with values from block + def test_assignment_binds_are_substituted + table = Table.new(:users) + um = Arel::UpdateManager.new Table.engine + bp = Nodes::BindParam.new '?' + um.set [[table[:name], bp]] + visitor = Class.new(Arel::Visitors::ToSql) { + include Arel::Visitors::BindVisitor + }.new Table.engine.connection + + assignment = um.ast.values[0] + actual = visitor.accept(assignment) { "replace" } + actual.must_be_like "\"name\" = replace" + end + def test_visitor_yields_on_binds visitor = Class.new(Arel::Visitors::Visitor) { def initialize omg -- cgit v1.2.3