1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

bind parameters can be differentiated from sql literals

This commit is contained in:
Aaron Patterson 2012-02-20 17:57:37 -08:00
parent cbdc7e72ba
commit 33f03c5557
6 changed files with 13 additions and 0 deletions

View file

@ -6,5 +6,8 @@ module Arel
include Arel::AliasPredication
include Arel::OrderPredications
end
class BindParam < SqlLiteral
end
end
end

View file

@ -109,6 +109,7 @@ module Arel
alias :visit_Arel_Nodes_Lock :terminal
alias :visit_Arel_Nodes_Node :terminal
alias :visit_Arel_Nodes_SqlLiteral :terminal
alias :visit_Arel_Nodes_BindParam :terminal
alias :visit_Arel_SqlLiteral :terminal
alias :visit_BigDecimal :terminal
alias :visit_Bignum :terminal

View file

@ -65,6 +65,7 @@ module Arel
visit_edge o, "expr"
end
alias :visit_Arel_Nodes_Group :unary
alias :visit_Arel_Nodes_BindParam :unary
alias :visit_Arel_Nodes_Grouping :unary
alias :visit_Arel_Nodes_Having :unary
alias :visit_Arel_Nodes_Limit :unary

View file

@ -374,6 +374,7 @@ key on UpdateManager using UpdateManager#key=
def literal o; o end
alias :visit_Arel_Nodes_BindParam :literal
alias :visit_Arel_Nodes_SqlLiteral :literal
alias :visit_Arel_SqlLiteral :literal # This is deprecated
alias :visit_Bignum :literal

View file

@ -11,6 +11,7 @@ module Arel
Nodes.const_get(k)
}.grep(Class).each do |klass|
next if Nodes::SqlLiteral == klass
next if Nodes::BindParam == klass
next if klass.name =~ /^Arel::Nodes::Test/
assert klass.ancestors.include?(Nodes::Node), klass.name
end

View file

@ -9,6 +9,12 @@ module Arel
@attr = @table[:id]
end
it 'works with BindParams' do
node = Nodes::BindParam.new 'omg'
sql = @visitor.accept node
sql.must_be_like 'omg'
end
it 'can define a dispatch method' do
visited = false
viz = Class.new(Arel::Visitors::Visitor) {