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
-
#autosequence ⇒ Object
Returns the value of attribute autosequence.
Instance Method Summary collapse
- #create_sequence(name, opts = OPTS) ⇒ Object
- #create_trigger(*args) ⇒ Object
- #current_user ⇒ Object
- #database_type ⇒ Object
- #drop_sequence(name) ⇒ Object
- #foreign_key_list(table, opts = OPTS) ⇒ Object
- #freeze ⇒ Object
-
#global_index_namespace? ⇒ Boolean
Oracle namespaces indexes per table.
-
#server_version(server = nil) ⇒ Object
The version of the Oracle server, used for determining capability.
-
#supports_deferrable_constraints? ⇒ Boolean
Oracle supports deferrable constraints.
-
#supports_transaction_isolation_levels? ⇒ Boolean
Oracle supports transaction isolation levels.
- #tables(opts = OPTS) ⇒ Object
-
#view_exists?(name, opts = OPTS) ⇒ Boolean
Whether a view with a given name exists.
- #views(opts = OPTS) ⇒ Object
Instance Attribute Details
#autosequence ⇒ Object
Returns the value of attribute autosequence.
18 19 20 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 18 def autosequence @autosequence end |
Instance Method Details
#create_sequence(name, opts = OPTS) ⇒ Object
20 21 22 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 20 def create_sequence(name, opts=OPTS) self << create_sequence_sql(name, opts) end |
#create_trigger(*args) ⇒ Object
24 25 26 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 24 def create_trigger(*args) self << create_trigger_sql(*args) end |
#current_user ⇒ Object
28 29 30 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 28 def current_user @current_user ||= .get{sys_context('USERENV', 'CURRENT_USER')} end |
#database_type ⇒ Object
36 37 38 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 36 def database_type :oracle end |
#drop_sequence(name) ⇒ Object
32 33 34 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 32 def drop_sequence(name) self << drop_sequence_sql(name) end |
#foreign_key_list(table, opts = OPTS) ⇒ Object
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 72 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 40 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 |
#freeze ⇒ Object
74 75 76 77 78 79 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 74 def freeze current_user server_version @conversion_procs.freeze super end |
#global_index_namespace? ⇒ Boolean
Oracle namespaces indexes per table.
82 83 84 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 82 def global_index_namespace? false end |
#server_version(server = nil) ⇒ Object
The version of the Oracle server, used for determining capability.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 122 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.
139 140 141 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 139 def supports_deferrable_constraints? true end |
#supports_transaction_isolation_levels? ⇒ Boolean
Oracle supports transaction isolation levels.
144 145 146 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 144 def supports_transaction_isolation_levels? true end |
#tables(opts = OPTS) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 88 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, opts = OPTS) ⇒ Boolean
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.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 109 def view_exists?(name, opts=OPTS) ds = .from(:all_views).where(:view_name=>input_identifier_meth.call(name)) if opts[:current_schema] ds = ds.where(:owner=>Sequel.function(:SYS_CONTEXT, 'userenv', 'current_schema')) else ds = ds.exclude(:owner=>IGNORE_OWNERS) end ds.count > 0 end |
#views(opts = OPTS) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 98 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 |