module Sequel::Oracle::DatasetMethods

  1. lib/sequel/adapters/shared/oracle.rb
Parent: Oracle

Constants

APOS = Dataset::APOS  
APOS_RE = Dataset::APOS_RE  
BITCOMP_CLOSE = ") - 1)".freeze  
BITCOMP_OPEN = "((0 - ".freeze  
BOOL_FALSE = "'N'".freeze  
BOOL_TRUE = "'Y'".freeze  
DOUBLE_APOS = Dataset::DOUBLE_APOS  
DUAL = ['DUAL'.freeze].freeze  
FROM = Dataset::FROM  
HSTAR = "H*".freeze  
ROW_NUMBER_EXPRESSION = LiteralString.new('ROWNUM').freeze  
SELECT_CLAUSE_METHODS = Dataset.clause_methods(:select, %w'with select distinct columns from join where group having compounds order lock')  
SPACE = Dataset::SPACE  
TIMESTAMP_FORMAT = "TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'".freeze  
TIMESTAMP_OFFSET_FORMAT = "%+03i:%02i".freeze  

Public Instance methods

complex_expression_sql_append (sql, op, args)
[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 266
def complex_expression_sql_append(sql, op, args)
  case op
  when :&
    sql << complex_expression_arg_pairs(args){|a, b| "CAST(BITAND(#{literal(a)}, #{literal(b)}) AS INTEGER)"}
  when :|
    sql << complex_expression_arg_pairs(args) do |a, b|
      s1 = ''
      complex_expression_sql_append(s1, :&, [a, b])
      "(#{literal(a)} - #{s1} + #{literal(b)})"
    end
  when :^
    sql << complex_expression_arg_pairs(args) do |*x|
      s1 = ''
      s2 = ''
      complex_expression_sql_append(s1, :|, x)
      complex_expression_sql_append(s2, :&, x)
      "(#{s1} - #{s2})"
    end
  when :'B~'
    sql << BITCOMP_OPEN
    literal_append(sql, args.at(0))
    sql << BITCOMP_CLOSE
  when :<<
    sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * power(2, #{literal(b)}))"}
  when :>>
    sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / power(2, #{literal(b)}))"}
  when :%
    sql << complex_expression_arg_pairs(args){|a, b| "MOD(#{literal(a)}, #{literal(b)})"}
  else
    super
  end
end
constant_sql_append (sql, c)

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.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 302
def constant_sql_append(sql, c)
  if c == :CURRENT_TIME
    super(sql, :CURRENT_TIMESTAMP)
  else
    super
  end
end
empty? ()

Use a custom expression with EXISTS to determine whether a dataset is empty.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 332
def empty?
  db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil
end
emulated_function_sql_append (sql, f)

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.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 315
def emulated_function_sql_append(sql, f)
  case f.f
  when :char_length
    literal_append(sql, Sequel::SQL::Function.new(:length, Sequel.join([f.args.first, 'x'])) - 1)
  else
    super
  end
end
except (dataset, opts=OPTS)

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

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 325
def except(dataset, opts=OPTS)
  raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all]
  compound_clone(:minus, dataset, opts)
end
recursive_cte_requires_column_aliases? ()

Oracle requires recursive CTEs to have column aliases.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 380
def recursive_cte_requires_column_aliases?
  true
end
requires_sql_standard_datetimes? ()

Oracle requires SQL standard datetimes

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 337
def requires_sql_standard_datetimes?
  true
end
select_sql ()

Handle LIMIT by using a unlimited subselect filtered with ROWNUM.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 349
def select_sql
  return super if @opts[:sql]
  if o = @opts[:offset]
    columns = clone(:append_sql=>'').columns
    dsa1 = dataset_alias(1)
    rn = row_number_column
    limit = @opts[:limit]
    ds = unlimited.
      from_self(:alias=>dsa1).
      select_append(ROW_NUMBER_EXPRESSION.as(rn)).
      from_self(:alias=>dsa1).
      select(*columns).
      where(SQL::Identifier.new(rn) > o)
    ds = ds.where(SQL::Identifier.new(rn) <= Sequel.+(o, limit)) if limit
    sql = @opts[:append_sql] || ''
    subselect_sql_append(sql, ds)
    sql
  elsif limit = @opts[:limit]
    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]
    sql = @opts[:append_sql] || ''
    subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit)))
    sql
  else
    super
  end
end
sequence (s)

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.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 344
def sequence(s)
  clone(:sequence=>s)
end
supports_group_cube? ()

Oracle supports GROUP BY CUBE

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 385
def supports_group_cube?
  true
end
supports_group_rollup? ()

Oracle supports GROUP BY ROLLUP

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 390
def supports_group_rollup?
  true
end
supports_intersect_except_all? ()

Oracle does not support INTERSECT ALL or EXCEPT ALL

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 395
def supports_intersect_except_all?
  false
end
supports_is_true? ()

Oracle does not support IS TRUE.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 400
def supports_is_true?
  false
end
supports_select_all_and_column? ()

Oracle does not support SELECT *, column

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 405
def supports_select_all_and_column?
  false
end
supports_timestamp_timezones? ()

Oracle supports timezones in literal timestamps.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 410
def supports_timestamp_timezones?
  true
end
supports_where_true? ()

Oracle does not support WHERE 'Y' for WHERE TRUE.

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 415
def supports_where_true?
  false
end
supports_window_functions? ()

Oracle supports window functions

[show source]
# File lib/sequel/adapters/shared/oracle.rb, line 420
def supports_window_functions?
  true
end