1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #33977 from marshall-lee/abandon-top-support

Abandon TOP support.
This commit is contained in:
Ryuta Kamizono 2018-09-25 22:00:07 +09:00 committed by GitHub
commit 4f12139a22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 4 additions and 27 deletions

View file

@ -3,13 +3,12 @@
module Arel # :nodoc: all module Arel # :nodoc: all
module Nodes module Nodes
class SelectCore < Arel::Nodes::Node class SelectCore < Arel::Nodes::Node
attr_accessor :top, :projections, :wheres, :groups, :windows attr_accessor :projections, :wheres, :groups, :windows
attr_accessor :havings, :source, :set_quantifier attr_accessor :havings, :source, :set_quantifier
def initialize def initialize
super() super()
@source = JoinSource.new nil @source = JoinSource.new nil
@top = nil
# https://ronsavage.github.io/SQL/sql-92.bnf.html#set%20quantifier # https://ronsavage.github.io/SQL/sql-92.bnf.html#set%20quantifier
@set_quantifier = nil @set_quantifier = nil
@ -43,7 +42,7 @@ module Arel # :nodoc: all
def hash def hash
[ [
@source, @top, @set_quantifier, @projections, @source, @set_quantifier, @projections,
@wheres, @groups, @havings, @windows @wheres, @groups, @havings, @windows
].hash ].hash
end end
@ -51,7 +50,6 @@ module Arel # :nodoc: all
def eql?(other) def eql?(other)
self.class == other.class && self.class == other.class &&
self.source == other.source && self.source == other.source &&
self.top == other.top &&
self.set_quantifier == other.set_quantifier && self.set_quantifier == other.set_quantifier &&
self.projections == other.projections && self.projections == other.projections &&
self.wheres == other.wheres && self.wheres == other.wheres &&

View file

@ -37,7 +37,6 @@ module Arel # :nodoc: all
On On
Ordering Ordering
RollUp RollUp
Top
}.each do |name| }.each do |name|
const_set(name, Class.new(Unary)) const_set(name, Class.new(Unary))
end end

View file

@ -222,10 +222,8 @@ module Arel # :nodoc: all
def take(limit) def take(limit)
if limit if limit
@ast.limit = Nodes::Limit.new(limit) @ast.limit = Nodes::Limit.new(limit)
@ctx.top = Nodes::Top.new(limit)
else else
@ast.limit = nil @ast.limit = nil
@ctx.top = nil
end end
self self
end end

View file

@ -34,7 +34,6 @@ module Arel # :nodoc: all
alias :visit_Arel_Nodes_Ordering :unary alias :visit_Arel_Nodes_Ordering :unary
alias :visit_Arel_Nodes_Ascending :unary alias :visit_Arel_Nodes_Ascending :unary
alias :visit_Arel_Nodes_Descending :unary alias :visit_Arel_Nodes_Descending :unary
alias :visit_Arel_Nodes_Top :unary
alias :visit_Arel_Nodes_UnqualifiedColumn :unary alias :visit_Arel_Nodes_UnqualifiedColumn :unary
def function(o) def function(o)

View file

@ -81,7 +81,6 @@ module Arel # :nodoc: all
alias :visit_Arel_Nodes_Not :unary alias :visit_Arel_Nodes_Not :unary
alias :visit_Arel_Nodes_Offset :unary alias :visit_Arel_Nodes_Offset :unary
alias :visit_Arel_Nodes_On :unary alias :visit_Arel_Nodes_On :unary
alias :visit_Arel_Nodes_Top :unary
alias :visit_Arel_Nodes_UnqualifiedColumn :unary alias :visit_Arel_Nodes_UnqualifiedColumn :unary
alias :visit_Arel_Nodes_Preceding :unary alias :visit_Arel_Nodes_Preceding :unary
alias :visit_Arel_Nodes_Following :unary alias :visit_Arel_Nodes_Following :unary

View file

@ -12,13 +12,6 @@ module Arel # :nodoc: all
private private
# `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
# "select top 10 distinct first_name from users", which is invalid query! it should be
# "select distinct top 10 first_name from users"
def visit_Arel_Nodes_Top(o)
""
end
def visit_Arel_Visitors_MSSQL_RowNumber(o, collector) def visit_Arel_Visitors_MSSQL_RowNumber(o, collector)
collector << "ROW_NUMBER() OVER (ORDER BY " collector << "ROW_NUMBER() OVER (ORDER BY "
inject_join(o.children, collector, ", ") << ") as _row_num" inject_join(o.children, collector, ", ") << ") as _row_num"

View file

@ -237,8 +237,6 @@ module Arel # :nodoc: all
def visit_Arel_Nodes_SelectCore(o, collector) def visit_Arel_Nodes_SelectCore(o, collector)
collector << "SELECT" collector << "SELECT"
collector = maybe_visit o.top, collector
collector = maybe_visit o.set_quantifier, collector collector = maybe_visit o.set_quantifier, collector
collect_nodes_for o.projections, collector, SPACE collect_nodes_for o.projections, collector, SPACE
@ -405,11 +403,6 @@ module Arel # :nodoc: all
visit o.expr, collector visit o.expr, collector
end end
# FIXME: this does nothing on most databases, but does on MSSQL
def visit_Arel_Nodes_Top(o, collector)
collector
end
def visit_Arel_Nodes_Lock(o, collector) def visit_Arel_Nodes_Lock(o, collector)
visit o.expr, collector visit o.expr, collector
end end

View file

@ -131,7 +131,7 @@ module Arel
right = table.alias right = table.alias
mgr = table.from mgr = table.from
mgr.join(right).on("omg") mgr.join(right).on("omg")
mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg } mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg }
end end
it "converts to sqlliterals with multiple items" do it "converts to sqlliterals with multiple items" do
@ -139,7 +139,7 @@ module Arel
right = table.alias right = table.alias
mgr = table.from mgr = table.from
mgr.join(right).on("omg", "123") mgr.join(right).on("omg", "123")
mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 } mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 }
end end
end end
end end

View file

@ -33,7 +33,6 @@ module Arel
Arel::Nodes::Ordering, Arel::Nodes::Ordering,
Arel::Nodes::StringJoin, Arel::Nodes::StringJoin,
Arel::Nodes::UnqualifiedColumn, Arel::Nodes::UnqualifiedColumn,
Arel::Nodes::Top,
Arel::Nodes::Limit, Arel::Nodes::Limit,
Arel::Nodes::Else, Arel::Nodes::Else,
].each do |klass| ].each do |klass|

View file

@ -37,7 +37,6 @@ module Arel
Arel::Nodes::Offset, Arel::Nodes::Offset,
Arel::Nodes::Ordering, Arel::Nodes::Ordering,
Arel::Nodes::UnqualifiedColumn, Arel::Nodes::UnqualifiedColumn,
Arel::Nodes::Top,
Arel::Nodes::Limit, Arel::Nodes::Limit,
].each do |klass| ].each do |klass|
define_method("test_#{klass.name.gsub('::', '_')}") do define_method("test_#{klass.name.gsub('::', '_')}") do