Module: ActiveRecord::ConnectionAdapters::MySQL::Quoting
- Included in:
- AbstractMysqlAdapter
- Defined in:
- lib/active_record/connection_adapters/mysql/quoting.rb
Overview
:nodoc:
Instance Method Summary collapse
- #column_name_matcher ⇒ Object
- #column_name_with_order_matcher ⇒ Object
- #quote_bound_value(value) ⇒ Object
- #quote_column_name(name) ⇒ Object
- #quote_table_name(name) ⇒ Object
- #quoted_binary(value) ⇒ Object
- #quoted_date(value) ⇒ Object
-
#type_cast(value) ⇒ Object
Override
type_cast
we pass to mysql2 Date and Time objects instead of Strings since mysql2 is able to handle those classes more efficiently. - #unquote_identifier(identifier) ⇒ Object
- #unquoted_false ⇒ Object
- #unquoted_true ⇒ Object
Instance Method Details
#column_name_matcher ⇒ Object
82 83 84 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 82 def column_name_matcher COLUMN_NAME end |
#column_name_with_order_matcher ⇒ Object
86 87 88 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 86 def column_name_with_order_matcher COLUMN_NAME_WITH_ORDER end |
#quote_bound_value(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 9 def quote_bound_value(value) case value when Rational quote(value.to_f.to_s) when Numeric, ActiveSupport::Duration quote(value.to_s) when BigDecimal quote(value.to_s("F")) when true "'1'" when false "'0'" else quote(value) end end |
#quote_column_name(name) ⇒ Object
26 27 28 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 26 def quote_column_name(name) self.class.quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`" end |
#quote_table_name(name) ⇒ Object
30 31 32 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 30 def quote_table_name(name) self.class.quoted_table_names[name] ||= super.gsub(".", "`.`").freeze end |
#quoted_binary(value) ⇒ Object
50 51 52 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 50 def quoted_binary(value) "x'#{value.hex}'" end |
#quoted_date(value) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 42 def quoted_date(value) if supports_datetime_with_precision? super else super.sub(/\.\d{6}\z/, "") end end |
#type_cast(value) ⇒ Object
Override type_cast
we pass to mysql2 Date and Time objects instead of Strings since mysql2 is able to handle those classes more efficiently.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 64 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 ActiveRecord.default_timezone == :utc value.getutc else value.getlocal end when Date, Time value else super end end |
#unquote_identifier(identifier) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 54 def unquote_identifier(identifier) if identifier && identifier.start_with?("`") identifier[1..-2] else identifier end end |
#unquoted_false ⇒ Object
38 39 40 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 38 def unquoted_false 0 end |
#unquoted_true ⇒ Object
34 35 36 |
# File 'lib/active_record/connection_adapters/mysql/quoting.rb', line 34 def unquoted_true 1 end |