Module: Sequel::Access::DatasetMethods

Includes:
EmulateOffsetWithReverseAndCount, UnmodifiedIdentifiers::DatasetMethods
Included in:
Sequel::ADO::Access::Dataset
Defined in:
lib/sequel/adapters/shared/access.rb

Constant Summary

EXTRACT_MAP =
{:year=>"'yyyy'", :month=>"'m'", :day=>"'d'", :hour=>"'h'", :minute=>"'n'", :second=>"'s'"}.freeze
OPS =
{:%'=>' Mod '.freeze, :||'=>' & '.freeze}.freeze
CAST_TYPES =
{String=>:CStr, Integer=>:CLng, Date=>:CDate, Time=>:CDate, DateTime=>:CDate, Numeric=>:CDec, BigDecimal=>:CDec, File=>:CStr, Float=>:CDbl, TrueClass=>:CBool, FalseClass=>:CBool}.freeze

Instance Method Summary collapse

Methods included from EmulateOffsetWithReverseAndCount

#empty?, #select_sql, #supports_offsets_in_correlated_subqueries?

Instance Method Details

#case_expression_sql_append(sql, ce) ⇒ Object

Access doesn't support CASE, so emulate it with nested IIF function calls.



93
94
95
# 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

#cast_sql_append(sql, expr, type) ⇒ Object

Access doesn't support CAST, it uses separate functions for type conversion



99
100
101
102
103
104
# 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

#complex_expression_sql_append(sql, op, args) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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

#constant_sql_append(sql, constant) ⇒ Object

Use Date(), Now(), and Time() for CURRENT_DATE, CURRENT_TIMESTAMP, and CURRENT_TIME



152
153
154
155
156
157
158
159
160
161
162
163
# 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

#cross_join(table) ⇒ Object

Emulate cross join by using multiple tables in the FROM clause.



166
167
168
# File 'lib/sequel/adapters/shared/access.rb', line 166

def cross_join(table)
  clone(:from=>@opts[:from] + [table])
end

#escape_like(string) ⇒ Object

Access uses [] to escape metacharacters, instead of backslashes.



171
172
173
# File 'lib/sequel/adapters/shared/access.rb', line 171

def escape_like(string)
  string.gsub(/[\\*#?\[]/){|m| "[#{m}]"}
end

#into(table) ⇒ Object

Specify a table for a SELECT … INTO query.



176
177
178
# File 'lib/sequel/adapters/shared/access.rb', line 176

def into(table)
  clone(:into => table)
end

#supports_derived_column_lists?Boolean

Access does not support derived column lists.

Returns:

  • (Boolean)


181
182
183
# File 'lib/sequel/adapters/shared/access.rb', line 181

def supports_derived_column_lists?
  false
end

#supports_intersect_except?Boolean

Access doesn't support INTERSECT or EXCEPT

Returns:

  • (Boolean)


186
187
188
# File 'lib/sequel/adapters/shared/access.rb', line 186

def supports_intersect_except?
  false
end

#supports_is_true?Boolean

Access does not support IS TRUE

Returns:

  • (Boolean)


191
192
193
# File 'lib/sequel/adapters/shared/access.rb', line 191

def supports_is_true?
  false
end

#supports_join_using?Boolean

Access doesn't support JOIN USING

Returns:

  • (Boolean)


196
197
198
# File 'lib/sequel/adapters/shared/access.rb', line 196

def supports_join_using?
  false
end

#supports_multiple_column_in?Boolean

Access does not support multiple columns for the IN/NOT IN operators

Returns:

  • (Boolean)


201
202
203
# File 'lib/sequel/adapters/shared/access.rb', line 201

def supports_multiple_column_in?
  false
end

#truncateObject

Access doesn't support truncate, so do a delete instead.



206
207
208
209
# File 'lib/sequel/adapters/shared/access.rb', line 206

def truncate
  delete
  nil
end