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

quoting strings from equality statements, adding to_dot

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