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 :LIKE, :'NOT LIKE' sql << '(' literal_append(sql, args[0]) sql << ' ' << op.to_s << ' ' literal_append(sql, args[1]) sql << ')' 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 152 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 166 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 171 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 176 def into(table) clone(:into => table) end
Access does not support derived column lists.
# File lib/sequel/adapters/shared/access.rb, line 181 def supports_derived_column_lists? false end
Access doesn't support INTERSECT or EXCEPT
# File lib/sequel/adapters/shared/access.rb, line 186 def supports_intersect_except? false end
Access does not support IS TRUE
# File lib/sequel/adapters/shared/access.rb, line 191 def supports_is_true? false end
Access doesn't support JOIN USING
# File lib/sequel/adapters/shared/access.rb, line 196 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 201 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 206 def truncate delete nil end
Private Instance Methods
Access uses # to quote dates
# File lib/sequel/adapters/shared/access.rb, line 214 def literal_date(d) d.strftime('#%Y-%m-%d#') end
Access uses # to quote datetimes
# File lib/sequel/adapters/shared/access.rb, line 219 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 225 def literal_false '0' end
Use -1 for true on MSSQL
# File lib/sequel/adapters/shared/access.rb, line 230 def literal_true '-1' end
Emulate the char_length function with len
# File lib/sequel/adapters/shared/access.rb, line 235 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 281 def quoted_identifier_append(sql, v) sql << '[' << v.to_s << ']' end
Access requires parentheses when joining more than one table
# File lib/sequel/adapters/shared/access.rb, line 244 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 254 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 262 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 272 def select_limit_sql(sql) if l = @opts[:limit] sql << " TOP " literal_append(sql, l) end end