Module: ArJdbc::MSSQL::Column

Includes:
LockMethods
Included in:
ActiveRecord::ConnectionAdapters::MSSQLColumn
Defined in:
lib/arjdbc/mssql/old_column.rb

Overview

Defined Under Namespace

Modules: Cast

Instance Method Summary collapse

Methods included from LockMethods

#add_lock!

Instance Method Details

#default_value(value) ⇒ Object



40
41
42
43
# File 'lib/arjdbc/mssql/old_column.rb', line 40

def default_value(value)
  return $1 if value =~ /^\(N?'(.*)'\)$/ || value =~ /^\(\(?(.*?)\)?\)$/
  value
end

#extract_limit(sql_type) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/arjdbc/mssql/old_column.rb', line 63

def extract_limit(sql_type)
  case sql_type
  when /^smallint/i
    2
  when /^int/i
    4
  when /^bigint/i
    8
  when /\(max\)/, /decimal/, /numeric/
    nil
  when /text|ntext|xml|binary|image|varbinary|bit/
    nil
  else
    super
  end
end

#identity?Boolean Also known as: identity, is_identity

Returns:

  • (Boolean)


85
86
87
# File 'lib/arjdbc/mssql/old_column.rb', line 85

def identity?
  !! sql_type.downcase.index('identity')
end

#is_utf8?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/arjdbc/mssql/old_column.rb', line 107

def is_utf8?
  !!( sql_type =~ /nvarchar|ntext|nchar/i )
end

#primary?Boolean Also known as: is_primary

primary replacement that works on 4.2 as well

columns will set @primary even when on AR 4.2

Returns:

  • (Boolean)


82
# File 'lib/arjdbc/mssql/old_column.rb', line 82

def primary?; @primary end

#simplified_type(field_type) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arjdbc/mssql/old_column.rb', line 20

def simplified_type(field_type)
  case field_type
  when /int|bigint|smallint|tinyint/i           then :integer
  when /numeric/i                               then (@scale.nil? || @scale == 0) ? :integer : :decimal
  when /float|double|money|real|smallmoney/i    then :decimal
  when /datetime|smalldatetime/i                then :datetime
  when /timestamp/i                             then :timestamp
  when /time/i                                  then :time
  when /date/i                                  then :date
  when /text|ntext|xml/i                        then :text
  when /binary|image|varbinary/i                then :binary
  when /char|nchar|nvarchar|string|varchar/i    then (@limit == 1073741823 ? (@limit = nil; :text) : :string)
  when /bit/i                                   then :boolean
  when /uniqueidentifier/i                      then :string
  else
    super
  end
end

#type_cast(value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/arjdbc/mssql/old_column.rb', line 46

def type_cast(value)
  return nil if value.nil?
  case type
  when :integer then ( value.is_a?(String) ? unquote(value) : (value || 0) ).to_i
  when :primary_key then value.respond_to?(:to_i) ? value.to_i : ((value && 1) || 0)
  when :decimal   then self.class.value_to_decimal(unquote(value))
  when :date      then self.class.string_to_date(value)
  when :datetime  then self.class.string_to_time(value)
  when :timestamp then self.class.string_to_time(value)
  when :time      then self.class.string_to_dummy_time(value)
  when :boolean   then value == true || (value =~ /^t(rue)?$/i) == 0 || unquote(value) == '1'
  when :binary    then unquote(value)
  else value
  end
end