From 8eb1e94f4d18a8e3d268392aa518b039dbc749c0 2015-09-30 20:59:47 From: Jean-Philippe Lang Date: 2015-09-30 20:59:47 Subject: [PATCH] SQL error with MySQL (#19657). git-svn-id: http://svn.redmine.org/redmine/trunk@14633 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index 4f5e1e3..2ec96dc 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -133,9 +133,14 @@ class Enumeration < ActiveRecord::Base # get the same position as the overriden enumeration def reset_positions_in_list super - self.class. - where("parent_id IS NOT NULL"). - update_all("position = (SELECT MIN(position) FROM #{self.class.table_name} p WHERE p.id = #{self.class.table_name}.parent_id)") + # TODO: no database specific statement + if Redmine::Database.mysql? + self.class.connection.execute("UPDATE #{self.class.table_name} c JOIN #{self.class.table_name} p on p.id = c.parent_id SET c.position = p.position") + else + self.class. + where("parent_id IS NOT NULL"). + update_all("position = (SELECT MIN(position) FROM #{self.class.table_name} p WHERE p.id = #{self.class.table_name}.parent_id)") + end end private diff --git a/lib/redmine/database.rb b/lib/redmine/database.rb index d8b4b7c..89a8012 100644 --- a/lib/redmine/database.rb +++ b/lib/redmine/database.rb @@ -44,6 +44,11 @@ module Redmine end end + # Returns true if the database is MySQL + def mysql? + (ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present? + end + # Returns a SQL statement for case/accent (if possible) insensitive match def like(left, right, options={}) neg = (options[:match] == false ? 'NOT ' : '')