Module: ActiveRecord::ConnectionAdapters::Fb::Quoting

Included in:
ActiveRecord::ConnectionAdapters::FbAdapter
Defined in:
lib/active_record/connection_adapters/fb/quoting.rb

Instance Method Summary collapse

Instance Method Details

#quote(value, column = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_record/connection_adapters/fb/quoting.rb', line 5

def quote(value, column = nil)
  return value.quoted_id if value.respond_to?(:quoted_id)
  type = column && column.type

  case value
  when String, ActiveSupport::Multibyte::Chars
    value = value.to_s
    if [:integer, :float].include?(type)
      (type == :integer ? value.to_i : value.to_f).to_s
    elsif type && type == :binary
      "@BINDBINARY#{Base64.encode64(value.to_s)}BINDBINARY@"
    else
      "'#{quote_string(value)}'"
    end
  when Date, Time
    "@BINDDATE#{quoted_date(value)}BINDDATE@"
  else
    super
  end
end

#quote_column_name(column_name) ⇒ Object

:nodoc:



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

def quote_column_name(column_name) # :nodoc:
  name = ar_to_fb_case(column_name.to_s).gsub('"', '')
  @connection.dialect == 1 ? %Q(#{name}) : %Q("#{name}")
end

#quote_string(string) ⇒ Object

:nodoc:



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

def quote_string(string) # :nodoc:
  string.gsub(/'/, "''")
end

#quote_table_name_for_assignment(_table, attr) ⇒ Object



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

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

#quoted_falseObject

:nodoc:



51
52
53
# File 'lib/active_record/connection_adapters/fb/quoting.rb', line 51

def quoted_false # :nodoc:
  quote unquoted_false
end

#quoted_trueObject

:nodoc:



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

def quoted_true # :nodoc:
  quote unquoted_true
end

#type_cast(value, column) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/active_record/connection_adapters/fb/quoting.rb', line 55

def type_cast(value, column)
  if [true, false].include?(value)
    value ? quoted_true : quoted_false
  else
    super
  end
end

#unquoted_falseObject



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

def unquoted_false
  boolean_domain[:false]
end

#unquoted_trueObject



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

def unquoted_true
  boolean_domain[:true]
end