method
quote
rails latest stable - Class:
ActiveRecord::ConnectionAdapters::Quoting
quote(value)public
Quotes the column value to help prevent SQL injection attacks.
# File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 12
def quote(value)
case value
when String, Symbol, ActiveSupport::Multibyte::Chars
"'#{quote_string(value.to_s)}'"
when true then quoted_true
when false then quoted_false
when nil then "NULL"
# BigDecimals need to be put in a non-normalized form and quoted.
when BigDecimal then value.to_s("F")
when Numeric then value.to_s
when Type::Binary::Data then quoted_binary(value)
when Type::Time::Value then "'#{quoted_time(value)}'"
when Date, Time then "'#{quoted_date(value)}'"
when Class then "'#{value}'"
when ActiveSupport::Duration
warn_quote_duration_deprecated
value.to_s
else raise TypeError, "can't quote #{value.class.name}"
end
end Related methods
- Instance methods
- cast_bound_value
- column_name_matcher
- column_name_with_order_matcher
- lookup_cast_type_from_column
- quote
- quote_bound_value
- quote_column_name
- quote_default_expression
- quote_string
- quote_table_name
- quote_table_name_for_assignment
- quoted_binary
- quoted_date
- quoted_false
- quoted_time
- quoted_true
- sanitize_as_sql_comment
- type_cast
- unquoted_false
- unquoted_true
- Private methods
-
lookup_cast_type -
type_casted_binds -
warn_quote_duration_deprecated