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

Included in:
ActiveRecord::ConnectionAdapters::SQLite3Adapter
Defined in:
lib/active_record/connection_adapters/sqlite3/quoting.rb

Overview

:nodoc:

Constant Summary collapse

QUOTED_COLUMN_NAMES =

:nodoc:

Concurrent::Map.new
QUOTED_TABLE_NAMES =

:nodoc:

Concurrent::Map.new

Instance Method Summary collapse

Instance Method Details

#column_name_matcherObject



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

def column_name_matcher
  COLUMN_NAME
end

#column_name_with_order_matcherObject



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

def column_name_with_order_matcher
  COLUMN_NAME_WITH_ORDER
end

#quote_column_name(name) ⇒ Object



22
23
24
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 22

def quote_column_name(name)
  QUOTED_COLUMN_NAMES[name] ||= %Q("#{super.gsub('"', '""')}")
end

#quote_default_expression(value, column) ⇒ Object

:nodoc:



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

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



10
11
12
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 10

def quote_string(s)
  @connection.class.quote(s)
end

#quote_table_name(name) ⇒ Object



18
19
20
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 18

def quote_table_name(name)
  QUOTED_TABLE_NAMES[name] ||= super.gsub(".", "\".\"").freeze
end

#quote_table_name_for_assignment(table, attr) ⇒ Object



14
15
16
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 14

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

#quoted_binary(value) ⇒ Object



31
32
33
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 31

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

#quoted_falseObject



43
44
45
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 43

def quoted_false
  "0"
end

#quoted_time(value) ⇒ Object



26
27
28
29
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 26

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



35
36
37
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 35

def quoted_true
  "1"
end

#type_cast(value) ⇒ Object

:nodoc:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 64

def type_cast(value) # :nodoc:
  case value
  when BigDecimal
    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



47
48
49
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 47

def unquoted_false
  0
end

#unquoted_trueObject



39
40
41
# File 'lib/active_record/connection_adapters/sqlite3/quoting.rb', line 39

def unquoted_true
  1
end