Module: ActiveRecord::ConnectionAdapters::MySQL::Quoting
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | activerecord/lib/active_record/connection_adapters/mysql/quoting.rb |
Constant Summary
-
COLUMN_NAME =
private
# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 96/ \A ( (?: # `table_name`.`column_name` | function(one or no argument) ((?:\w\.|`\w`\.)?(?:\w|`\w`) | \w+\((?:|\g<2>)\)) ) (?:(?:\sAS)?\s(?:\w|`\w`))? ) (?:\s*,\s*\g<1>)* \z /ix
-
COLUMN_NAME_WITH_ORDER =
private
# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 109/ \A ( (?: # `table_name`.`column_name` | function(one or no argument) ((?:\w\.|`\w`\.)?(?:\w|`\w`) | \w+\((?:|\g<2>)\)) ) (?:\sCOLLATE\s(?:\w|"\w"))? (?:\sASC|\sDESC)? ) (?:\s*,\s*\g<1>)* \z /ix
-
QUOTED_COLUMN_NAMES =
# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 9Concurrent::Map.new
-
QUOTED_TABLE_NAMES =
# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 10Concurrent::Map.new
Instance Method Summary
- #cast_bound_value(value)
- #column_name_matcher
- #column_name_with_order_matcher
- #quote_column_name(name)
- #quote_table_name(name)
- #quoted_binary(value)
- #quoted_date(value)
-
#type_cast(value)
Override
type_cast
we pass to mysql2::Date
and::Time
objects instead of Strings since::ActiveRecord::ConnectionAdapters::MySQL
adapters are able to handle those classes more efficiently. - #unquote_identifier(identifier)
- #unquoted_false
- #unquoted_true
Instance Method Details
#cast_bound_value(value)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 12
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" when ActiveSupport::Duration warn_quote_duration_deprecated value.to_s else value end end
#column_name_matcher
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 88
def column_name_matcher COLUMN_NAME end
#column_name_with_order_matcher
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 92
def column_name_with_order_matcher COLUMN_NAME_WITH_ORDER end
#quote_column_name(name)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 32
def quote_column_name(name) QUOTED_COLUMN_NAMES[name] ||= "`#{super.gsub('`', '``')}`" end
#quote_table_name(name)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 36
def quote_table_name(name) QUOTED_TABLE_NAMES[name] ||= super.gsub(".", "`.`").freeze end
#quoted_binary(value)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 56
def quoted_binary(value) "x'#{value.hex}'" end
#quoted_date(value)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 48
def quoted_date(value) if supports_datetime_with_precision? super else super.sub(/\.\d{6}\z/, "") end end
#type_cast(value)
Override type_cast
we pass to mysql2 ::Date
and ::Time
objects instead of Strings since ::ActiveRecord::ConnectionAdapters::MySQL
adapters are able to handle those classes more efficiently.
# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 70
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 Date, Time value else super end end
#unquote_identifier(identifier)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 60
def unquote_identifier(identifier) if identifier && identifier.start_with?("`") identifier[1..-2] else identifier end end
#unquoted_false
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 44
def unquoted_false 0 end
#unquoted_true
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/quoting.rb', line 40
def unquoted_true 1 end