3 class MsSQLCompiler < GenericCompiler
5 projections = @relation.projections
6 offset = relation.skipped
8 if Count === projections.first && projections.size == 1 &&
9 (relation.taken.present? || relation.wheres.present?) && relation.joins(self).blank?
11 "SELECT * FROM #{relation.from_clauses}", build_clauses
13 @engine.connection.add_limit_offset!(subquery, :limit => limit, :offset => offset) if offset || limit
14 query = "SELECT COUNT(*) AS count_id FROM (#{subquery}) AS subquery"
17 "SELECT #{relation.select_clauses.join(', ')}",
18 "FROM #{relation.from_clauses}",
21 @engine.connection.add_limit_offset!(query, :limit => limit, :offset => offset) if offset || limit
27 joins = relation.joins(self)
28 wheres = relation.where_clauses
29 groups = relation.group_clauses
30 havings = relation.having_clauses
31 orders = relation.order_clauses
35 ("WHERE #{wheres.join(' AND ')}" unless wheres.empty?),
36 ("GROUP BY #{groups.join(', ')}" unless groups.empty?),
37 ("HAVING #{havings.join(' AND ')}" unless havings.empty?),
38 ("ORDER BY #{orders.join(', ')}" unless orders.empty?)
41 clauses << " #{locked}" unless locked.blank?
42 clauses unless clauses.blank?