Module: Sequel::MSSQL::DatasetMethods
- Defined in:
- lib/sequel_core/adapters/shared/mssql.rb
Instance Method Summary collapse
- #complex_expression_sql(op, args) ⇒ Object
- #full_text_search(cols, terms, opts = {}) ⇒ Object
-
#nolock ⇒ Object
Allows you to do .nolock on a query.
-
#select_sql(opts = nil) ⇒ Object
(also: #sql)
Formats a SELECT statement using the given options and the dataset options.
Instance Method Details
#complex_expression_sql(op, args) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 18 def complex_expression_sql(op, args) case op when :'||' super(:+, args) else super(op, args) end end |
#full_text_search(cols, terms, opts = {}) ⇒ Object
27 28 29 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 27 def full_text_search(cols, terms, opts = {}) filter("CONTAINS (#{literal(cols)}, #{literal(terms)})") end |
#nolock ⇒ Object
Allows you to do .nolock on a query
32 33 34 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 32 def nolock clone(:with => "(NOLOCK)") end |
#select_sql(opts = nil) ⇒ Object Also known as: sql
Formats a SELECT statement using the given options and the dataset options.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 38 def select_sql(opts = nil) opts = opts ? @opts.merge(opts) : @opts if sql = opts[:sql] return sql end # ADD TOP to SELECT string for LIMITS if limit = opts[:limit] top = "TOP #{limit} " raise Error, "Offset not supported" if opts[:offset] end columns = opts[:select] # We had to reference const WILDCARD with its full path, because # the Ruby constant scope rules played against us (it was resolving it # as Sequel::Dataset::DatasetMethods::WILDCARD). select_columns = columns ? column_list(columns) : Sequel::Dataset::WILDCARD if distinct = opts[:distinct] distinct_clause = distinct.empty? ? "DISTINCT" : "DISTINCT ON (#{expression_list(distinct)})" sql = "SELECT #{top}#{distinct_clause} #{select_columns}" else sql = "SELECT #{top}#{select_columns}" end if opts[:from] sql << " FROM #{source_list(opts[:from])}" end # ADD WITH to SELECT string for NOLOCK if with = opts[:with] sql << " WITH #{with}" end if join = opts[:join] join.each{|j| sql << literal(j)} end if where = opts[:where] sql << " WHERE #{literal(where)}" end if group = opts[:group] sql << " GROUP BY #{expression_list(group)}" end if order = opts[:order] sql << " ORDER BY #{expression_list(order)}" end if having = opts[:having] sql << " HAVING #{literal(having)}" end if union = opts[:union] sql << (opts[:union_all] ? \ " UNION ALL #{union.sql}" : " UNION #{union.sql}") end raise Error, "Intersect not supported" if opts[:intersect] raise Error, "Except not supported" if opts[:except] sql end |