提交 bd3ecd76 编写于 作者: A Aaron Patterson

quoting strings from equality statements, adding to_dot

上级 e1155aa9
...@@ -7,6 +7,10 @@ def initialize engine ...@@ -7,6 +7,10 @@ def initialize engine
@engine = engine @engine = engine
end end
def to_dot
Visitors::Dot.new.accept @head
end
def to_sql def to_sql
viz = Visitors::ToSql.new @engine viz = Visitors::ToSql.new @engine
viz.accept @head viz.accept @head
......
...@@ -56,6 +56,8 @@ def visit_String o ...@@ -56,6 +56,8 @@ def visit_String o
end end
alias :visit_Time :visit_String alias :visit_Time :visit_String
alias :visit_NilClass :visit_String alias :visit_NilClass :visit_String
alias :visit_Arel_SqlLiteral :visit_String
alias :visit_Fixnum :visit_String
def visit_Hash o def visit_Hash o
o.each_with_index do |pair, i| o.each_with_index do |pair, i|
...@@ -105,13 +107,17 @@ def with_node node ...@@ -105,13 +107,17 @@ def with_node node
@node_stack.pop @node_stack.pop
end end
def quote string
string.to_s.gsub('"', '\"')
end
def to_dot def to_dot
"digraph \"ARel\" {\nnode [width=0.375,height=0.25,shape=record];\n" + "digraph \"ARel\" {\nnode [width=0.375,height=0.25,shape=record];\n" +
@nodes.map { |node| @nodes.map { |node|
label = "<f0>#{node.name}" label = "<f0>#{node.name}"
node.fields.each_with_index do |field, i| node.fields.each_with_index do |field, i|
label << "|<f#{i + 1}>#{field}" label << "|<f#{i + 1}>#{quote field}"
end end
"#{node.id} [label=\"#{label}\"];" "#{node.id} [label=\"#{label}\"];"
......
...@@ -57,7 +57,7 @@ def visit_Arel_Table o ...@@ -57,7 +57,7 @@ def visit_Arel_Table o
end end
def visit_Arel_Nodes_Equality o def visit_Arel_Nodes_Equality o
"#{visit o.left} = #{visit o.right}" "#{visit o.left} = #{quote visit o.right}"
end end
def visit_Arel_Attributes_Attribute o def visit_Arel_Attributes_Attribute o
......
...@@ -12,6 +12,15 @@ module Visitors ...@@ -12,6 +12,15 @@ module Visitors
attr = Attributes::Time.new(@attr.relation, @attr.name, @attr.column) attr = Attributes::Time.new(@attr.relation, @attr.name, @attr.column)
@visitor.accept attr @visitor.accept attr
end end
describe 'Equality' do
it "should escape strings" do
test = @attr.eq 'Aaron Patterson'
@visitor.accept(test).should be_like %{
"users"."id" = 'Aaron Patterson'
}
end
end
end end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册