Class: Arel::SelectManager

Inherits:
TreeManager
  • Object
show all
Defined in:
lib/arel/select_manager_sqlserver.rb

Constant Summary collapse

AR_CA_SQLSA_NAME =
'ActiveRecord::ConnectionAdapters::SQLServerAdapter'.freeze

Instance Method Summary collapse

Instance Method Details

#lock(locking = true) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arel/select_manager_sqlserver.rb', line 40

def lock(locking = true)
  if engine_activerecord_sqlserver_adapter?
    case locking
    when true
      locking = Arel.sql('WITH(HOLDLOCK, ROWLOCK)')
    when Arel::Nodes::SqlLiteral
    when String
      locking = Arel.sql locking
    end
    @ast.lock = Arel::Nodes::Lock.new(locking)
    self
  else
    lock_without_sqlserver(locking)
  end
end

#lock_without_sqlserverObject

A friendly over ride that allows us to put a special lock object that can have a default or pass custom string hints down. See the visit_Arel_Nodes_LockWithSQLServer delegation method.



39
# File 'lib/arel/select_manager_sqlserver.rb', line 39

alias_method :lock_without_sqlserver, :lock

#order(*expr) ⇒ Object



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
35
# File 'lib/arel/select_manager_sqlserver.rb', line 10

def order(*expr)
  return order_without_sqlserver(*expr) unless engine_activerecord_sqlserver_adapter?
  @ast.orders.concat(expr.map do |x|
    case x
    when Arel::Attributes::Attribute
      table = Arel::Table.new(x.relation.table_alias || x.relation.name)
      e = table[x.name]
      Arel::Nodes::Ascending.new e
    when Arel::Nodes::Ordering
      x
    when String
      x.split(',').map do |s|
        s = x if x.strip =~ /\A\b\w+\b\(.*,.*\)(\s+(ASC|DESC))?\Z/i # Allow functions with comma(s) to pass thru.
        s.strip!
        d = s =~ /(ASC|DESC)\Z/i ? Regexp.last_match[1].upcase : nil
        e = d.nil? ? s : s.mb_chars[0...-d.length].strip
        e = Arel.sql(e)
        d && d == 'DESC' ? Arel::Nodes::Descending.new(e) : Arel::Nodes::Ascending.new(e)
      end
    else
      e = Arel.sql(x.to_s)
      Arel::Nodes::Ascending.new e
    end
  end.flatten)
  self
end

#order_without_sqlserverObject

Getting real Ordering objects is very important for us. We need to be able to call #uniq on a colleciton of them reliably as well as using their true object attributes to mutate them to grouping objects for the inner sql during a select statment with an offset/rownumber. So this is here till ActiveRecord & ARel does this for us instead of using SqlLiteral objects.



9
# File 'lib/arel/select_manager_sqlserver.rb', line 9

alias_method :order_without_sqlserver, :order