Class: ActiveRecord::ConnectionAdapters::MysqlColumn

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

Overview

:nodoc:

Constant Summary

Constants inherited from Column

Column::FALSE_VALUES, Column::TRUE_VALUES

Instance Attribute Summary

Attributes inherited from Column

#coder, #default, #limit, #name, #null, #precision, #primary, #scale, #sql_type, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Column

binary_to_string, #human_name, #initialize, #klass, #number?, string_to_binary, #string_to_binary, #text?, #type_cast, #type_cast_code, value_to_boolean, value_to_decimal

Constructor Details

This class inherits a constructor from ActiveRecord::ConnectionAdapters::Column

Class Method Details

.string_to_date(v) ⇒ Object



64
65
66
67
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 64

def string_to_date(v)
  return super unless Mysql::Time === v
  new_date(v.year, v.month, v.day)
end

.string_to_dummy_time(v) ⇒ Object



59
60
61
62
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 59

def string_to_dummy_time(v)
  return super unless Mysql::Time === v
  new_time(2000, 01, 01, v.hour, v.minute, v.second, v.second_part)
end

.string_to_time(value) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 47

def string_to_time(value)
  return super unless Mysql::Time === value
  new_time(
    value.year,
    value.month,
    value.day,
    value.hour,
    value.minute,
    value.second,
    value.second_part)
end

Instance Method Details

#extract_default(default) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 70

def extract_default(default)
  if sql_type =~ /blob/i || type == :text
    if default.blank?
      return null ? 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)


84
85
86
87
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 84

def has_default?
  return false if sql_type =~ /blob/i || type == :text #mysql forbids defaults on blob and text columns
  super
end