match_adapters.patch

Pavel Rosick√Ĺ, 2018-06-04 02:18

Download (3.23 KB)

View differences:

database.rb (working copy)
21 21
    class << self
22 22
      # Returns true if the database is PostgreSQL
23 23
      def postgresql?
24
        (ActiveRecord::Base.connection.adapter_name =~ /postgresql/i).present?
24
        /postgresql/i.match?(ActiveRecord::Base.connection.connection.adapter_name)
25 25
      end
26 26

  
27 27
      # Returns the PostgreSQL version or nil if another DBMS is used
......
46 46

  
47 47
      # Returns true if the database is MySQL
48 48
      def mysql?
49
        (ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present?
49
        /mysql/i.match?(ActiveRecord::Base.connection.connection.adapter_name)
50 50
      end
51 51

  
52 52
      # Returns a SQL statement for case/accent (if possible) insensitive match
nested_set/issue_nested_set.rb (working copy)
84 84
        if parent
85 85
          previous_root_id = root_id
86 86
          self.root_id = parent.root_id
87
          
87

  
88 88
          lft_after_move = target_lft
89 89
          self.class.where(:root_id => parent.root_id).update_all([
90 90
            "lft = CASE WHEN lft >= :lft THEN lft + :shift ELSE lft END, " +
91 91
            "rgt = CASE WHEN rgt >= :lft THEN rgt + :shift ELSE rgt END",
92 92
            {:lft => lft_after_move, :shift => (rgt - lft + 1)}
93 93
          ])
94
    
94

  
95 95
          self.class.where(:root_id => previous_root_id).update_all([
96 96
            "root_id = :root_id, lft = lft + :shift, rgt = rgt + :shift",
97 97
            {:root_id => parent.root_id, :shift => lft_after_move - lft}
98 98
          ])
99
    
99

  
100 100
          self.lft, self.rgt = lft_after_move, (rgt - lft + lft_after_move)
101 101
          parent.send :reload_nested_set_values
102 102
        end
......
105 105
      def remove_from_nested_set
106 106
        self.class.where(:root_id => root_id).where("lft >= ? AND rgt <= ?", lft, rgt).
107 107
          update_all(["root_id = :id, lft = lft - :shift, rgt = rgt - :shift", {:id => id, :shift => lft - 1}])
108
    
108

  
109 109
        self.class.where(:root_id => root_id).update_all([
110 110
          "lft = CASE WHEN lft >= :lft THEN lft - :shift ELSE lft END, " +
111 111
          "rgt = CASE WHEN rgt >= :lft THEN rgt - :shift ELSE rgt END",
......
149 149
      end
150 150

  
151 151
      def lock_nested_set
152
        if self.class.connection.adapter_name =~ /sqlserver/i
152
        if /sqlserver/i.match?(self.class.connection.adapter_name)
153 153
          lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
154 154
          # Custom lock for SQLServer
155 155
          # This can be problematic if root_id or parent root_id changes
nested_set/project_nested_set.rb (working copy)
119 119

  
120 120
      def lock_nested_set
121 121
        lock = true
122
        if self.class.connection.adapter_name =~ /sqlserver/i
122
        if /sqlserver/i.match?(self.class.connection.adapter_name)
123 123
          lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
124 124
        end
125 125
        self.class.order(:id).lock(lock).ids