Class: Sequel::ODBC::MSSQL::Dataset

Inherits:
Dataset show all
Defined in:
lib/sequel/adapters/odbc_mssql.rb

Constant Summary

Constants inherited from Dataset

Dataset::BOOL_FALSE, Dataset::BOOL_TRUE

Constants inherited from Dataset

Dataset::NOTIMPL_MSG, Dataset::STOCK_TRANSFORMS

Constants included from Dataset::Convenience

Dataset::Convenience::COMMA_SEPARATOR, Dataset::Convenience::MAGIC_METHODS, Dataset::Convenience::MUTATION_RE, Dataset::Convenience::NAKED_HASH

Constants included from Dataset::SQL

Dataset::SQL::ALIASED_REGEXP, Dataset::SQL::AND_SEPARATOR, Dataset::SQL::COMMA_SEPARATOR, Dataset::SQL::DATE_FORMAT, Dataset::SQL::FALSE, Dataset::SQL::JOIN_TYPES, Dataset::SQL::NULL, Dataset::SQL::QUALIFIED_REGEXP, Dataset::SQL::QUESTION_MARK, Dataset::SQL::STOCK_COUNT_OPTS, Dataset::SQL::TIMESTAMP_FORMAT, Dataset::SQL::TRUE, Dataset::SQL::WILDCARD

Constants included from Dataset::Sequelizer

Dataset::Sequelizer::JOIN_AND, Dataset::Sequelizer::JOIN_COMMA

Instance Attribute Summary

Attributes inherited from Dataset

#db, #opts

Attributes included from Dataset::Convenience

#current_page, #page_count, #page_size, #pagination_record_count

Instance Method Summary collapse

Methods inherited from Dataset

#array_tuples_fetch_rows, #array_tuples_make_row, #convert_odbc_value, #delete, #fetch_rows, #hash_row, #insert, #literal, #update

Methods inherited from Dataset

#<<, #clone_merge, #columns, dataset_classes, #delete, #each, #extend_with_destroy, #fetch_rows, inherited, #initialize, #insert, #model_classes, #naked, #polymorphic_key, #remove_row_proc, #set, #set_model, #set_options, #set_row_proc, #transform, #transform_load, #transform_save, #update, #update_each_method

Methods included from Dataset::Convenience

#[], #[]=, #avg, #create_or_replace_view, #create_view, #current_page_record_count, #current_page_record_range, #each_hash, #empty?, #first, #group_and_count, #interval, #last, #magic_method_missing, #map, #max, #method_missing, #min, #multi_insert, #next_page, #page_range, #paginate, #prev_page, #print, #query, #range, #set_pagination_info, #single_record, #single_value, #sum, #to_csv, #to_hash

Methods included from Dataset::SQL

#and, #column_list, #count, #delete_sql, #except, #exclude, #exists, #expression_list, #filter, #from, #full_outer_join, #group, #having, #inner_join, #insert_multiple, #insert_sql, #intersect, #invert_order, #join_expr, #join_table, #left_outer_join, #limit, #literal, #or, #order, #qualified_column_name, #quote_column_ref, #reverse_order, #right_outer_join, #select, #source_list, #to_table_reference, #union, #uniq, #update_sql, #where

Methods included from Dataset::Sequelizer

#call_expr, #compare_expr, #eval_expr, #ext_expr, #fcall_expr, #iter_expr, #match_expr, #proc_to_sql, #pt_expr, #replace_dvars, #unfold_each_expr, #value_to_parse_tree, #vcall_expr

Methods included from Enumerable

#send_each

Constructor Details

This class inherits a constructor from Sequel::Dataset

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sequel::Dataset::Convenience

Instance Method Details

#nolockObject

Allows you to do .nolock on a query



18
19
20
# File 'lib/sequel/adapters/odbc_mssql.rb', line 18

def nolock
  clone_merge(:with => "(NOLOCK)")
end

#select_sql(opts = nil) ⇒ Object Also known as: sql

Formats a SELECT statement using the given options and the dataset options.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
# File 'lib/sequel/adapters/odbc_mssql.rb', line 24

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]
  select_columns = columns ? column_list(columns) : WILDCARD

  if distinct = opts[:distinct]
    distinct_clause = distinct.empty? ? "DISTINCT" : "DISTINCT ON (#{column_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]
    sql << join
  end

  if where = opts[:where]
    sql << " WHERE #{where}"
  end

  if group = opts[:group]
    sql << " GROUP BY #{column_list(group)}"
  end

  if order = opts[:order]
    sql << " ORDER BY #{column_list(order)}"
  end

  if having = opts[:having]
    sql << " HAVING #{having}"
  end

  if union = opts[:union]
    sql << (opts[:union_all] ? \
      " UNION ALL #{union.sql}" : " UNION #{union.sql}")
  elsif intersect = opts[:intersect]
    sql << (opts[:intersect_all] ? \
      " INTERSECT ALL #{intersect.sql}" : " INTERSECT #{intersect.sql}")
  elsif except = opts[:except]
    sql << (opts[:except_all] ? \
      " EXCEPT ALL #{except.sql}" : " EXCEPT #{except.sql}")
  end

  sql
end