Module: Og::MysqlUtils

Includes:
SqlUtils
Included in:
MysqlStore, MysqlStore
Defined in:
lib/og/store/mysql.rb

Instance Method Summary collapse

Methods included from SqlUtils

#date, #join_table, #parse_date, #parse_float, #parse_int, #parse_timestamp, #table, #timestamp

Instance Method Details

#escape(str) ⇒ Object



40
41
42
43
# File 'lib/og/store/mysql.rb', line 40

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

#quote(val) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/og/store/mysql.rb', line 45

def quote(val)
	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
			val ? "'1'" : 'NULL'
		else 
			# gmosx: keep the '' for nil symbols.
			val ? escape(val.to_yaml) : ''
	end 
end