Class: ActiveRecord::ConnectionAdapters::ColumnWithIdentity

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

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Column

#default, #limit, #name, #type

Instance Method Summary collapse

Methods inherited from Column

#human_name, #klass, #type_cast

Constructor Details

#initialize(name, default, sql_type = nil, is_identity = false, scale_value = 0) ⇒ ColumnWithIdentity

Returns a new instance of ColumnWithIdentity.



39
40
41
42
43
44
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 39

def initialize(name, default, sql_type = nil, is_identity = false, scale_value = 0)
  super(name, default, sql_type)

  @scale = scale_value
  @identity = is_identity
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



37
38
39
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 37

def identity
  @identity
end

#scaleObject (readonly)

Returns the value of attribute scale.



37
38
39
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 37

def scale
  @scale
end

Instance Method Details

#binary_to_string(value) ⇒ Object



46
47
48
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 46

def binary_to_string(value)
  value
end

#simplified_type(field_type) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 54

def simplified_type(field_type)
  case field_type
    when /int/i
      :integer
    when /float|double|decimal|numeric/i
      if @scale == 0
        :integer
      else  
        :float
        nil
      end  
    when /datetime/i
      :datetime
    when /timestamp/i
      :timestamp
    when /time/i
      :time
    when /date/i
      :date
    when /clob|text|ntext/i
      :text
    when /blob|binary|image/i
      :binary
    when /char|string/i
      :string
    when /boolean|bit/i
      :boolean
  end
end

#string_to_binary(value) ⇒ Object



50
51
52
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 50

def string_to_binary(value)
  value
end

#string_to_time(string) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_record/connection_adapters/sqlserver_adapter.rb', line 84

def string_to_time(string)
  return string if string.is_a?(Time)
  time_array = ParseDate.parsedate(string, true)
  time_array.each_index do |i|
    case i
      when 0
        time_array[i] = time_array[i].nil? ? "2000" : time_array[i].to_s
      when 1
        time_array[i] = time_array[i].nil? ? "Jan" : time_array[i].to_s
      when 2
        time_array[i] = time_array[i].nil? ? "1" : time_array[i].to_s
      when 3
        time_array[i] = time_array[i].nil? ? "0" : time_array[i].to_s
      when 4
        time_array[i] = time_array[i].nil? ? "0" : time_array[i].to_s
      when 5
        time_array[i] = time_array[i].nil? ? "0" : time_array[i].to_s
    end
  end
  # treat 0000-00-00 00:00:00 as nil
  Time.send(Base.default_timezone, *time_array) rescue nil
end