Class: Arel::Visitors::Firebird

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

Instance Method Summary collapse

Methods included from ArJdbcCompat

#limit_for

Instance Method Details

#visit_Arel_Nodes_SelectStatement(o) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/arel/visitors/firebird.rb', line 6

def visit_Arel_Nodes_SelectStatement o
  lim_off = [
    ("FIRST #{visit(o.limit.expr)}" if o.limit),
    ("SKIP #{visit(o.offset.expr)}" if o.offset)
  ].compact.join(' ').strip

  sql = [
   o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
   ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
  ].compact.join ' '

  sql.sub!(/\A(\s*SELECT\s)/i, '\&' + lim_off + ' ') unless lim_off.empty?

  sql
end