Module: Tramp::Quoting

Included in:
Engine
Defined in:
lib/tramp/quoting.rb

Instance Method Summary collapse

Instance Method Details

#quote(value, column = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/tramp/quoting.rb', line 34

def quote(value, column = nil)
  if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
    s = value.unpack("H*")[0]
    "x'#{s}'"
  elsif value.kind_of?(BigDecimal)
    value.to_s("F")
  else
    super
  end
end

#quote_column_name(name) ⇒ Object



26
27
28
# File 'lib/tramp/quoting.rb', line 26

def quote_column_name(name)
  @quoted_column_names[name] ||= "`#{name}`"
end

#quote_string(s) ⇒ Object

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



77
78
79
# File 'lib/tramp/quoting.rb', line 77

def quote_string(s)
  s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
end

#quote_table_name(name) ⇒ Object



30
31
32
# File 'lib/tramp/quoting.rb', line 30

def quote_table_name(name)
  @quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`')
end

#quoted_date(value) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/tramp/quoting.rb', line 89

def quoted_date(value)
  if value.acts_like?(:time)
    zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
    value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
  else
    value
  end.to_s(:db)
end

#quoted_falseObject



85
86
87
# File 'lib/tramp/quoting.rb', line 85

def quoted_false
  "'f'"
end

#quoted_string_prefixObject



98
99
100
# File 'lib/tramp/quoting.rb', line 98

def quoted_string_prefix
  ''
end

#quoted_trueObject



81
82
83
# File 'lib/tramp/quoting.rb', line 81

def quoted_true
  "'t'"
end