Module: Sequel::Access::DatasetMethods
- Includes:
- Dataset::ColumnsLimit1, EmulateOffsetWithReverseAndCount, UnmodifiedIdentifiers::DatasetMethods
- Included in:
- Sequel::ADO::Access::Dataset
- Defined in:
- lib/sequel/adapters/shared/access.rb
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
-
#case_expression_sql_append(sql, ce) ⇒ Object
Access doesn't support CASE, so emulate it 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(), Now(), and Time() for CURRENT_DATE, CURRENT_TIMESTAMP, and CURRENT_TIME.
-
#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 ...
-
#quoted_identifier_append(sql, v) ⇒ Object
Access uses [] for quoting identifiers, and can't handle ] inside identifiers.
-
#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 Dataset::ColumnsLimit1
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.
106 107 108 |
# File 'lib/sequel/adapters/shared/access.rb', line 106 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
112 113 114 115 116 117 |
# File 'lib/sequel/adapters/shared/access.rb', line 112 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
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 154 155 156 |
# File 'lib/sequel/adapters/shared/access.rb', line 119 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
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/sequel/adapters/shared/access.rb', line 159 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.
173 174 175 |
# File 'lib/sequel/adapters/shared/access.rb', line 173 def cross_join(table) clone(:from=>@opts[:from] + [table]) end |
#escape_like(string) ⇒ Object
Access uses [] to escape metacharacters, instead of backslashes.
178 179 180 |
# File 'lib/sequel/adapters/shared/access.rb', line 178 def escape_like(string) string.gsub(/[\\*#?\[]/){|m| "[#{m}]"} end |
#into(table) ⇒ Object
Specify a table for a SELECT ... INTO query.
183 184 185 |
# File 'lib/sequel/adapters/shared/access.rb', line 183 def into(table) clone(:into => table) end |
#quoted_identifier_append(sql, v) ⇒ Object
Access uses [] for quoting identifiers, and can't handle ] inside identifiers.
189 190 191 192 193 |
# File 'lib/sequel/adapters/shared/access.rb', line 189 def quoted_identifier_append(sql, v) v = v.to_s raise Error, "Access cannot quote an identifier containing ]" if v.include?("]") sql << '[' << v << ']' end |
#supports_derived_column_lists? ⇒ Boolean
Access does not support derived column lists.
196 197 198 |
# File 'lib/sequel/adapters/shared/access.rb', line 196 def supports_derived_column_lists? false end |
#supports_intersect_except? ⇒ Boolean
Access doesn't support INTERSECT or EXCEPT
201 202 203 |
# File 'lib/sequel/adapters/shared/access.rb', line 201 def supports_intersect_except? false end |
#supports_is_true? ⇒ Boolean
Access does not support IS TRUE
206 207 208 |
# File 'lib/sequel/adapters/shared/access.rb', line 206 def supports_is_true? false end |
#supports_join_using? ⇒ Boolean
Access doesn't support JOIN USING
211 212 213 |
# File 'lib/sequel/adapters/shared/access.rb', line 211 def supports_join_using? false end |
#supports_multiple_column_in? ⇒ Boolean
Access does not support multiple columns for the IN/NOT IN operators
216 217 218 |
# File 'lib/sequel/adapters/shared/access.rb', line 216 def supports_multiple_column_in? false end |
#truncate ⇒ Object
Access doesn't support truncate, so do a delete instead.
221 222 223 224 |
# File 'lib/sequel/adapters/shared/access.rb', line 221 def truncate delete nil end |