Class: Arel::Visitors::SybaseJtds

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

Instance Method Summary collapse

Instance Method Details

#limit_and_no_offset(sql, limit) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/arel/visitors/sybase_jtds.rb', line 28

def limit_and_no_offset sql, limit
  if sql =~ /DISTINCT /i
    sql.gsub!(/DISTINCT /i, "DISTINCT TOP #{limit} ")
  else
    sql.gsub!(/SELECT /, "SELECT TOP #{limit} ")
  end
end

#select_count?(o) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/arel/visitors/sybase_jtds.rb', line 5

def select_count? o
  sel = o.cores.length == 1 && o.cores.first
  projections = sel.projections.length == 1 && sel.projections
  Arel::Nodes::Count === (projections.respond_to?(:first) && projections.first)
end

#visit_Arel_Nodes_SelectStatement(o) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arel/visitors/sybase_jtds.rb', line 12

def visit_Arel_Nodes_SelectStatement o
  if o.offset || (o.limit && select_count?(o))
    o.offset.expr += 1 if o.offset
    sql = super  # if offset OR (limit & count) use the Java limit/offset/count parser
  elsif o.limit
    limit  = o.limit.expr
    o.limit = nil
    sql = super
    limit_and_no_offset sql, limit
  else
    sql = super
  end

  sql
end