| 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 | = | LiteralString.new('ROWNUM').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 |
| 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 |
# File lib/sequel/adapters/shared/oracle.rb, line 247
247: def complex_expression_sql_append(sql, op, args)
248: case op
249: when :&
250: sql << complex_expression_arg_pairs(args){|a, b| "CAST(BITAND(#{literal(a)}, #{literal(b)}) AS INTEGER)"}
251: when :|
252: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} - #{complex_expression_sql(:&, [a, b])} + #{literal(b)})"}
253: when :^
254: sql << complex_expression_arg_pairs(args){|*x| "(#{complex_expression_sql(:|, x)} - #{complex_expression_sql(:&, x)})"}
255: when 'B~''B~'
256: sql << BITCOMP_OPEN
257: literal_append(sql, args.at(0))
258: sql << BITCOMP_CLOSE
259: when :<<
260: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * power(2, #{literal b}))"}
261: when :>>
262: sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / power(2, #{literal b}))"}
263: when :%
264: sql << complex_expression_arg_pairs(args){|a, b| "MOD(#{literal(a)}, #{literal(b)})"}
265: else
266: super
267: end
268: 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 273
273: def constant_sql_append(sql, c)
274: if c == :CURRENT_TIME
275: super(sql, :CURRENT_TIMESTAMP)
276: else
277: super
278: end
279: end
Use a custom expression with EXISTS to determine whether a dataset is empty.
# File lib/sequel/adapters/shared/oracle.rb, line 304
304: def empty?
305: db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil
306: end
Oracle treats empty strings like NULL values, and doesn‘t support char_length, so make char_length use length with a nonempty string. Unfortunately, as Oracle treats the empty string as NULL, there is no way to get trim to return an empty string instead of nil if the string only contains spaces.
# File lib/sequel/adapters/shared/oracle.rb, line 286
286: def emulated_function_sql_append(sql, f)
287: case f.f
288: when :char_length
289: literal_append(sql, Sequel::SQL::Function.new(:length, Sequel.join([f.args.first, 'x'])) - 1)
290: else
291: super
292: end
293: end
Oracle uses MINUS instead of EXCEPT, and doesn‘t support EXCEPT ALL
# File lib/sequel/adapters/shared/oracle.rb, line 296
296: def except(dataset, opts={})
297: opts = {:all=>opts} unless opts.is_a?(Hash)
298: raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all]
299: compound_clone(:minus, dataset, opts)
300: end
Handle LIMIT by using a unlimited subselect filtered with ROWNUM.
# File lib/sequel/adapters/shared/oracle.rb, line 321
321: def select_sql
322: if (limit = @opts[:limit]) && !@opts[:sql]
323: ds = clone(:limit=>nil)
324: # Lock doesn't work in subselects, so don't use a subselect when locking.
325: # Don't use a subselect if custom SQL is used, as it breaks somethings.
326: ds = ds.from_self unless @opts[:lock]
327: sql = @opts[:append_sql] || ''
328: subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit)))
329: sql
330: else
331: super
332: end
333: end