Methods
Q
T
Instance Public methods
quote(value, column = nil)

Quotes the column value to help prevent SQL injection attacks.

    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 8
 8:       def quote(value, column = nil)
 9:         # records are quoted as their primary key
10:         return value.quoted_id if value.respond_to?(:quoted_id)
11: 
12:         case value
13:         when String, ActiveSupport::Multibyte::Chars
14:           value = value.to_s
15:           return "'#{quote_string(value)}'" unless column
16: 
17:           case column.type
18:           when :binary then "'#{quote_string(column.string_to_binary(value))}'"
19:           when :integer then value.to_i.to_s
20:           when :float then value.to_f.to_s
21:           else
22:             "'#{quote_string(value)}'"
23:           end
24: 
25:         when true, false
26:           if column && column.type == :integer
27:             value ? '1' : '0'
28:           else
29:             value ? quoted_true : quoted_false
30:           end
31:           # BigDecimals need to be put in a non-normalized form and quoted.
32:         when nil        then "NULL"
33:         when BigDecimal then value.to_s('F')
34:         when Numeric    then value.to_s
35:         when Date, Time then "'#{quoted_date(value)}'"
36:         when Symbol     then "'#{quote_string(value.to_s)}'"
37:         else
38:           "'#{quote_string(YAML.dump(value))}'"
39:         end
40:       end
quote_column_name(column_name)

Quotes the column name. Defaults to no quoting.

    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 85
85:       def quote_column_name(column_name)
86:         column_name
87:       end
quote_string(s)

Quotes a string, escaping any ’ (single quote) and \ (backslash) characters.

    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 80
80:       def quote_string(s)
81:         s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
82:       end
quote_table_name(table_name)

Quotes the table name. Defaults to column name quoting.

    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 90
90:       def quote_table_name(table_name)
91:         quote_column_name(table_name)
92:       end
quoted_date(value)
     # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 102
102:       def quoted_date(value)
103:         if value.acts_like?(:time)
104:           zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
105: 
106:           if value.respond_to?(zone_conversion_method)
107:             value = value.send(zone_conversion_method)
108:           end
109:         end
110: 
111:         value.to_s(:db)
112:       end
quoted_false()
     # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 98
 98:       def quoted_false
 99:         "'f'"
100:       end
quoted_true()
    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 94
94:       def quoted_true
95:         "'t'"
96:       end
type_cast(value, column)

Cast a value to a type that the database understands. For example, SQLite does not understand dates, so this method will convert a Date to a String.

    # File activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, line 45
45:       def type_cast(value, column)
46:         return value.id if value.respond_to?(:quoted_id)
47: 
48:         case value
49:         when String, ActiveSupport::Multibyte::Chars
50:           value = value.to_s
51:           return value unless column
52: 
53:           case column.type
54:           when :binary then value
55:           when :integer then value.to_i
56:           when :float then value.to_f
57:           else
58:             value
59:           end
60: 
61:         when true, false
62:           if column && column.type == :integer
63:             value ? 1 : 0
64:           else
65:             value ? 't' : 'f'
66:           end
67:           # BigDecimals need to be put in a non-normalized form and quoted.
68:         when nil        then nil
69:         when BigDecimal then value.to_s('F')
70:         when Numeric    then value
71:         when Date, Time then quoted_date(value)
72:         when Symbol     then value.to_s
73:         else
74:           YAML.dump(value)
75:         end
76:       end