Class: ActiveRecord::ConnectionAdapters::OracleEnhancedColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/oracle_enhanced/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, cast_type, sql_type = nil, null = true, table_name = nil, virtual = false, returning_id = false) ⇒ OracleEnhancedColumn

:nodoc:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 10

def initialize(name, default, cast_type, sql_type = nil, null = true, table_name = nil, virtual=false, returning_id=false) #:nodoc:
  @table_name = table_name
  @virtual = virtual
  @virtual_column_data_default = default.inspect if virtual
  @returning_id = returning_id
  if virtual
    default_value = nil
  else
    default_value = self.class.extract_value_from_default(default)
  end
  super(name, default_value, cast_type, sql_type, null)
  # Is column NCHAR or NVARCHAR2 (will need to use N'...' value quoting for these data types)?
  # Define only when needed as adapter "quote" method will check at first if instance variable is defined.
  if sql_type 
    @nchar = true if cast_type.class == ActiveRecord::Type::String && sql_type[0,1] == 'N'
    @object_type = sql_type.include? '.'
  end
  # TODO: Need to investigate when `sql_type` becomes nil
end

Instance Attribute Details

#ncharObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 5

def nchar
  @nchar
end

#returning_idObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 5

def returning_id
  @returning_id
end

#table_nameObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 5

def table_name
  @table_name
end

#virtual_column_data_defaultObject (readonly)

:nodoc:



5
6
7
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 5

def virtual_column_data_default
  @virtual_column_data_default
end

Class Method Details

.string_to_date(string) ⇒ Object

convert Time or DateTime value to Date for :date columns



65
66
67
68
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 65

def self.string_to_date(string) #:nodoc:
  return string.to_date if string.is_a?(Time) || string.is_a?(DateTime)
  super
end

.string_to_raw(string) ⇒ Object

convert RAW column values back to byte strings.



77
78
79
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 77

def self.string_to_raw(string) #:nodoc:
  string
end

.string_to_time(string) ⇒ Object

convert Date value to Time for :datetime columns



71
72
73
74
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 71

def self.string_to_time(string) #:nodoc:
  return string.to_time if string.is_a?(Date) && !OracleEnhancedAdapter.emulate_dates
  super
end

.value_to_boolean(value) ⇒ Object

convert something to a boolean added y as boolean value



54
55
56
57
58
59
60
61
62
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 54

def self.value_to_boolean(value) #:nodoc:
  if value == true || value == false
    value
  elsif value.is_a?(String) && value.blank?
    nil
  else
    %w(true t 1 y +).include?(value.to_s.downcase)
  end
end

Instance Method Details

#commentObject

Get column comment from schema definition. Will work only if using default ActiveRecord connection.



83
84
85
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 83

def comment
  ActiveRecord::Base.connection.column_comment(@table_name, name)
end

#lob?Boolean



44
45
46
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 44

def lob?
  self.sql_type =~ /LOB$/i
end

#object_type?Boolean



48
49
50
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 48

def object_type?
  @object_type
end

#returning_id?Boolean



40
41
42
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 40

def returning_id?
  @returning_id
end

#type_cast(value) ⇒ Object

:nodoc:



30
31
32
33
34
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 30

def type_cast(value) #:nodoc:
  return OracleEnhancedColumn::string_to_raw(value) if type == :raw
  return guess_date_or_time(value) if type == :datetime && OracleEnhancedAdapter.emulate_dates
  super
end

#virtual?Boolean



36
37
38
# File 'lib/active_record/connection_adapters/oracle_enhanced/column.rb', line 36

def virtual?
  @virtual
end