Module: Foreigner::ConnectionAdapters::OracleEnhancedAdapter

Includes:
Sql2003
Defined in:
lib/active_record/connection_adapters/oracleenhanced_adapter.rb

Instance Method Summary collapse

Instance Method Details

#constraints(table_name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_record/connection_adapters/oracleenhanced_adapter.rb', line 61

def constraints(table_name)
  (owner, table_name) = @connection.describe(table_name)

  # RSI: changed select from all_constraints to user_constraints - much faster in large data dictionaries
  fks = select_rows("    select c.constraint_name, c.search_condition\n      from user_constraints c\n    where c.owner = '\#{owner}'\n      and c.table_name = '\#{table_name}'\n      and c.constraint_type = 'C'\n      and c.generated = 'USER NAME'\n      and c.status = 'ENABLED'\n  SQL\nend\n", 'User Contraints')

#foreign_keys(table_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_record/connection_adapters/oracleenhanced_adapter.rb', line 8

def foreign_keys(table_name)
  (owner, table_name) = @connection.describe(table_name)

  # RSI: changed select from all_constraints to user_constraints - much faster in large data dictionaries
  fks = select_rows("    select parent_c.table_name to_table, cc.column_name column_name, c.r_constraint_name name, c.delete_rule \n      from user_constraints c, user_constraints parent_c, user_cons_columns cc\n    where c.owner = '\#{owner}'\n      and c.table_name = '\#{table_name}'\n      and c.r_constraint_name = parent_c.constraint_name\n      and c.constraint_type = 'R'\n      and cc.owner = c.owner\n      and cc.constraint_name = c.constraint_name\n  SQL\n\n  fks.map do |row|\n    options = {:column => row[1], :name => row[2]}\n    if row[3] == 'CASCADE'\n      options[:dependent] = :delete\n    elsif $1 == 'SET NULL'\n      options[:dependent] = :nullify\n    end\n    ForeignKeyDefinition.new(table_name, row[0], options)\n  end\nend\n", 'Foreign Keys')

#foreign_keys_of(table_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_record/connection_adapters/oracleenhanced_adapter.rb', line 34

def foreign_keys_of(table_name)
  (owner, table_name) = @connection.describe(table_name)

  # RSI: changed select from all_constraints to user_constraints - much faster in large data dictionaries
  fks = select_rows("    select c.table_name, cc.column_name, c.delete_rule \n      from user_constraints c, user_constraints parent_c, user_cons_columns cc\n    where c.owner = '\#{owner}'\n      and parent_c.table_name = '\#{table_name}'\n      and c.r_constraint_name = parent_c.constraint_name\n      and c.constraint_type = 'R'\n      and cc.owner = c.owner\n      and cc.constraint_name = c.constraint_name\n  SQL\n  fks.map do |row| \n    dependent = case row[2] \n      when 'CASCADE'\n        :destroy\n      when 'SET NULL'\n        :nullify\n      end\n    options = {:to_table => row[0].downcase, :foreign_key =>row[1].downcase.to_sym }\n    options[:dependent] = dependent unless dependent.nil?\n    options\n  end\nend\n", 'Remote Foriegn Keys')