Sha256: 2a6bbcb5c924971f6790b1c32f114e032dc605086852106f8fab35c05db78914

Contents?: true

Size: 1.63 KB

Versions: 88

Compression:

Stored size: 1.63 KB

Contents

module Arel
  module Visitors
    class MySQL < Arel::Visitors::ToSql
      private
      def visit_Arel_Nodes_Union o, suppress_parens = false
        left_result = case o.left
                      when Arel::Nodes::Union
                        visit_Arel_Nodes_Union o.left, true
                      else
                        visit o.left
                      end

        right_result = case o.right
                       when Arel::Nodes::Union
                         visit_Arel_Nodes_Union o.right, true
                       else
                         visit o.right
                       end

        if suppress_parens
          "#{left_result} UNION #{right_result}"
        else
          "( #{left_result} UNION #{right_result} )"
        end
      end

      def visit_Arel_Nodes_Bin o
        "BINARY #{visit o.expr}"
      end

      ###
      # :'(
      # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
      def visit_Arel_Nodes_SelectStatement o
        o.limit = Arel::Nodes::Limit.new(18446744073709551615) if o.offset && !o.limit
        super
      end

      def visit_Arel_Nodes_SelectCore o
        o.froms ||= Arel.sql('DUAL')
        super
      end

      def visit_Arel_Nodes_UpdateStatement o
        [
          "UPDATE #{visit o.relation}",
          ("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
          ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
          ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
          (visit(o.limit) if o.limit),
        ].compact.join ' '
      end

    end
  end
end

Version data entries

88 entries across 70 versions & 13 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/arel-3.0.3/lib/arel/visitors/mysql.rb
arel-3.0.3 lib/arel/visitors/mysql.rb
challah-1.0.0 vendor/bundle/gems/arel-4.0.0/lib/arel/visitors/mysql.rb
swipe-rails-0.0.5 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
challah-1.0.0.beta3 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
arel-4.0.0 lib/arel/visitors/mysql.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/arel-3.0.2/lib/arel/visitors/mysql.rb
challah-1.0.0.beta2 vendor/bundle/gems/arel-3.0.2/lib/arel/visitors/mysql.rb