aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@squareup.com>2015-02-23 09:58:22 -0800
committerTamir Duberstein <tamird@squareup.com>2015-02-23 09:58:22 -0800
commitd86e20ccbea226bb6e42da508bc040fd03ab473f (patch)
treeb0fd958a2a7cdb947ffb8ce1e933c531941fea3a /lib
parent65135d00a854edfd1684f5163db8e68fdb956ae0 (diff)
downloadrails-d86e20ccbea226bb6e42da508bc040fd03ab473f.tar.gz
rails-d86e20ccbea226bb6e42da508bc040fd03ab473f.tar.bz2
rails-d86e20ccbea226bb6e42da508bc040fd03ab473f.zip
Special limited delete handling in MSSQL
Refernce: https://technet.microsoft.com/en-us/library/ms175486%28v=sql.105%29.aspx
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/visitors/mssql.rb17
-rw-r--r--lib/arel/visitors/to_sql.rb4
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/arel/visitors/mssql.rb b/lib/arel/visitors/mssql.rb
index 7c65ad33f2..92362a0c5f 100644
--- a/lib/arel/visitors/mssql.rb
+++ b/lib/arel/visitors/mssql.rb
@@ -66,6 +66,23 @@ module Arel
end
end
+ def visit_Arel_Nodes_DeleteStatement o, collector
+ collector << 'DELETE '
+ if o.limit
+ collector << 'TOP ('
+ visit o.limit.expr, collector
+ collector << ') '
+ end
+ collector << 'FROM '
+ collector = visit o.relation, collector
+ if o.wheres.any?
+ collector << ' WHERE '
+ inject_join o.wheres, collector, AND
+ else
+ collector
+ end
+ end
+
def determine_order_by orders, x
if orders.any?
orders
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 6084f5746c..ba176a552c 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -74,10 +74,10 @@ module Arel
end
def visit_Arel_Nodes_DeleteStatement o, collector
- collector << "DELETE FROM "
+ collector << 'DELETE FROM '
collector = visit o.relation, collector
if o.wheres.any?
- collector << " WHERE "
+ collector << ' WHERE '
collector = inject_join o.wheres, collector, AND
end