Module: ActiveRecord::ConnectionAdapters::SQLite3::Quoting

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::ConnectionAdapters::SQLite3Adapter
Defined in:
lib/active_record/connection_adapters/sqlite3/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

#quote(value) ⇒ Object

:nodoc:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 53

def quote(value) # :nodoc:
  case value
  when Numeric
    if value.finite?
      super
    else
      "'#{value}'"
    end
  else
    super
  end
end

#quote_default_expression(value, column) ⇒ Object

:nodoc:



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 99

def quote_default_expression(value, column) # :nodoc:
  if value.is_a?(Proc)
    value = value.call
    if value.match?(/\A\w+\(.*\)\z/)
      "(#{value})"
    else
      value
    end
  else
    super
  end
end

#quote_string(s) ⇒ Object



66
67
68
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 66

def quote_string(s)
  ::SQLite3::Database.quote(s)
end

#quote_table_name_for_assignment(table, attr) ⇒ Object



70
71
72
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 70

def quote_table_name_for_assignment(table, attr)
  quote_column_name(attr)
end

#quoted_binary(value) ⇒ Object



79
80
81
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 79

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

#quoted_falseObject



91
92
93
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 91

def quoted_false
  "0"
end

#quoted_time(value) ⇒ Object



74
75
76
77
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 74

def quoted_time(value)
  value = value.change(year: 2000, month: 1, day: 1)
  quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "2000-01-01 ")
end

#quoted_trueObject



83
84
85
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 83

def quoted_true
  "1"
end

#type_cast(value) ⇒ Object

:nodoc:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 112

def type_cast(value) # :nodoc:
  case value
  when BigDecimal, Rational
    value.to_f
  when String
    if value.encoding == Encoding::ASCII_8BIT
      super(value.encode(Encoding::UTF_8))
    else
      super
    end
  else
    super
  end
end

#unquoted_falseObject



95
96
97
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 95

def unquoted_false
  0
end

#unquoted_trueObject



87
88
89
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 87

def unquoted_true
  1
end