module Db2Query::Quoting::ClassMethods

Public Instance Methods

quoted_binary(value) click to toggle source
# File lib/db2_query/quoting.rb, line 26
def quoted_binary(value)
  "x'#{value.hex}'"
end
quoted_date(value) click to toggle source
# File lib/db2_query/quoting.rb, line 35
def quoted_date(value)
  if value.acts_like?(:time)
    if ActiveRecord::Base.default_timezone == :utc
      value = value.getutc if !value.utc?
    else
      value = value.getlocal
    end
  end

  result = value.to_s(:db)
  if value.respond_to?(:usec) && value.usec > 0
    result << "." << sprintf("%06d", value.usec)
  else
    result
  end
end
quoted_false() click to toggle source
# File lib/db2_query/quoting.rb, line 18
def quoted_false
  "FALSE"
end
quoted_time(value) click to toggle source
# File lib/db2_query/quoting.rb, line 30
def quoted_time(value)
  value = value.change(year: 2000, month: 1, day: 1)
  quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "")
end
quoted_true() click to toggle source
# File lib/db2_query/quoting.rb, line 10
def quoted_true
  "TRUE"
end
unquoted_false() click to toggle source
# File lib/db2_query/quoting.rb, line 22
def unquoted_false
  0
end
unquoted_true() click to toggle source
# File lib/db2_query/quoting.rb, line 14
def unquoted_true
  1
end

Private Instance Methods

_quote(value) click to toggle source
# File lib/db2_query/quoting.rb, line 53
def _quote(value)
  case value
  when String, Symbol, ActiveSupport::Multibyte::Chars
    "'#{quote_string(value.to_s)}'"
  when true
    quoted_true
  when false
    quoted_false
  when nil
    "NULL"
  when BigDecimal
    value.to_s("F")
  when Numeric, ActiveSupport::Duration
    value.to_s
  when Db2Query::Type::Binary::Data
    quoted_binary(value)
  when ActiveRecord::Type::Time::Value
    "'#{quoted_time(value)}'"
  when Date, Time
    "'#{quoted_date(value)}'"
  when Class
    "'#{value}'"
  else raise TypeError, "can't quote #{value.class.name}"
  end
end
_type_cast(value) click to toggle source
# File lib/db2_query/quoting.rb, line 79
def _type_cast(value)
  case value
  when Symbol, ActiveSupport::Multibyte::Chars
    value.to_s
  when Db2Query::Type::Binary::Data
    value.hex
  when true
    unquoted_true
  when false
    unquoted_false
  when BigDecimal
    value.to_s("F")
  when nil, Numeric, String
    value
  when ActiveRecord::Type::Time::Value
    quoted_time(value)
  when Date, Time
    quoted_date(value)
  else raise TypeError, "can't cast #{value.class.name}"
  end
end