Module: ActiveRecord::ConnectionAdapters::Quoting

### Home Classes Methods

### In Files

- lib/active_record/connection_adapters/abstract/quoting.rb

### Methods

- #quote
- #quote_column_name
- #quote_string
- #quote_table_name
- #quoted_date
- #quoted_false
- #quoted_true

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::ActiveRecordError
- ActiveRecord::AdapterNotFound
- ActiveRecord::AdapterNotSpecified
- ActiveRecord::Aggregations
- ActiveRecord::Aggregations::ClassMethods
- ActiveRecord::AssociationPreload
- ActiveRecord::AssociationPreload::ClassMethods
- ActiveRecord::AssociationTypeMismatch
- ActiveRecord::Associations
- ActiveRecord::Associations::ClassMethods
- ActiveRecord::Associations::HasOneThroughAssociation
- ActiveRecord::Associations::ThroughAssociationScope
- ActiveRecord::AttributeAssignmentError
- ActiveRecord::AttributeMethods
- ActiveRecord::AttributeMethods::BeforeTypeCast
- ActiveRecord::AttributeMethods::ClassMethods
- ActiveRecord::AttributeMethods::Dirty
- ActiveRecord::AttributeMethods::PrimaryKey
- ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods
- ActiveRecord::AttributeMethods::Query
- ActiveRecord::AttributeMethods::Read
- ActiveRecord::AttributeMethods::Read::ClassMethods
- ActiveRecord::AttributeMethods::TimeZoneConversion
- ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods
- ActiveRecord::AttributeMethods::Write
- ActiveRecord::AttributeMethods::Write::ClassMethods
- ActiveRecord::AutosaveAssociation
- ActiveRecord::AutosaveAssociation::ClassMethods
- ActiveRecord::Base
- ActiveRecord::Calculations
- ActiveRecord::Callbacks
- ActiveRecord::Callbacks::ClassMethods
- ActiveRecord::ConfigurationError
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::ConnectionAdapters::Column::Format
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- ActiveRecord::ConnectionAdapters::ConnectionManagement
- ActiveRecord::ConnectionAdapters::ConnectionPool
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::SQLiteAdapter
- ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- ActiveRecord::ConnectionAdapters::SchemaStatements
- ActiveRecord::ConnectionAdapters::Table
- ActiveRecord::ConnectionAdapters::TableDefinition
- ActiveRecord::ConnectionNotEstablished
- ActiveRecord::ConnectionTimeoutError
- ActiveRecord::CounterCache
- ActiveRecord::DangerousAttributeError
- ActiveRecord::DynamicFinderMatch
- ActiveRecord::DynamicScopeMatch
- ActiveRecord::FinderMethods
- ActiveRecord::Generators
- ActiveRecord::Generators::Migration
- ActiveRecord::Generators::MigrationGenerator
- ActiveRecord::Generators::ModelGenerator
- ActiveRecord::Generators::ObserverGenerator
- ActiveRecord::Generators::SessionMigrationGenerator
- ActiveRecord::InvalidForeignKey
- ActiveRecord::IrreversibleMigration
- ActiveRecord::Locking
- ActiveRecord::Locking::Optimistic
- ActiveRecord::Locking::Optimistic::ClassMethods
- ActiveRecord::Locking::Pessimistic
- ActiveRecord::LogSubscriber
- ActiveRecord::Migration
- ActiveRecord::MigrationProxy
- ActiveRecord::MultiparameterAssignmentErrors
- ActiveRecord::NamedScope
- ActiveRecord::NamedScope::ClassMethods
- ActiveRecord::NestedAttributes
- ActiveRecord::NestedAttributes::ClassMethods
- ActiveRecord::NestedAttributes::TooManyRecords
- ActiveRecord::Observer
- ActiveRecord::Persistence
- ActiveRecord::PredicateBuilder
- ActiveRecord::PreparedStatementInvalid
- ActiveRecord::QueryCache
- ActiveRecord::QueryCache::ClassMethods
- ActiveRecord::QueryMethods
- ActiveRecord::Railtie
- ActiveRecord::Railties
- ActiveRecord::Railties::ControllerRuntime
- ActiveRecord::Railties::ControllerRuntime::ClassMethods
- ActiveRecord::ReadOnlyRecord
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::RecordNotUnique
- ActiveRecord::Reflection
- ActiveRecord::Reflection::ClassMethods
- ActiveRecord::Reflection::MacroReflection
- ActiveRecord::Relation
- ActiveRecord::Rollback
- ActiveRecord::Schema
- ActiveRecord::Serialization
- ActiveRecord::SerializationTypeMismatch
- ActiveRecord::SessionStore
- ActiveRecord::SessionStore::Session
- ActiveRecord::SessionStore::SqlBypass
- ActiveRecord::SpawnMethods
- ActiveRecord::StaleObjectError
- ActiveRecord::StatementInvalid
- ActiveRecord::TestFixtures
- ActiveRecord::TestFixtures::ClassMethods
- ActiveRecord::ThrowResult
- ActiveRecord::Timestamp
- ActiveRecord::Transactions
- ActiveRecord::Transactions::ClassMethods
- ActiveRecord::UnknownAttributeError
- ActiveRecord::Validations
- ActiveRecord::Validations::AssociatedValidator
- ActiveRecord::Validations::ClassMethods
- ActiveRecord::Validations::UniquenessValidator
- ActiveRecord::WrappedDatabaseException
- <
- Fixtures
- FixturesFileNotFound

No matching classes.

# ActiveRecord::ConnectionAdapters::Quoting

### Public Instance Methods

quote(value, column = nil) click to toggle source

Quotes the column value to help prevent SQL injection attacks.

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 8
    def quote(value, column = nil)
      # records are quoted as their primary key
      return value.quoted_id if value.respond_to?(:quoted_id)

      case value
        when String, ActiveSupport::Multibyte::Chars
          value = value.to_s
          if column && column.type == :binary && column.class.respond_to?(:string_to_binary)
            "'#{quote_string(column.class.string_to_binary(value))}'" # ' (for ruby-mode)
          elsif column && [:integer, :float].include?(column.type)
            value = column.type == :integer ? value.to_i : value.to_f
            value.to_s
          else
            "'#{quote_string(value)}'" # ' (for ruby-mode)
          end
        when NilClass                 then "NULL"
        when TrueClass                then (column && column.type == :integer ? '1' : quoted_true)
        when FalseClass               then (column && column.type == :integer ? '0' : quoted_false)
        when Float, Fixnum, Bignum    then value.to_s
        # BigDecimals need to be output in a non-normalized form and quoted.
        when BigDecimal               then value.to_s('F')
        when Symbol                   then "'#{quote_string(value.to_s)}'"
        else
          if value.acts_like?(:date) || value.acts_like?(:time)
            "'#{quoted_date(value)}'"
          else
            "'#{quote_string(value.to_yaml)}'"
          end
      end
    end

quote_column_name(column_name) click to toggle source

Quotes the column name. Defaults to no quoting.

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 46
    def quote_column_name(column_name)
      column_name
    end

quote_string(s) click to toggle source

Quotes a string, escaping any ‘ (single quote) and \ (backslash) characters.

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 41
    def quote_string(s)
      s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
    end

quote_table_name(table_name) click to toggle source

Quotes the table name. Defaults to column name quoting.

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 51
    def quote_table_name(table_name)
      quote_column_name(table_name)
    end

quoted_date(value) click to toggle source

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 63
    def quoted_date(value)
      if value.acts_like?(:time)
        zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
        value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
      else
        value
      end.to_s(:db)
    end

quoted_false() click to toggle source

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 59
    def quoted_false
      "'f'"
    end

quoted_true() click to toggle source

    # File lib/active_record/connection_adapters/abstract/quoting.rb, line 55
    def quoted_true
      "'t'"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.