module Sequel::Oracle::DatabaseMethods

  1. lib/sequel/adapters/shared/oracle.rb

Constants

DATABASE_ERROR_REGEXPS = { /unique constraint .+ violated/ => UniqueConstraintViolation, /integrity constraint .+ violated/ => ForeignKeyConstraintViolation, /check constraint .+ violated/ => CheckConstraintViolation, /cannot insert NULL into|cannot update .+ to NULL/ => NotNullConstraintViolation, /can't serialize access for this transaction/ => SerializationFailure, /resource busy and acquire with NOWAIT specified or timeout/ => DatabaseLockTimeout, }.freeze  
IGNORE_OWNERS = %w'APEX_040000 CTXSYS EXFSYS MDSYS OLAPSYS ORDDATA ORDSYS SYS SYSTEM XDB XDBMETADATA XDBPM XFILES WMSYS'.freeze  
TRANSACTION_ISOLATION_LEVELS = {:uncommitted=>'READ COMMITTED'.freeze, :committed=>'READ COMMITTED'.freeze, :repeatable=>'SERIALIZABLE'.freeze, :serializable=>'SERIALIZABLE'.freeze}.freeze  

Attributes

Public Instance methods

create_sequence(name, opts=OPTS)
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
20 def create_sequence(name, opts=OPTS)
21   self << create_sequence_sql(name, opts)
22 end
create_trigger(*args)
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
24 def create_trigger(*args)
25   self << create_trigger_sql(*args)
26 end
current_user()
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
28 def current_user
29   @current_user ||= metadata_dataset.get{sys_context('USERENV', 'CURRENT_USER')}
30 end
database_type()
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
36 def database_type
37   :oracle
38 end
drop_sequence(name)
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
32 def drop_sequence(name)
33   self << drop_sequence_sql(name)
34 end
foreign_key_list(table, opts=OPTS)
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
40 def foreign_key_list(table, opts=OPTS)
41   m = output_identifier_meth
42   im = input_identifier_meth
43   schema, table = schema_and_table(table)
44   ds = metadata_dataset.
45     from{[all_cons_columns.as(:pc), all_constraints.as(:p), all_cons_columns.as(:fc), all_constraints.as(:f)]}.
46     where{{
47       f[:table_name]=>im.call(table),
48       f[:constraint_type]=>'R',
49       p[:owner]=>f[:r_owner],
50       p[:constraint_name]=>f[:r_constraint_name],
51       pc[:owner]=>p[:owner],
52       pc[:constraint_name]=>p[:constraint_name],
53       pc[:table_name]=>p[:table_name],
54       fc[:owner]=>f[:owner],
55       fc[:constraint_name]=>f[:constraint_name],
56       fc[:table_name]=>f[:table_name],
57       fc[:position]=>pc[:position]}}.
58     select{[p[:table_name].as(:table), pc[:column_name].as(:key), fc[:column_name].as(:column), f[:constraint_name].as(:name)]}.
59     order{[:table, fc[:position]]}
60   ds = ds.where{{f[:schema_name]=>im.call(schema)}} if schema
61 
62   fks = {}
63   ds.each do |r|
64     if fk = fks[r[:name]]
65       fk[:columns] << m.call(r[:column])
66       fk[:key] << m.call(r[:key])
67     else
68       fks[r[:name]] = {:name=>m.call(r[:name]), :columns=>[m.call(r[:column])], :table=>m.call(r[:table]), :key=>[m.call(r[:key])]}
69     end
70   end
71   fks.values
72 end
freeze()
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
74 def freeze
75   current_user
76   server_version
77   @conversion_procs.freeze
78   super
79 end
global_index_namespace?()

Oracle namespaces indexes per table.

[show source]
   # File lib/sequel/adapters/shared/oracle.rb
82 def global_index_namespace?
83   false
84 end
server_version(server=nil)

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

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
122 def server_version(server=nil)
123   return @server_version if @server_version
124   @server_version = synchronize(server) do |conn|
125     (conn.server_version rescue nil) if conn.respond_to?(:server_version)
126   end
127   unless @server_version
128     @server_version = if m = /(\d+)\.(\d+)\.?(\d+)?\.?(\d+)?/.match(fetch("select version from PRODUCT_COMPONENT_VERSION where lower(product) like 'oracle%'").single_value)
129       (m[1].to_i*1000000) + (m[2].to_i*10000) + (m[3].to_i*100) + m[4].to_i
130     else
131       0
132     end
133   end
134   @server_version
135 end
supports_deferrable_constraints?()

Oracle supports deferrable constraints.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
139 def supports_deferrable_constraints?
140   true
141 end
supports_transaction_isolation_levels?()

Oracle supports transaction isolation levels.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
144 def supports_transaction_isolation_levels?
145   true
146 end
tables(opts=OPTS)
[show source]
   # File lib/sequel/adapters/shared/oracle.rb
88 def tables(opts=OPTS)
89   m = output_identifier_meth
90   metadata_dataset.from(:all_tables).
91     server(opts[:server]).
92     where(:dropped=>'NO').
93     exclude(:owner=>IGNORE_OWNERS).
94     select(:table_name).
95     map{|r| m.call(r[:table_name])}
96 end
view_exists?(name, opts=OPTS)

Whether a view with a given name exists. By default, looks in all schemas other than system schemas. If the :current_schema option is given, looks in the schema for the current user.

[show source]
    # File lib/sequel/adapters/shared/oracle.rb
109 def view_exists?(name, opts=OPTS) 
110   ds = metadata_dataset.from(:all_views).where(:view_name=>input_identifier_meth.call(name))
111   
112   if opts[:current_schema]
113     ds = ds.where(:owner=>Sequel.function(:SYS_CONTEXT, 'userenv', 'current_schema'))
114   else
115     ds = ds.exclude(:owner=>IGNORE_OWNERS)
116   end
117 
118   ds.count > 0
119 end
views(opts=OPTS)
[show source]
    # File lib/sequel/adapters/shared/oracle.rb
 98 def views(opts=OPTS) 
 99   m = output_identifier_meth
100   metadata_dataset.from(:all_views).
101     server(opts[:server]).
102     exclude(:owner=>IGNORE_OWNERS).
103     select(:view_name).
104     map{|r| m.call(r[:view_name])}
105 end