Sha256: 3659d02b8035e90bde2ced864326fcca6ebc34813ad2b8acf466c2520876ca5c

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

require 'og/store/sql/utils'

module Og

module MysqlUtils
  include SqlUtils
  
  def escape(str)
    return nil unless str
    return Mysql.quote(str)
  end

  # Escape the various Ruby types.

  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

end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
og-0.41.0 lib/og/adapter/mysql/utils.rb
og-0.40.0 lib/og/adapter/mysql/utils.rb