| Module | Sequel::Access::DatasetMethods |
| In: |
lib/sequel/adapters/shared/access.rb
|
| SELECT_CLAUSE_METHODS | = | Dataset.clause_methods(:select, %w'select distinct limit columns into from join where group order having compounds') |
| DATE_FORMAT | = | '#%Y-%m-%d#'.freeze |
| TIMESTAMP_FORMAT | = | '#%Y-%m-%d %H:%M:%S#'.freeze |
| TOP | = | " TOP ".freeze |
| BRACKET_CLOSE | = | Dataset::BRACKET_CLOSE |
| BRACKET_OPEN | = | Dataset::BRACKET_OPEN |
| PAREN_CLOSE | = | Dataset::PAREN_CLOSE |
| PAREN_OPEN | = | Dataset::PAREN_OPEN |
| INTO | = | Dataset::INTO |
| FROM | = | Dataset::FROM |
| SPACE | = | Dataset::SPACE |
| NOT_EQUAL | = | ' <> '.freeze |
| OPS | = | {:'%'=>' Mod '.freeze, :'||'=>' & '.freeze} |
| BOOL_FALSE | = | '0'.freeze |
| BOOL_TRUE | = | '-1'.freeze |
| DATE_FUNCTION | = | 'Date()'.freeze |
| NOW_FUNCTION | = | 'Now()'.freeze |
| TIME_FUNCTION | = | 'Time()'.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} |
| EXTRACT_MAP | = | {:year=>"'yyyy'", :month=>"'m'", :day=>"'d'", :hour=>"'h'", :minute=>"'n'", :second=>"'s'"} |
| COMMA | = | Dataset::COMMA |
| DATEPART_OPEN | = | "datepart(".freeze |
Access doesn‘t support CASE, but it can be emulated with nested IIF function calls.
# File lib/sequel/adapters/shared/access.rb, line 119
119: def case_expression_sql_append(sql, ce)
120: literal_append(sql, ce.with_merged_expression.conditions.reverse.inject(ce.default){|exp,(cond,val)| Sequel::SQL::Function.new(:IIF, cond, val, exp)})
121: end
Access doesn‘t support CAST, it uses separate functions for type conversion
# File lib/sequel/adapters/shared/access.rb, line 125
125: def cast_sql_append(sql, expr, type)
126: sql << CAST_TYPES.fetch(type, type).to_s
127: sql << PAREN_OPEN
128: literal_append(sql, expr)
129: sql << PAREN_CLOSE
130: end
# File lib/sequel/adapters/shared/access.rb, line 132
132: def complex_expression_sql_append(sql, op, args)
133: case op
134: when :ILIKE
135: complex_expression_sql_append(sql, :LIKE, args)
136: when 'NOT ILIKE''NOT ILIKE'
137: complex_expression_sql_append(sql, 'NOT LIKE''NOT LIKE', args)
138: when :LIKE, 'NOT LIKE''NOT LIKE'
139: sql << PAREN_OPEN
140: literal_append(sql, args.at(0))
141: sql << SPACE << op.to_s << SPACE
142: literal_append(sql, args.at(1))
143: sql << PAREN_CLOSE
144: when '!=''!='
145: sql << PAREN_OPEN
146: literal_append(sql, args.at(0))
147: sql << NOT_EQUAL
148: literal_append(sql, args.at(1))
149: sql << PAREN_CLOSE
150: when '%''%', '||''||'
151: sql << PAREN_OPEN
152: c = false
153: op_str = OPS[op]
154: args.each do |a|
155: sql << op_str if c
156: literal_append(sql, a)
157: c ||= true
158: end
159: sql << PAREN_CLOSE
160: when :extract
161: part = args.at(0)
162: raise(Sequel::Error, "unsupported extract argument: #{part.inspect}") unless format = EXTRACT_MAP[part]
163: sql << DATEPART_OPEN << format.to_s << COMMA
164: literal_append(sql, args.at(1))
165: sql << PAREN_CLOSE
166: else
167: super
168: end
169: end
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
# File lib/sequel/adapters/shared/access.rb, line 172
172: def constant_sql_append(sql, constant)
173: case constant
174: when :CURRENT_DATE
175: sql << DATE_FUNCTION
176: when :CURRENT_TIMESTAMP
177: sql << NOW_FUNCTION
178: when :CURRENT_TIME
179: sql << TIME_FUNCTION
180: else
181: super
182: end
183: end
Emulate cross join by using multiple tables in the FROM clause.
# File lib/sequel/adapters/shared/access.rb, line 186
186: def cross_join(table)
187: clone(:from=>@opts[:from] + [table])
188: end
# File lib/sequel/adapters/shared/access.rb, line 190
190: def emulated_function_sql_append(sql, f)
191: case f.f
192: when :char_length
193: literal_append(sql, SQL::Function.new(:len, f.args.first))
194: else
195: super
196: end
197: end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/access.rb, line 205
205: def into(table)
206: clone(:into => table)
207: end