Module: Og::MysqlUtils

Includes:
SqlUtils
Included in:
MysqlAdapter, MysqlAdapter
Defined in:
lib/og/adapter/mysql/utils.rb

Instance Method Summary collapse

Methods included from SqlUtils

#blob, #build_join_name, #create_join_table_sql, #date, #join_class_ordering, #join_object_ordering, #join_table, #join_table_index, #join_table_info, #join_table_key, #join_table_keys, #ordered_join_table_keys, #parse_blob, #parse_boolean, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote_array, #table, #tableize, #timestamp

Instance Method Details

#escape(str) ⇒ Object



8
9
10
11
# File 'lib/og/adapter/mysql/utils.rb', line 8

def escape(str)
  return nil unless str
  return Mysql.quote(str)
end

#quote(vals) ⇒ Object

Escape the various Ruby types.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/og/adapter/mysql/utils.rb', line 15

def quote(vals)
  vals = [vals] unless vals.is_a?(Array)
  quoted = vals.inject('') do |s, val|
    s += case val
      when Fixnum, Integer, Float
        val ? val.to_s : 'NULL'
      when String
        val ? "'#{escape(val)}'" : 'NULL'
      when Time
        val ? "'#{timestamp(val)}'" : 'NULL'
      when Date
        val ? "'#{date(val)}'" : 'NULL'
      when TrueClass, FalseClass
        val ? "'1'" : 'NULL'
      else
        # gmosx: keep the '' for nil symbols.
        val ? escape(val.to_yaml) : ''
    end + ','
  end
  quoted.chop!
  vals.size > 1 ? "(#{quoted})" : quoted
end