Module: Sequel::Access::DatasetMethods

Constant Summary collapse

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

Constants included from Dataset::ColumnsLimit1

Dataset::ColumnsLimit1::COLUMNS_CLONE_OPTIONS

Instance Method Summary collapse

Methods included from Dataset::ColumnsLimit1

#columns!

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.



103
104
105
# File 'lib/sequel/adapters/shared/access.rb', line 103

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



109
110
111
112
113
114
# File 'lib/sequel/adapters/shared/access.rb', line 109

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



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
150
151
152
153
# File 'lib/sequel/adapters/shared/access.rb', line 116

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

#constant_sql_append(sql, constant) ⇒ Object

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



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/sequel/adapters/shared/access.rb', line 156

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.



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

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

#escape_like(string) ⇒ Object

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



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

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

#into(table) ⇒ Object

Specify a table for a SELECT … INTO query.



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

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

#quoted_identifier_append(sql, v) ⇒ Object

Access uses [] for quoting identifiers, and can’t handle ] inside identifiers.



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

def quoted_identifier_append(sql, v)
  sql << '[' << v.to_s << ']'
end

#supports_derived_column_lists?Boolean

Access does not support derived column lists.

Returns:

  • (Boolean)


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

def supports_derived_column_lists?
  false
end

#supports_intersect_except?Boolean

Access doesn’t support INTERSECT or EXCEPT

Returns:

  • (Boolean)


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

def supports_intersect_except?
  false
end

#supports_is_true?Boolean

Access does not support IS TRUE

Returns:

  • (Boolean)


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

def supports_is_true?
  false
end

#supports_join_using?Boolean

Access doesn’t support JOIN USING

Returns:

  • (Boolean)


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

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)


211
212
213
# File 'lib/sequel/adapters/shared/access.rb', line 211

def supports_multiple_column_in?
  false
end

#truncateObject

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



216
217
218
219
# File 'lib/sequel/adapters/shared/access.rb', line 216

def truncate
  delete
  nil
end