diff options
Diffstat (limited to 'lib/arel/visitors/to_sql.rb')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 486c51a183..2b5c43b173 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -1,8 +1,4 @@ # frozen_string_literal: true -require 'bigdecimal' -require 'date' -require 'arel/visitors/reduce' - module Arel module Visitors class UnsupportedVisitError < StandardError @@ -11,7 +7,7 @@ module Arel end end - class ToSql < Arel::Visitors::Reduce + class ToSql < Arel::Visitors::Visitor ## # This is some roflscale crazy stuff. I'm roflscaling this because # building SQL queries is a hotspot. I will explain the roflscale so that @@ -166,6 +162,28 @@ module Arel collector << "FALSE" end + def visit_Arel_Nodes_ValuesList o, collector + collector << "VALUES " + + len = o.rows.length - 1 + o.rows.each_with_index { |row, i| + collector << '(' + row_len = row.length - 1 + row.each_with_index do |value, k| + case value + when Nodes::SqlLiteral, Nodes::BindParam + collector = visit(value, collector) + else + collector << quote(value) + end + collector << COMMA unless k == row_len + end + collector << ')' + collector << COMMA unless i == len + } + collector + end + def visit_Arel_Nodes_Values o, collector collector << "VALUES (" @@ -405,7 +423,8 @@ module Arel end def visit_Arel_SelectManager o, collector - collector << "(#{o.to_sql.rstrip})" + collector << '(' + visit(o.ast, collector) << ')' end def visit_Arel_Nodes_Ascending o, collector @@ -715,7 +734,7 @@ module Arel def literal o, collector; collector << o.to_s; end def visit_Arel_Nodes_BindParam o, collector - collector.add_bind(o) { "?" } + collector.add_bind(o.value) { "?" } end alias :visit_Arel_Nodes_SqlLiteral :literal |