Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Constant Summary collapse
- ORACLE_IN_LIMIT =
1000
- ORACLE_ODCINUMBERLIST_ARGS_LIMIT =
999
Class Method Summary collapse
-
.add_order_with_lobs!(sql, order, scope = :auto) ⇒ Object
(also: add_order!)
patch ORDER BY to work with LOBs.
-
.ignore_table_columns(*args) ⇒ Object
Specify table columns which should be ignored by ActiveRecord, e.g.:.
- .join_quoted_values_for_condition(values) ⇒ Object
-
.oracle_enhanced_connection(config) ⇒ Object
Establishes a connection to the database that’s used by all Active Record objects.
-
.quote_bound_value(value) ⇒ Object
:nodoc:.
-
.set_boolean_columns(*args) ⇒ Object
Specify which table columns should be typecasted to boolean values
true
orfalse
, e.g.:. -
.set_date_columns(*args) ⇒ Object
Specify which table columns should be typecasted to Date (without time), e.g.:.
-
.set_datetime_columns(*args) ⇒ Object
Specify which table columns should be typecasted to Time (or DateTime), e.g.:.
-
.set_integer_columns(*args) ⇒ Object
Specify which table columns should be typecasted to integer values.
-
.set_string_columns(*args) ⇒ Object
Specify which table columns should be typecasted to string values.
-
.table_comment ⇒ Object
Get table comment from schema definition.
- .update_counters(id, counters) ⇒ Object
Class Method Details
.add_order_with_lobs!(sql, order, scope = :auto) ⇒ Object Also known as: add_order!
patch ORDER BY to work with LOBs
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 154 def add_order_with_lobs!(sql, order, scope = :auto) if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) order = connection.lob_order_by_expression(self, order) if order orig_scope = scope scope = scope(:find) if :auto == scope if scope new_scope_order = connection.lob_order_by_expression(self, scope[:order]) if new_scope_order != scope[:order] scope = scope.merge(:order => new_scope_order) else scope = orig_scope end end end add_order_without_lobs!(sql, order, scope = :auto) end |
.ignore_table_columns(*args) ⇒ Object
Specify table columns which should be ignored by ActiveRecord, e.g.:
ignore_table_columns :attribute1, :attribute2
57 58 59 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 57 def self.ignore_table_columns(*args) connection.ignore_table_columns(table_name,*args) end |
.join_quoted_values_for_condition(values) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 141 def join_quoted_values_for_condition(values) return values * ',' unless values.length > ORACLE_IN_LIMIT values.uniq! return values * ',' unless values.length > ORACLE_IN_LIMIT quoted_chunks = values.in_groups_of(ORACLE_ODCINUMBERLIST_ARGS_LIMIT, false).map do |chunk| "(SELECT * FROM TABLE(sys.odcinumberlist(#{chunk * ','})))" end quoted_chunks * " UNION " end |
.oracle_enhanced_connection(config) ⇒ Object
Establishes a connection to the database that’s used by all Active Record objects.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 41 def self.oracle_enhanced_connection(config) #:nodoc: if config[:emulate_oracle_adapter] == true # allows the enhanced adapter to look like the OracleAdapter. Useful to pick up # conditionals in the rails activerecord test suite require 'active_record/connection_adapters/emulation/oracle_adapter' ConnectionAdapters::OracleAdapter.new( ConnectionAdapters::OracleEnhancedConnection.create(config), logger) else ConnectionAdapters::OracleEnhancedAdapter.new( ConnectionAdapters::OracleEnhancedConnection.create(config), logger) end end |
.quote_bound_value(value) ⇒ Object
:nodoc:
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 111 def quote_bound_value(value) #:nodoc: if value.respond_to?(:map) && !value.acts_like?(:string) if value.respond_to?(:empty?) && value.empty? connection.quote(nil) else join_quoted_values_for_condition(value.map {|v| connection.quote(v)}) end else connection.quote(value) end end |
.set_boolean_columns(*args) ⇒ Object
Specify which table columns should be typecasted to boolean values true
or false
, e.g.:
set_boolean_columns :is_valid, :is_completed
78 79 80 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 78 def self.set_boolean_columns(*args) connection.set_type_for_columns(table_name,:boolean,*args) end |
.set_date_columns(*args) ⇒ Object
Specify which table columns should be typecasted to Date (without time), e.g.:
set_date_columns :created_on, :updated_on
64 65 66 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 64 def self.set_date_columns(*args) connection.set_type_for_columns(table_name,:date,*args) end |
.set_datetime_columns(*args) ⇒ Object
Specify which table columns should be typecasted to Time (or DateTime), e.g.:
set_datetime_columns :created_date, :updated_date
71 72 73 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 71 def self.set_datetime_columns(*args) connection.set_type_for_columns(table_name,:datetime,*args) end |
.set_integer_columns(*args) ⇒ Object
Specify which table columns should be typecasted to integer values. Might be useful to force NUMBER(1) column to be integer and not boolean, or force NUMBER column without scale to be retrieved as integer and not decimal. Example:
set_integer_columns :version_number, :object_identifier
87 88 89 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 87 def self.set_integer_columns(*args) connection.set_type_for_columns(table_name,:integer,*args) end |
.set_string_columns(*args) ⇒ Object
Specify which table columns should be typecasted to string values. Might be useful to specify that columns should be string even if its name matches boolean column criteria.
set_integer_columns :active_flag
95 96 97 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 95 def self.set_string_columns(*args) connection.set_type_for_columns(table_name,:string,*args) end |
.table_comment ⇒ Object
Get table comment from schema definition.
179 180 181 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 179 def self.table_comment connection.table_comment(self.table_name) end |
.update_counters(id, counters) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/active_record/connection_adapters/oracle_enhanced_adapter.rb', line 123 def update_counters(id, counters) updates = counters.inject([]) { |list, (counter_name, increment)| list << "#{connection.quote_column_name(counter_name)} = COALESCE(#{connection.quote_column_name(counter_name)}, 0) + #{increment}" }.join(", ") if id.is_a?(Array) ids_list = join_quoted_values_for_condition(id.map{|i| quote_value(i)}) condition = "IN (#{ids_list})" else condition = "= #{quote_value(id)}" end update_all(updates, "#{connection.quote_column_name(primary_key)} #{condition}") end |