class Arel::Visitors::DB2

Public Instance Methods

visit_Arel_Nodes_InsertStatement(o, a = nil) click to toggle source
# File lib/arel/visitors/db2.rb, line 81
def visit_Arel_Nodes_InsertStatement o, a = nil
  a << "INSERT INTO "
  visit(o.relation, a)

  values = o.values

  if o.columns.any?
    cols = o.columns.map { |x| quote_column_name x.name }
    a << ' (' << cols.join(', ') << ') '
  elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
    cols = o.relation.engine.columns.map { |c| c.name }
    a << ' (' << cols.join(', ') << ')'
    a << ' VALUES '
    a << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
    values = false
  end
  visit(values, a) if values
  a
end
visit_Arel_Nodes_Limit(o, collector) click to toggle source
# File lib/arel/visitors/db2.rb, line 48
def visit_Arel_Nodes_Limit o, collector
  # visit o.expr, collector
end
visit_Arel_Nodes_Offset(o, collector) click to toggle source
# File lib/arel/visitors/db2.rb, line 52
def visit_Arel_Nodes_Offset o, collector
  # visit o.expr, collector
end
visit_Arel_Nodes_SelectStatement(o, a = nil) click to toggle source
# File lib/arel/visitors/db2.rb, line 19
def visit_Arel_Nodes_SelectStatement(o, a = nil)
  a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }

  unless o.orders.empty?
    a << ' ORDER BY '
    last = o.orders.length - 1
    o.orders.each_with_index do |x, i|
      visit(x, a);  a << ', ' unless last == i
    end
  end

  if limit = o.limit
    if limit = limit.value
      limit = limit.to_i
    end
  end
  if offset = o.offset
    if offset = offset.value
      offset = offset.to_i
    end
  end

  if limit || offset
    add_limit_offset(a, o, limit, offset)
  else
    a
  end
end

Private Instance Methods

add_limit_offset(sql, o, limit, offset) click to toggle source
# File lib/arel/visitors/db2.rb, line 127
def add_limit_offset(sql, o, limit, offset)
  @connection.replace_limit_offset! sql, limit, offset, o.orders
end