]> source.dussan.org Git - redmine.git/commitdiff
SQL error with MySQL (#19657).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 30 Sep 2015 20:59:47 +0000 (20:59 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 30 Sep 2015 20:59:47 +0000 (20:59 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14633 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/enumeration.rb
lib/redmine/database.rb

index 4f5e1e37728270e3f3b4979bc5597fa8a53028d1..2ec96dc1fa4091f97cd09874ff0b26bcba821333 100644 (file)
@@ -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
index d8b4b7ccbca315b6666b8471da8076b04a496158..89a80129bb6473296caa7886d6b80962198d96ff 100644 (file)
@@ -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 ' : '')