Module: ActiveRecord::ConnectionAdapters::MySQL::Quoting

Extended by:
ActiveSupport::Concern
Included in:
AbstractMysqlAdapter
Defined in:
lib/active_record/connection_adapters/mysql/quoting.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

QUOTED_COLUMN_NAMES =

:nodoc:

Concurrent::Map.new
QUOTED_TABLE_NAMES =

:nodoc:

Concurrent::Map.new

Instance Method Summary collapse

Instance Method Details

#cast_bound_value(value) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 55

def cast_bound_value(value)
  case value
  when Rational
    value.to_f.to_s
  when Numeric
    value.to_s
  when BigDecimal
    value.to_s("F")
  when true
    "1"
  when false
    "0"
  else
    value
  end
end

#quoted_binary(value) ⇒ Object



80
81
82
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 80

def quoted_binary(value)
  "x'#{value.hex}'"
end

#type_cast(value) ⇒ Object

Override type_cast we pass to mysql2 Date and Time objects instead of Strings since MySQL adapters are able to handle those classes more efficiently.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 94

def type_cast(value) # :nodoc:
  case value
  when ActiveSupport::TimeWithZone
    # We need to check explicitly for ActiveSupport::TimeWithZone because
    # we need to transform it to Time objects but we don't want to
    # transform Time objects to themselves.
    if default_timezone == :utc
      value.getutc
    else
      value.getlocal
    end
  when Time
    if default_timezone == :utc
      value.utc? ? value : value.getutc
    else
      value.utc? ? value.getlocal : value
    end
  when Date
    value
  else
    super
  end
end

#unquote_identifier(identifier) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 84

def unquote_identifier(identifier)
  if identifier && identifier.start_with?("`")
    identifier[1..-2]
  else
    identifier
  end
end

#unquoted_falseObject



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

def unquoted_false
  0
end

#unquoted_trueObject



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

def unquoted_true
  1
end