Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure limit/offset are cast to integers. Also make sure we return…

… SqlLiteral objects when removing expressions from projections.
  • Loading branch information...
commit 36f860e098fbc0a114e1663e0966ddac84de2a1b 1 parent 4d63805
@metaskills metaskills authored
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/arel/visitors/sqlserver.rb
View
20 lib/arel/visitors/sqlserver.rb
@@ -1,8 +1,22 @@
module Arel
module Nodes
+
class LockWithSQLServer < Arel::Nodes::Unary
end
+
+ class Limit < Arel::Nodes::Unary
+ def initialize expr
+ @expr = expr.to_i
+ end
+ end
+
+ class Offset < Arel::Nodes::Unary
+ def initialize expr
+ @expr = expr.to_i
+ end
+ end
+
end
class SelectManager < Arel::TreeManager
@@ -101,7 +115,7 @@ def visit_Arel_Nodes_SelectStatementForComplexCount(o)
# joins = correlated_safe_joins
core = o.cores.first
orders = rowtable_orders(o)
- o.limit.expr = o.limit.expr.to_i + o.offset.expr.to_i if o.limit
+ o.limit.expr = o.limit.expr + o.offset.expr if o.limit
[ "SELECT COUNT([count]) AS [count_id]",
"FROM (",
"SELECT",
@@ -186,13 +200,13 @@ def rowtable_orders(o)
end
def projection_without_expression(projection)
- projection.to_s.split(',').map do |x|
+ Arel::SqlLiteral.new(projection.split(',').map do |x|
x.strip!
x.sub!(/^(COUNT|SUM|MAX|MIN|AVG)\s*(\((.*)\))?/,'\3')
x.sub!(/^DISTINCT\s*/,'')
x.sub!(/TOP\s*\(\d+\)\s*/i,'')
x.strip
- end.join(', ')
+ end.join(', '))
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.