Module: Sequel::Oracle::DatabaseMethods

Included in:
JDBC::Oracle::DatabaseMethods, Database
Defined in:
lib/sequel/adapters/shared/oracle.rb

Constant Summary collapse

IGNORE_OWNERS =
%w'APEX_040000 CTXSYS EXFSYS MDSYS OLAPSYS ORDDATA ORDSYS SYS SYSTEM XDB XDBMETADATA XDBPM XFILES WMSYS'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#autosequenceObject

Returns the value of attribute autosequence


17
18
19
# File 'lib/sequel/adapters/shared/oracle.rb', line 17

def autosequence
  @autosequence
end

Instance Method Details

#create_sequence(name, opts = OPTS) ⇒ Object


19
20
21
# File 'lib/sequel/adapters/shared/oracle.rb', line 19

def create_sequence(name, opts=OPTS)
  self << create_sequence_sql(name, opts)
end

#create_trigger(*args) ⇒ Object


23
24
25
# File 'lib/sequel/adapters/shared/oracle.rb', line 23

def create_trigger(*args)
  self << create_trigger_sql(*args)
end

#current_userObject


27
28
29
# File 'lib/sequel/adapters/shared/oracle.rb', line 27

def current_user
  @current_user ||= .get{sys_context('USERENV', 'CURRENT_USER')}
end

#database_typeObject


35
36
37
# File 'lib/sequel/adapters/shared/oracle.rb', line 35

def database_type
  :oracle
end

#drop_sequence(name) ⇒ Object


31
32
33
# File 'lib/sequel/adapters/shared/oracle.rb', line 31

def drop_sequence(name)
  self << drop_sequence_sql(name)
end

#foreign_key_list(table, opts = OPTS) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sequel/adapters/shared/oracle.rb', line 39

def foreign_key_list(table, opts=OPTS)
  m = output_identifier_meth
  im = input_identifier_meth
  schema, table = schema_and_table(table)
  ds = .
    from{[all_cons_columns.as(:pc), all_constraints.as(:p), all_cons_columns.as(:fc), all_constraints.as(:f)]}.
    where{{
      f[:table_name]=>im.call(table),
      f[:constraint_type]=>'R',
      p[:owner]=>f[:r_owner],
      p[:constraint_name]=>f[:r_constraint_name],
      pc[:owner]=>p[:owner],
      pc[:constraint_name]=>p[:constraint_name],
      pc[:table_name]=>p[:table_name],
      fc[:owner]=>f[:owner],
      fc[:constraint_name]=>f[:constraint_name],
      fc[:table_name]=>f[:table_name],
      fc[:position]=>pc[:position]}}.
    select{[p[:table_name].as(:table), pc[:column_name].as(:key), fc[:column_name].as(:column), f[:constraint_name].as(:name)]}.
    order{[:table, fc[:position]]}
  ds = ds.where{{f[:schema_name]=>im.call(schema)}} if schema

  fks = {}
  ds.each do |r|
    if fk = fks[r[:name]]
      fk[:columns] << m.call(r[:column])
      fk[:key] << m.call(r[:key])
    else
      fks[r[:name]] = {:name=>m.call(r[:name]), :columns=>[m.call(r[:column])], :table=>m.call(r[:table]), :key=>[m.call(r[:key])]}
    end
  end
  fks.values
end

#freezeObject


73
74
75
76
77
78
# File 'lib/sequel/adapters/shared/oracle.rb', line 73

def freeze
  current_user
  server_version
  @conversion_procs.freeze
  super
end

#global_index_namespace?Boolean

Oracle namespaces indexes per table.


81
82
83
# File 'lib/sequel/adapters/shared/oracle.rb', line 81

def global_index_namespace?
  false
end

#server_version(server = nil) ⇒ Object

The version of the Oracle server, used for determining capability.


115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sequel/adapters/shared/oracle.rb', line 115

def server_version(server=nil)
  return @server_version if @server_version
  @server_version = synchronize(server) do |conn|
    (conn.server_version rescue nil) if conn.respond_to?(:server_version)
  end
  unless @server_version
    @server_version = if m = /(\d+)\.(\d+)\.?(\d+)?\.?(\d+)?/.match(fetch("select version from PRODUCT_COMPONENT_VERSION where lower(product) like 'oracle%'").single_value)
      (m[1].to_i*1000000) + (m[2].to_i*10000) + (m[3].to_i*100) + m[4].to_i
    else
      0
    end
  end
  @server_version
end

#supports_deferrable_constraints?Boolean

Oracle supports deferrable constraints.


132
133
134
# File 'lib/sequel/adapters/shared/oracle.rb', line 132

def supports_deferrable_constraints?
  true
end

#supports_transaction_isolation_levels?Boolean

Oracle supports transaction isolation levels.


137
138
139
# File 'lib/sequel/adapters/shared/oracle.rb', line 137

def supports_transaction_isolation_levels?
  true
end

#tables(opts = OPTS) ⇒ Object


87
88
89
90
91
92
93
94
95
# File 'lib/sequel/adapters/shared/oracle.rb', line 87

def tables(opts=OPTS)
  m = output_identifier_meth
  .from(:all_tables).
    server(opts[:server]).
    where(:dropped=>'NO').
    exclude(:owner=>IGNORE_OWNERS).
    select(:table_name).
    map{|r| m.call(r[:table_name])}
end

#view_exists?(name) ⇒ Boolean


106
107
108
109
110
111
112
# File 'lib/sequel/adapters/shared/oracle.rb', line 106

def view_exists?(name) 
  m = input_identifier_meth
  .from(:all_views).
    exclude(:owner=>IGNORE_OWNERS).
    where(:view_name=>m.call(name)).
    count > 0
end

#views(opts = OPTS) ⇒ Object


97
98
99
100
101
102
103
104
# File 'lib/sequel/adapters/shared/oracle.rb', line 97

def views(opts=OPTS) 
  m = output_identifier_meth
  .from(:all_views).
    server(opts[:server]).
    exclude(:owner=>IGNORE_OWNERS).
    select(:view_name).
    map{|r| m.call(r[:view_name])}
end