class SQLValue

Class representing SQL scalar values

Public Class Methods

new( val = nil ) click to toggle source
# File lib/sqlobject.rb, line 129
def initialize ( val = nil )
    @value = val.is_a?( SQLValue )  ?  val.value  :  _escape( val )
end

Public Instance Methods

to_s() click to toggle source
# File lib/sqlobject.rb, line 134
def to_s
    @value
end

Private Instance Methods

_escape( val ) click to toggle source

DERIVED FROM github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

# File lib/sqlobject.rb, line 143
def _escape ( val )
    case val
        when String     then "'#{_quoteString(val.to_s)}'"
        when true       then 'TRUE'
        when false      then 'FALSE'
        when nil        then "NULL"
        when Numeric, Time then val.to_s
        when Symbol     then "'#{_quoteString(val.to_s)}'"
        when Class      then "'#{val.to_s}'"
        else
            "'#{quoteString( val.to_s )}'"
    end
end
_quoteString( str ) click to toggle source

FROM github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb Quotes a string, escaping any ' (single quote) and \ (backslash) characters.

# File lib/sqlobject.rb, line 162
def _quoteString ( str )
    str.gsub( /\\/, '\&\&' ).gsub( /'/, "''" ) # ' (for ruby-mode)
end