Class: ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column

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

Overview

:nodoc:

Direct Known Subclasses

HbaseAdapter::Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false, extra = "") ⇒ Column

Returns a new instance of Column.



41
42
43
44
45
46
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 41

def initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false, extra = "")
  @strict    = strict
  @collation = collation
  @extra     = extra
  super(name, default, sql_type, null)
end

Instance Attribute Details

#collationObject (readonly)

Returns the value of attribute collation.



39
40
41
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 39

def collation
  @collation
end

#extraObject (readonly)

Returns the value of attribute extra.



39
40
41
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 39

def extra
  @extra
end

#strictObject (readonly)

Returns the value of attribute strict.



39
40
41
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 39

def strict
  @strict
end

Instance Method Details

#adapterObject

Must return the relevant concrete adapter

Raises:

  • (NotImplementedError)


72
73
74
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 72

def adapter
  raise NotImplementedError
end

#blob_or_text_column?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 67

def blob_or_text_column?
  sql_type =~ /blob/i || type == :text
end

#case_sensitive?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 76

def case_sensitive?
  collation && !collation.match(/_ci$/)
end

#extract_default(default) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 48

def extract_default(default)
  if blob_or_text_column?
    if default.blank?
      null || strict ? nil : ''
    else
      raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}"
    end
  elsif missing_default_forged_as_empty_string?(default)
    nil
  else
    super
  end
end

#has_default?Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/active_record/connection_adapters/abstract_mysql_adapter.rb', line 62

def has_default?
  return false if blob_or_text_column? #mysql forbids defaults on blob and text columns
  super
end