module Sequel::Access
Constants
- CAST_TYPES
- EXTRACT_MAP
- OPS
Public Instance Methods
Access doesn't support CASE, so emulate it with nested IIF function calls.
# File lib/sequel/adapters/shared/access.rb, line 93 def case_expression_sql_append(sql, ce) literal_append(sql, ce.with_merged_expression.conditions.reverse.inject(ce.default){|exp,(cond,val)| Sequel::SQL::Function.new(:IIF, cond, val, exp)}) end
Access doesn't support CAST, it uses separate functions for type conversion
# File lib/sequel/adapters/shared/access.rb, line 99 def cast_sql_append(sql, expr, type) sql << CAST_TYPES.fetch(type, type).to_s sql << '(' literal_append(sql, expr) sql << ')' end
# File lib/sequel/adapters/shared/access.rb, line 106 def complex_expression_sql_append(sql, op, args) case op when :ILIKE complex_expression_sql_append(sql, :LIKE, args) when :'NOT ILIKE' complex_expression_sql_append(sql, :'NOT LIKE', args) when :'!=' sql << '(' literal_append(sql, args[0]) sql << ' <> ' literal_append(sql, args[1]) sql << ')' when :'%', :'||' sql << '(' c = false op_str = OPS[op] args.each do |a| sql << op_str if c literal_append(sql, a) c ||= true end sql << ')' when :** sql << '(' literal_append(sql, args[0]) sql << ' ^ ' literal_append(sql, args[1]) sql << ')' when :extract part = args[0] raise(Sequel::Error, "unsupported extract argument: #{part.inspect}") unless format = EXTRACT_MAP[part] sql << "datepart(" << format.to_s << ', ' literal_append(sql, args[1]) sql << ')' else super end end
Use Date(), Now(), and Time() for CURRENT_DATE, CURRENT_TIMESTAMP, and CURRENT_TIME
# File lib/sequel/adapters/shared/access.rb, line 146 def constant_sql_append(sql, constant) case constant when :CURRENT_DATE sql << 'Date()' when :CURRENT_TIMESTAMP sql << 'Now()' when :CURRENT_TIME sql << 'Time()' else super end end
Emulate cross join by using multiple tables in the FROM clause.
# File lib/sequel/adapters/shared/access.rb, line 160 def cross_join(table) clone(:from=>@opts[:from] + [table]) end
Access uses [] to escape metacharacters, instead of backslashes.
# File lib/sequel/adapters/shared/access.rb, line 165 def escape_like(string) string.gsub(/[\\*#?\[]/){|m| "[#{m}]"} end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/access.rb, line 170 def into(table) clone(:into => table) end
Access does not support derived column lists.
# File lib/sequel/adapters/shared/access.rb, line 175 def supports_derived_column_lists? false end
Access doesn't support INTERSECT or EXCEPT
# File lib/sequel/adapters/shared/access.rb, line 180 def supports_intersect_except? false end
Access does not support IS TRUE
# File lib/sequel/adapters/shared/access.rb, line 185 def supports_is_true? false end
Access doesn't support JOIN USING
# File lib/sequel/adapters/shared/access.rb, line 190 def supports_join_using? false end
Access does not support multiple columns for the IN/NOT IN operators
# File lib/sequel/adapters/shared/access.rb, line 195 def supports_multiple_column_in? false end
Access doesn't support truncate, so do a delete instead.
# File lib/sequel/adapters/shared/access.rb, line 200 def truncate delete nil end
Private Instance Methods
Access uses # to quote dates
# File lib/sequel/adapters/shared/access.rb, line 208 def literal_date(d) d.strftime('#%Y-%m-%d#') end
Access uses # to quote datetimes
# File lib/sequel/adapters/shared/access.rb, line 213 def literal_datetime(t) t.strftime('#%Y-%m-%d %H:%M:%S#') end
Use 0 for false on MSSQL
# File lib/sequel/adapters/shared/access.rb, line 219 def literal_false '0' end
Use -1 for true on MSSQL
# File lib/sequel/adapters/shared/access.rb, line 224 def literal_true '-1' end
Emulate the char_length function with len
# File lib/sequel/adapters/shared/access.rb, line 229 def native_function_name(emulated_function) if emulated_function == :char_length 'len' else super end end
Access uses [] for quoting identifiers, and can't handle ] inside identifiers.
# File lib/sequel/adapters/shared/access.rb, line 285 def quoted_identifier_append(sql, v) sql << '[' << v.to_s << ']' end
Access does not natively support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/access.rb, line 238 def requires_emulating_nulls_first? true end
Access doesn't support ESCAPE for LIKE.
# File lib/sequel/adapters/shared/access.rb, line 243 def requires_like_escape? false end
Access requires parentheses when joining more than one table
# File lib/sequel/adapters/shared/access.rb, line 248 def select_from_sql(sql) if f = @opts[:from] sql << ' FROM ' if (j = @opts[:join]) && !j.empty? sql << ('(' * j.length) end source_list_append(sql, f) end end
# File lib/sequel/adapters/shared/access.rb, line 258 def select_into_sql(sql) if i = @opts[:into] sql << " INTO " identifier_append(sql, i) end end
Access requires parentheses when joining more than one table
# File lib/sequel/adapters/shared/access.rb, line 266 def select_join_sql(sql) if js = @opts[:join] js.each do |j| literal_append(sql, j) sql << ')' end end end
Access uses TOP for limits
# File lib/sequel/adapters/shared/access.rb, line 276 def select_limit_sql(sql) if l = @opts[:limit] sql << " TOP " literal_append(sql, l) end end