summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:31:18 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:31:18 +0100
commit9eefae69171ba199d34bccf504902500a980fcb3 (patch)
tree5b4a70ccd2ecc0947d2d04e0d7ff26e59952d51d
parentcc11c44ba997eb32dfa48ea225ae4c6942bc8610 (diff)
downloadgitlab-ce-9eefae69171ba199d34bccf504902500a980fcb3.tar.gz
Fix UNION syntax for MySQL
Apparently MySQL doesn't support this syntax: (...) UNION (...) instead it only supports: ... UNION ...
-rw-r--r--lib/gitlab/sql/union.rb4
-rw-r--r--spec/lib/gitlab/sql/union_spec.rb2
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/gitlab/sql/union.rb b/lib/gitlab/sql/union.rb
index 1a62eff0b31..1cd89b3a9c4 100644
--- a/lib/gitlab/sql/union.rb
+++ b/lib/gitlab/sql/union.rb
@@ -23,11 +23,11 @@ module Gitlab
# (thus fixing this problem), at a slight performance cost.
fragments = ActiveRecord::Base.connection.unprepared_statement do
@relations.map do |rel|
- "(#{rel.reorder(nil).to_sql})"
+ rel.reorder(nil).to_sql
end
end
- fragments.join(' UNION ')
+ fragments.join("\nUNION\n")
end
end
end
diff --git a/spec/lib/gitlab/sql/union_spec.rb b/spec/lib/gitlab/sql/union_spec.rb
index 976360af9b5..9e1cd4419e0 100644
--- a/spec/lib/gitlab/sql/union_spec.rb
+++ b/spec/lib/gitlab/sql/union_spec.rb
@@ -10,7 +10,7 @@ describe Gitlab::SQL::Union do
sql1 = rel1.reorder(nil).to_sql
sql2 = rel2.reorder(nil).to_sql
- expect(union.to_sql).to eq("(#{sql1}) UNION (#{sql2})")
+ expect(union.to_sql).to eq("#{sql1}\nUNION\n#{sql2}")
end
end
end