Class: Arel::Visitors::Derby

Inherits:
ToSql
  • Object
show all
Defined in:
lib/arel/visitors/derby.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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/arel/visitors/derby.rb', line 89

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? 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, a = nil) ⇒ Object



42
43
44
45
46
# File 'lib/arel/visitors/derby.rb', line 42

def visit_Arel_Nodes_Limit(o, a = nil)
  limit = "FETCH FIRST #{limit_for(o)} ROWS ONLY"
  a << limit if a
  limit
end

#visit_Arel_Nodes_Lock(o, a = nil) ⇒ Object

This generates SELECT...FOR UPDATE, but it will only work if the current transaction isolation level is set to SERIALIZABLE. Otherwise, locks aren't held for the entire transaction.



61
62
63
# File 'lib/arel/visitors/derby.rb', line 61

def visit_Arel_Nodes_Lock o, a = nil
  do_visit o.expr, a
end

#visit_Arel_Nodes_Offset(o, a = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/arel/visitors/derby.rb', line 48

def visit_Arel_Nodes_Offset(o, a = nil)
  if a
    a << 'OFFSET '
    do_visit(o.value, a)
    a << ' ROWS'
  else
    "OFFSET #{do_visit o.value, a} ROWS"
  end
end

#visit_Arel_Nodes_SelectStatement(o, a = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/arel/visitors/derby.rb', line 11

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 o.offset
    a << STR_1; visit(o.offset, a)
  end
  if o.limit
    a << STR_1; visit(o.limit, a)
  end
  if o.lock
    a << STR_1; visit(o.lock, a)
  end
  a
end