Class: Arel::Visitors::DB2

Inherits:
ToSql
  • Object
show all
Defined in:
lib/arel/visitors/db2.rb

Instance Method Summary collapse

Instance Method Details

#visit_Arel_Nodes_InsertStatement(o, a = nil) ⇒ Object

AR 4.0 ... AREL 5.0 since AR >= 4.1



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/arel/visitors/db2.rb', line 101

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) ⇒ Object



48
49
50
# 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) ⇒ Object



52
53
54
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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