Sha256: 299b033563af4fc3c6ca4af032975a9c2888083181b16de0fb116633ebd438bc
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module DataMapper module Adapters module Sql # Quoting is a mixin that extends your DataMapper::Database singleton-class # to allow for object-name and value quoting to be exposed to the queries. # # DESIGN: Is there any need for this outside of the query objects? Should # we just include it in our query object subclasses and not rely on a Quoting # mixin being part of the "standard" Adapter interface? module Quoting def quote_table_name(name) name.ensure_wrapped_with(self.class::TABLE_QUOTING_CHARACTER) end def quote_column_name(name) name.ensure_wrapped_with(self.class::COLUMN_QUOTING_CHARACTER) end def quote_value(value) return 'NULL' if value.nil? case value when Numeric then value.to_s when String then "'#{value.gsub("'", "''")}'" when Class then "'#{value.name}'" when Date then "'#{value.to_s}'" when Time, DateTime then "'#{value.utc.strftime("%Y-%m-%d %H:%M:%S")}'" when TrueClass, FalseClass then value.to_s.upcase when Array then "(#{value.map { |entry| quote_value(entry) }.join(', ')})" else if value.respond_to?(:to_sql) value.to_sql else raise "Don't know how to quote #{value.inspect}" end end end end # module Quoting end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datamapper-0.2.0 | lib/data_mapper/adapters/sql/quoting.rb |