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_Limit(o, a = nil) ⇒ Object



16
17
18
# File 'lib/arel/visitors/derby.rb', line 16

def visit_Arel_Nodes_Limit o, a = nil
  "FETCH FIRST #{limit_for(o)} ROWS ONLY"
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.



27
28
29
# File 'lib/arel/visitors/derby.rb', line 27

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

#visit_Arel_Nodes_Offset(o, a = nil) ⇒ Object



20
21
22
# File 'lib/arel/visitors/derby.rb', line 20

def visit_Arel_Nodes_Offset o, a = nil
  "OFFSET #{do_visit o.value, a} ROWS"
end

#visit_Arel_Nodes_SelectStatement(o, a = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/arel/visitors/derby.rb', line 7

def visit_Arel_Nodes_SelectStatement o, a = nil
  sql = o.cores.map { |x| do_visit(x, a) }.join
  sql << " ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?
  sql << " #{do_visit o.offset, a}" if o.offset
  sql << " #{do_visit o.limit, a}" if o.limit
  sql << " #{do_visit o.lock, a}" if o.lock
  sql
end