Class: ActiveRecord::ConnectionAdapters::MSSQLColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/arjdbc/mssql/column.rb

Overview

MSSQL specific extensions to column definitions in a table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, raw_default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil) ⇒ MSSQLColumn

Returns a new instance of MSSQLColumn.



9
10
11
12
13
14
15
# File 'lib/arjdbc/mssql/column.rb', line 9

def initialize(name, raw_default,  = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil)
  @table_name = table_name

  default_val, default_fun = extract_default(raw_default)

  super(name, default_val, , null, default_fun, collation: collation, comment: comment)
end

Instance Attribute Details

#table_nameObject (readonly)

Returns the value of attribute table_name.



7
8
9
# File 'lib/arjdbc/mssql/column.rb', line 7

def table_name
  @table_name
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



43
44
45
46
47
# File 'lib/arjdbc/mssql/column.rb', line 43

def ==(other)
  other.is_a?(MSSQLColumn) &&
    super &&
    table_name == other.table_name
end

#extract_default(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arjdbc/mssql/column.rb', line 17

def extract_default(value)
  return [nil, nil] unless value

  case value
  when /\A\(N?'(.*)'\)\Z/m
    [unquote_string(Regexp.last_match[1]), nil]
  when /\A\(\((.*)\)\)\Z/
    [unquote_string(Regexp.last_match[1]), nil]
  when /\A\((\w+\(\))\)\Z/
    [nil, unquote_string(Regexp.last_match[1])]
  else
    # return nil if default does not match the patterns to avoid
    # any unexpected errors.
    [nil, nil]
  end
end

#hashObject



50
51
52
53
54
# File 'lib/arjdbc/mssql/column.rb', line 50

def hash
  MSSQLColumn.hash ^
    super.hash ^
    table_name.hash
end

#identity?Boolean Also known as: auto_incremented_by_db?

Returns:

  • (Boolean)


38
39
40
# File 'lib/arjdbc/mssql/column.rb', line 38

def identity?
  sql_type.downcase.include? 'identity'
end

#unquote_string(string) ⇒ Object



34
35
36
# File 'lib/arjdbc/mssql/column.rb', line 34

def unquote_string(string)
  string.to_s.gsub("''", "'")
end