Module: OracleEnhancedAdapterConstraintsMethods
- Defined in:
- lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Instance Method Summary collapse
- #constraints(table_name) ⇒ Object
- #foreign_keys_for(table_name) ⇒ Object
- #foreign_keys_of(table_name) ⇒ Object
Instance Method Details
#constraints(table_name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 45 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(<<-SQL, 'User Contraints') select c.constraint_name, c.search_condition from user_constraints c where c.owner = '#{owner}' and c.table_name = '#{table_name}' and c.constraint_type = 'C' and c.generated = 'USER NAME' and c.status = 'ENABLED' SQL end |
#foreign_keys_for(table_name) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 3 def foreign_keys_for(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(<<-SQL, 'Foreign Keys') select parent_c.table_name, cc.column_name from user_constraints c, user_constraints parent_c, user_cons_columns cc where c.owner = '#{owner}' and c.table_name = '#{table_name}' and c.r_constraint_name = parent_c.constraint_name and c.constraint_type = 'R' and cc.owner = c.owner and cc.constraint_name = c.constraint_name SQL end |
#foreign_keys_of(table_name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 18 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(<<-SQL, 'Remote Foriegn Keys') select c.table_name, cc.column_name, c.delete_rule from user_constraints c, user_constraints parent_c, user_cons_columns cc where c.owner = '#{owner}' and parent_c.table_name = '#{table_name}' and c.r_constraint_name = parent_c.constraint_name and c.constraint_type = 'R' and cc.owner = c.owner and cc.constraint_name = c.constraint_name SQL fks.map do |row| dependent = case row[2] when 'CASCADE' :destroy when 'SET NULL' :nullify end = {:to_table => row[0].downcase, :foreign_key =>row[1].downcase.to_sym } [:dependent] = dependent unless dependent.nil? end end |