Module: Sequel::Oracle::DatasetMethods

Includes:
EmulateOffsetWithRowNumber
Included in:
JDBC::Oracle::Dataset, Dataset
Defined in:
lib/sequel/adapters/shared/oracle.rb

Constant Summary collapse

SELECT_CLAUSE_METHODS =
Dataset.clause_methods(:select, %w'with distinct columns from join where group having compounds order lock')
ROW_NUMBER_EXPRESSION =
'ROWNUM'.lit.freeze

Instance Method Summary collapse

Instance Method Details

#complex_expression_sql(op, args) ⇒ Object

Oracle needs to emulate bitwise operators and ILIKE/NOT ILIKE operators.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/sequel/adapters/shared/oracle.rb', line 184

def complex_expression_sql(op, args)
  case op
  when :&
    complex_expression_arg_pairs(args){|a, b| "CAST(BITAND(#{literal(a)}, #{literal(b)}) AS INTEGER)"}
  when :|
    complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} - #{complex_expression_sql(:&, [a, b])} + #{literal(b)})"}
  when :^
    complex_expression_arg_pairs(args){|*x| "(#{complex_expression_sql(:|, x)} - #{complex_expression_sql(:&, x)})"}
  when :'B~'
    "((0 - #{literal(args.at(0))}) - 1)"
  when :<<
    complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * power(2, #{literal b}))"}
  when :>>
    complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / power(2, #{literal b}))"}
  when :ILIKE, :'NOT ILIKE'
    a, b = args
    "(UPPER(#{literal(a)}) #{op == :ILIKE ? :LIKE : :'NOT LIKE'} UPPER(#{literal(b)}))"
  else
    super
  end
end

#constant_sql(c) ⇒ Object

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.



209
210
211
212
213
214
215
# File 'lib/sequel/adapters/shared/oracle.rb', line 209

def constant_sql(c)
  if c == :CURRENT_TIME
    super(:CURRENT_TIMESTAMP)
  else
    super
  end
end

#empty?Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/sequel/adapters/shared/oracle.rb', line 224

def empty?
  db[:dual].where(unordered.exists).get(1) == nil
end

#except(dataset, opts = {}) ⇒ Object

Oracle uses MINUS instead of EXCEPT, and doesn’t support EXCEPT ALL

Raises:



218
219
220
221
222
# File 'lib/sequel/adapters/shared/oracle.rb', line 218

def except(dataset, opts={})
  opts = {:all=>opts} unless opts.is_a?(Hash)
  raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all]
  compound_clone(:minus, dataset, opts)
end

#recursive_cte_requires_column_aliases?Boolean

Oracle requires recursive CTEs to have column aliases.

Returns:

  • (Boolean)


254
255
256
# File 'lib/sequel/adapters/shared/oracle.rb', line 254

def recursive_cte_requires_column_aliases?
  true
end

#requires_sql_standard_datetimes?Boolean

Oracle requires SQL standard datetimes

Returns:

  • (Boolean)


229
230
231
# File 'lib/sequel/adapters/shared/oracle.rb', line 229

def requires_sql_standard_datetimes?
  true
end

#select_sqlObject

Handle LIMIT by using a unlimited subselect filtered with ROWNUM.



241
242
243
244
245
246
247
248
249
250
251
# File 'lib/sequel/adapters/shared/oracle.rb', line 241

def select_sql
  if (limit = @opts[:limit]) && !@opts[:sql]
    ds = clone(:limit=>nil)
    # Lock doesn't work in subselects, so don't use a subselect when locking.
    # Don't use a subselect if custom SQL is used, as it breaks somethings.
    ds = ds.from_self unless @opts[:lock]
    subselect_sql(ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit)))
  else
    super
  end
end

#sequence(s) ⇒ Object

Create a copy of this dataset associated to the given sequence name, which will be used when calling insert to find the most recently inserted value for the sequence.



236
237
238
# File 'lib/sequel/adapters/shared/oracle.rb', line 236

def sequence(s)
  clone(:sequence=>s)
end

#supports_intersect_except_all?Boolean

Oracle does not support INTERSECT ALL or EXCEPT ALL

Returns:

  • (Boolean)


259
260
261
# File 'lib/sequel/adapters/shared/oracle.rb', line 259

def supports_intersect_except_all?
  false
end

#supports_is_true?Boolean

Oracle does not support IS TRUE.

Returns:

  • (Boolean)


264
265
266
# File 'lib/sequel/adapters/shared/oracle.rb', line 264

def supports_is_true?
  false
end

#supports_select_all_and_column?Boolean

Oracle does not support SELECT *, column

Returns:

  • (Boolean)


269
270
271
# File 'lib/sequel/adapters/shared/oracle.rb', line 269

def supports_select_all_and_column?
  false
end

#supports_timestamp_timezones?Boolean

Oracle supports timezones in literal timestamps.

Returns:

  • (Boolean)


274
275
276
# File 'lib/sequel/adapters/shared/oracle.rb', line 274

def supports_timestamp_timezones?
  true
end

#supports_where_true?Boolean

Oracle does not support WHERE ‘Y’ for WHERE TRUE.

Returns:

  • (Boolean)


279
280
281
# File 'lib/sequel/adapters/shared/oracle.rb', line 279

def supports_where_true?
  false
end

#supports_window_functions?Boolean

Oracle supports window functions

Returns:

  • (Boolean)


284
285
286
# File 'lib/sequel/adapters/shared/oracle.rb', line 284

def supports_window_functions?
  true
end