Module: Sequel::Access::DatasetMethods
- Includes:
- EmulateOffsetWithReverseAndCount
- Included in:
- Sequel::ADO::Access::Dataset
- Defined in:
- lib/sequel/adapters/shared/access.rb
Constant Summary collapse
- 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}
- EMULATED_FUNCTION_MAP =
{:char_length=>:len}
- EXTRACT_MAP =
{:year=>"'yyyy'", :month=>"'m'", :day=>"'d'", :hour=>"'h'", :minute=>"'n'", :second=>"'s'"}
- COMMA =
Dataset::COMMA
- DATEPART_OPEN =
"datepart(".freeze
Instance Method Summary collapse
-
#case_expression_sql_append(sql, ce) ⇒ Object
Access doesn’t support CASE, but it can be emulated with nested IIF function calls.
-
#cast_sql_append(sql, expr, type) ⇒ Object
Access doesn’t support CAST, it uses separate functions for type conversion.
- #complex_expression_sql_append(sql, op, args) ⇒ Object
-
#constant_sql_append(sql, constant) ⇒ Object
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP.
-
#cross_join(table) ⇒ Object
Emulate cross join by using multiple tables in the FROM clause.
-
#escape_like(string) ⇒ Object
Access uses [] to escape metacharacters, instead of backslashes.
-
#into(table) ⇒ Object
Specify a table for a SELECT …
-
#supports_derived_column_lists? ⇒ Boolean
Access does not support derived column lists.
-
#supports_intersect_except? ⇒ Boolean
Access doesn’t support INTERSECT or EXCEPT.
-
#supports_is_true? ⇒ Boolean
Access does not support IS TRUE.
-
#supports_join_using? ⇒ Boolean
Access doesn’t support JOIN USING.
-
#supports_multiple_column_in? ⇒ Boolean
Access does not support multiple columns for the IN/NOT IN operators.
-
#truncate ⇒ Object
Access doesn’t support truncate, so do a delete instead.
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, but it can be emulated with nested IIF function calls.
117 118 119 |
# File 'lib/sequel/adapters/shared/access.rb', line 117 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
123 124 125 126 127 128 |
# File 'lib/sequel/adapters/shared/access.rb', line 123 def cast_sql_append(sql, expr, type) sql << CAST_TYPES.fetch(type, type).to_s sql << PAREN_OPEN literal_append(sql, expr) sql << PAREN_CLOSE end |
#complex_expression_sql_append(sql, op, args) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/sequel/adapters/shared/access.rb', line 130 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 << PAREN_OPEN literal_append(sql, args.at(0)) sql << SPACE << op.to_s << SPACE literal_append(sql, args.at(1)) sql << PAREN_CLOSE when :'!=' sql << PAREN_OPEN literal_append(sql, args.at(0)) sql << NOT_EQUAL literal_append(sql, args.at(1)) sql << PAREN_CLOSE when :'%', :'||' sql << PAREN_OPEN c = false op_str = OPS[op] args.each do |a| sql << op_str if c literal_append(sql, a) c ||= true end sql << PAREN_CLOSE when :extract part = args.at(0) raise(Sequel::Error, "unsupported extract argument: #{part.inspect}") unless format = EXTRACT_MAP[part] sql << DATEPART_OPEN << format.to_s << COMMA literal_append(sql, args.at(1)) sql << PAREN_CLOSE else super end end |
#constant_sql_append(sql, constant) ⇒ Object
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/sequel/adapters/shared/access.rb', line 170 def constant_sql_append(sql, constant) case constant when :CURRENT_DATE sql << DATE_FUNCTION when :CURRENT_TIMESTAMP sql << NOW_FUNCTION when :CURRENT_TIME sql << TIME_FUNCTION else super end end |
#cross_join(table) ⇒ Object
Emulate cross join by using multiple tables in the FROM clause.
184 185 186 |
# File 'lib/sequel/adapters/shared/access.rb', line 184 def cross_join(table) clone(:from=>@opts[:from] + [table]) end |
#escape_like(string) ⇒ Object
Access uses [] to escape metacharacters, instead of backslashes.
189 190 191 |
# File 'lib/sequel/adapters/shared/access.rb', line 189 def escape_like(string) string.gsub(/[\\*#?\[]/){|m| "[#{m}]"} end |
#into(table) ⇒ Object
Specify a table for a SELECT … INTO query.
194 195 196 |
# File 'lib/sequel/adapters/shared/access.rb', line 194 def into(table) clone(:into => table) end |
#supports_derived_column_lists? ⇒ Boolean
Access does not support derived column lists.
199 200 201 |
# File 'lib/sequel/adapters/shared/access.rb', line 199 def supports_derived_column_lists? false end |
#supports_intersect_except? ⇒ Boolean
Access doesn’t support INTERSECT or EXCEPT
204 205 206 |
# File 'lib/sequel/adapters/shared/access.rb', line 204 def supports_intersect_except? false end |
#supports_is_true? ⇒ Boolean
Access does not support IS TRUE
209 210 211 |
# File 'lib/sequel/adapters/shared/access.rb', line 209 def supports_is_true? false end |
#supports_join_using? ⇒ Boolean
Access doesn’t support JOIN USING
214 215 216 |
# File 'lib/sequel/adapters/shared/access.rb', line 214 def supports_join_using? false end |
#supports_multiple_column_in? ⇒ Boolean
Access does not support multiple columns for the IN/NOT IN operators
219 220 221 |
# File 'lib/sequel/adapters/shared/access.rb', line 219 def supports_multiple_column_in? false end |
#truncate ⇒ Object
Access doesn’t support truncate, so do a delete instead.
224 225 226 227 |
# File 'lib/sequel/adapters/shared/access.rb', line 224 def truncate delete nil end |