Patch #28940 » match_adapters.patch
| database.rb (working copy) | ||
|---|---|---|
|
class << self
|
||
|
# Returns true if the database is PostgreSQL
|
||
|
def postgresql?
|
||
|
(ActiveRecord::Base.connection.adapter_name =~ /postgresql/i).present?
|
||
|
/postgresql/i.match?(ActiveRecord::Base.connection.connection.adapter_name)
|
||
|
end
|
||
|
# Returns the PostgreSQL version or nil if another DBMS is used
|
||
| ... | ... | |
|
# Returns true if the database is MySQL
|
||
|
def mysql?
|
||
|
(ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present?
|
||
|
/mysql/i.match?(ActiveRecord::Base.connection.connection.adapter_name)
|
||
|
end
|
||
|
# Returns a SQL statement for case/accent (if possible) insensitive match
|
||
| nested_set/issue_nested_set.rb (working copy) | ||
|---|---|---|
|
if parent
|
||
|
previous_root_id = root_id
|
||
|
self.root_id = parent.root_id
|
||
|
|
||
|
lft_after_move = target_lft
|
||
|
self.class.where(:root_id => parent.root_id).update_all([
|
||
|
"lft = CASE WHEN lft >= :lft THEN lft + :shift ELSE lft END, " +
|
||
|
"rgt = CASE WHEN rgt >= :lft THEN rgt + :shift ELSE rgt END",
|
||
|
{:lft => lft_after_move, :shift => (rgt - lft + 1)}
|
||
|
])
|
||
|
|
||
|
self.class.where(:root_id => previous_root_id).update_all([
|
||
|
"root_id = :root_id, lft = lft + :shift, rgt = rgt + :shift",
|
||
|
{:root_id => parent.root_id, :shift => lft_after_move - lft}
|
||
|
])
|
||
|
|
||
|
self.lft, self.rgt = lft_after_move, (rgt - lft + lft_after_move)
|
||
|
parent.send :reload_nested_set_values
|
||
|
end
|
||
| ... | ... | |
|
def remove_from_nested_set
|
||
|
self.class.where(:root_id => root_id).where("lft >= ? AND rgt <= ?", lft, rgt).
|
||
|
update_all(["root_id = :id, lft = lft - :shift, rgt = rgt - :shift", {:id => id, :shift => lft - 1}])
|
||
|
|
||
|
self.class.where(:root_id => root_id).update_all([
|
||
|
"lft = CASE WHEN lft >= :lft THEN lft - :shift ELSE lft END, " +
|
||
|
"rgt = CASE WHEN rgt >= :lft THEN rgt - :shift ELSE rgt END",
|
||
| ... | ... | |
|
end
|
||
|
def lock_nested_set
|
||
|
if self.class.connection.adapter_name =~ /sqlserver/i
|
||
|
if /sqlserver/i.match?(self.class.connection.adapter_name)
|
||
|
lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
|
||
|
# Custom lock for SQLServer
|
||
|
# This can be problematic if root_id or parent root_id changes
|
||
| nested_set/project_nested_set.rb (working copy) | ||
|---|---|---|
|
def lock_nested_set
|
||
|
lock = true
|
||
|
if self.class.connection.adapter_name =~ /sqlserver/i
|
||
|
if /sqlserver/i.match?(self.class.connection.adapter_name)
|
||
|
lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
|
||
|
end
|
||
|
self.class.order(:id).lock(lock).ids
|
||