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
38 39 40 41 42 43 44 45 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 38 def complex_expression_sql(op, args) case op when :'||' super(:+, args) else super(op, args) end end |
#full_text_search(cols, terms, opts = {}) ⇒ Object
47 48 49 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 47 def full_text_search(cols, terms, opts = {}) filter("CONTAINS (#{literal(cols)}, #{literal(terms)})") end |
#nolock ⇒ Object
Allows you to do .nolock on a query
52 53 54 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 52 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.
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/sequel_core/adapters/shared/mssql.rb', line 58 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 |