Class: Arel::Visitors::Firebird

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

Instance Method Summary collapse

Instance Method Details

#visit_Arel_Nodes_Limit(o, a) ⇒ Object



36
37
38
# File 'lib/arel/visitors/firebird.rb', line 36

def visit_Arel_Nodes_Limit(o, a)
  a << "FIRST #{limit_for(o)}"
end

#visit_Arel_Nodes_Offset(o, a) ⇒ Object



40
41
42
# File 'lib/arel/visitors/firebird.rb', line 40

def visit_Arel_Nodes_Offset(o, a)
  a << 'SKIP '; visit(o.value, a)
end

#visit_Arel_Nodes_SelectStatement(o, a = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arel/visitors/firebird.rb', line 8

def visit_Arel_Nodes_SelectStatement(o, a)
  a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }

  limit, offset = o.limit, o.offset
  if limit || offset
    select = a.parts[0]

    sql = Arel::Collectors::SQLString.new
    visit(limit, sql) if limit
    if offset
      sql << ' ' if limit
      visit(offset, sql)
    end

    a.parts[0] = "#{select} #{sql.value}"
  end

  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

  a
end