Module | Sequel::Oracle::DatasetMethods |
In: |
lib/sequel/adapters/shared/oracle.rb
|
SELECT_CLAUSE_METHODS | = | Dataset.clause_methods(:select, %w'with select distinct columns from join where group having compounds order lock') |
ROW_NUMBER_EXPRESSION | = | 'ROWNUM'.lit.freeze |
SPACE | = | Dataset::SPACE |
APOS | = | Dataset::APOS |
APOS_RE | = | Dataset::APOS_RE |
DOUBLE_APOS | = | Dataset::DOUBLE_APOS |
FROM | = | Dataset::FROM |
BITCOMP_OPEN | = | "((0 - ".freeze |
BITCOMP_CLOSE | = | ") - 1)".freeze |
ILIKE_0 | = | "(UPPER(".freeze |
ILIKE_1 | = | ") ".freeze |
ILIKE_2 | = | ' UPPER('.freeze |
ILIKE_3 | = | "))".freeze |
LIKE | = | 'LIKE'.freeze |
NOT_LIKE | = | 'NOT LIKE'.freeze |
TIMESTAMP_FORMAT | = | "TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'".freeze |
TIMESTAMP_OFFSET_FORMAT | = | "%+03i:%02i".freeze |
BOOL_FALSE | = | "'N'".freeze |
BOOL_TRUE | = | "'Y'".freeze |
HSTAR | = | "H*".freeze |
DUAL | = | ['DUAL'.freeze].freeze |
Oracle needs to emulate bitwise operators and ILIKE/NOT ILIKE operators.
# File lib/sequel/adapters/shared/oracle.rb, line 205 205: def complex_expression_sql_append(sql, op, args) 206: case op 207: when :& 208: sql << complex_expression_arg_pairs(args){|a, b| "CAST(BITAND(#{literal(a)}, #{literal(b)}) AS INTEGER)"} 209: when :| 210: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} - #{complex_expression_sql(:&, [a, b])} + #{literal(b)})"} 211: when :^ 212: sql << complex_expression_arg_pairs(args){|*x| "(#{complex_expression_sql(:|, x)} - #{complex_expression_sql(:&, x)})"} 213: when 'B~''B~' 214: sql << BITCOMP_OPEN 215: literal_append(sql, args.at(0)) 216: sql << BITCOMP_CLOSE 217: when :<< 218: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * power(2, #{literal b}))"} 219: when :>> 220: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / power(2, #{literal b}))"} 221: when :ILIKE, 'NOT ILIKE''NOT ILIKE' 222: sql << ILIKE_0 223: literal_append(sql, args.at(0)) 224: sql << ILIKE_1 225: sql << (op == :ILIKE ? LIKE : NOT_LIKE) 226: sql<< ILIKE_2 227: literal_append(sql, args.at(1)) 228: sql << ILIKE_3 229: else 230: super 231: end 232: end
Oracle doesn‘t support CURRENT_TIME, as it doesn‘t have a type for storing just time values without a date, so use CURRENT_TIMESTAMP in its place.
# File lib/sequel/adapters/shared/oracle.rb, line 237 237: def constant_sql_append(sql, c) 238: if c == :CURRENT_TIME 239: super(sql, :CURRENT_TIMESTAMP) 240: else 241: super 242: end 243: end
Use a custom expression with EXISTS to determine whether a dataset is empty.
# File lib/sequel/adapters/shared/oracle.rb, line 254 254: def empty? 255: db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil 256: end
Oracle uses MINUS instead of EXCEPT, and doesn‘t support EXCEPT ALL
# File lib/sequel/adapters/shared/oracle.rb, line 246 246: def except(dataset, opts={}) 247: opts = {:all=>opts} unless opts.is_a?(Hash) 248: raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all] 249: compound_clone(:minus, dataset, opts) 250: end
Handle LIMIT by using a unlimited subselect filtered with ROWNUM.
# File lib/sequel/adapters/shared/oracle.rb, line 271 271: def select_sql 272: if (limit = @opts[:limit]) && !@opts[:sql] 273: ds = clone(:limit=>nil) 274: # Lock doesn't work in subselects, so don't use a subselect when locking. 275: # Don't use a subselect if custom SQL is used, as it breaks somethings. 276: ds = ds.from_self unless @opts[:lock] 277: sql = @opts[:append_sql] || '' 278: subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit))) 279: sql 280: else 281: super 282: end 283: end