Class: Arel::SelectManager

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#lock(locking = true) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/arel/visitors/sqlserver.rb', line 62

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.



61
# File 'lib/arel/visitors/sqlserver.rb', line 61

alias :lock_without_sqlserver :lock

#order(*expr) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/arel/visitors/sqlserver.rb', line 32

def order(*expr)
  return order_without_sqlserver(*expr) unless engine_activerecord_sqlserver_adapter?
  @ast.orders.concat(expr.map{ |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 ? $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
  }.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.



31
# File 'lib/arel/visitors/sqlserver.rb', line 31

alias :order_without_sqlserver :order