class Upsert::Connection::Mysql2_Client

@private

Public Instance Methods

execute(sql) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 5
def execute(sql)
  Upsert.logger.debug { %{[upsert] #{sql}} }
  if results = metal.query(sql)
    rows = []
    results.each { |row| rows << row }
    if rows[0].is_a? Array
      # you don't know if mysql2 is going to give you an array or a hash... and you shouldn't specify, because it's sticky
      fields = results.fields
      rows.map { |row| Hash[fields.zip(row)] }
    else
      rows
    end
  end
end
quote_big_decimal(v) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 71
def quote_big_decimal(v)
  v.to_s('F')
end
quote_binary(v) click to toggle source

This doubles the size of the representation.

# File lib/upsert/connection/Mysql2_Client.rb, line 55
def quote_binary(v)
  X_AND_SINGLE_QUOTE + v.unpack("H*")[0] + SINGLE_QUOTE
end
quote_boolean(v) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 46
def quote_boolean(v)
  v ? 'TRUE' : 'FALSE'
end
quote_date(v) click to toggle source

put raw binary straight into sql might work if we could get the encoding issues fixed when joining together the values for the sql alias_method :quote_binary, :quote_string

# File lib/upsert/connection/Mysql2_Client.rb, line 63
def quote_date(v)
  quote_string v.strftime(ISO8601_DATE)
end
quote_ident(k) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 67
def quote_ident(k)
  BACKTICK + metal.escape(k.to_s) + BACKTICK
end
quote_string(v) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 50
def quote_string(v)
  SINGLE_QUOTE + metal.escape(v) + SINGLE_QUOTE
end
quote_value(v) click to toggle source
# File lib/upsert/connection/Mysql2_Client.rb, line 20
def quote_value(v)
  case v
  when NilClass
    NULL_WORD
  when Upsert::Binary
    quote_binary v.value
  when String
    quote_string v
  when TrueClass, FalseClass
    quote_boolean v
  when BigDecimal
    quote_big_decimal v
  when Numeric
    v
  when Symbol
    quote_string v.to_s
  when DateTime, Time
    # mysql doesn't like it when you send timezone to a datetime
    quote_string Upsert.utc_iso8601(v, false)
  when Date
    quote_date v
  else
    raise "not sure how to quote #{v.class}: #{v.inspect}"
  end
end