Class: ActiveRecord::ConnectionAdapters::MSSQLColumn

Inherits:
JdbcColumn
  • Object
show all
Includes:
ArJdbc::MSSQL::Column
Defined in:
lib/arjdbc/mssql/column.rb,
lib/arjdbc/mssql/old_adapter.rb

Overview

MSSQL specific extensions to column definitions in a table.

Instance Attribute Summary collapse

Attributes inherited from JdbcColumn

#limit, #precision

Instance Method Summary collapse

Methods included from ArJdbc::MSSQL::Column

#default_value, #extract_limit, #is_utf8?, #primary?, #simplified_type, #type_cast

Methods included from ArJdbc::MSSQL::LockMethods

#add_lock!

Methods inherited from JdbcColumn

column_types, #default_value, #init_column

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 = extract_default(raw_default)

  super(name, default, , null, default_function, 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?



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

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

#extract_default(value) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/arjdbc/mssql/column.rb', line 17

def extract_default(value)
  # return nil if default does not match the patterns to avoid
  # any unexpected errors.
  return unless value =~ /^\(N?'(.*)'\)$/m || value =~ /^\(\(?(.*?)\)?\)$/

  unquote_string(Regexp.last_match[1])
end

#hashObject



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

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

#identity?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/arjdbc/mssql/column.rb', line 29

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

#unquote_string(string) ⇒ Object



25
26
27
# File 'lib/arjdbc/mssql/column.rb', line 25

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