Class: PG::BasicTypeMapForResults

### Home Classes Methods

### In Files

- lib/pg/basic_type_mapping.rb

### Parent

PG::TypeMapByOid

### Namespace

- CLASS PG::BasicTypeMapForResults::WarningTypeMap

### Methods

- ::new

### Included Modules

- PG::BasicTypeRegistry

### Files

- LICENSE
- Manifest.txt
- POSTGRES
- README-OS_X.rdoc
- README-Windows.rdoc
- README.ja.rdoc
- README.rdoc
- errorcodes.txt

### Class/Module Index

Quicksearch

- PG
- PG::BasicTypeMapBasedOnResult
- PG::BasicTypeMapForQueries
- PG::BasicTypeMapForResults
- PG::BasicTypeMapForResults::WarningTypeMap
- PG::BasicTypeRegistry
- PG::BasicTypeRegistry::CoderMap
- PG::Coder
- PG::Coder::BinaryFormatting
- PG::CompositeCoder
- PG::Connection
- PG::Connection
- PG::Constants
- PG::CopyCoder
- PG::Error
- PG::NotAllCopyDataRetrieved
- PG::Result
- PG::Result
- PG::TextDecoder
- PG::TextDecoder::Date
- PG::TextDecoder::TimestampWithTimeZone
- PG::TextDecoder::TimestampWithoutTimeZone
- PG::TextEncoder
- PG::TextEncoder::Date
- PG::TextEncoder::TimestampWithTimeZone
- PG::TextEncoder::TimestampWithoutTimeZone
- PG::TypeMapByColumn
- Object
- Object::PGconn
- Object::PGresult

No matching classes.

# PG::BasicTypeMapForResults

Simple set of rules for type casting common PostgreSQL types to Ruby.

OIDs of supported type casts are not hard-coded in the sources, but are retrieved from the PostgreSQL's pg_type table in PG::BasicTypeMapForResults.new .

Result values are type casted based on the type OID of the given result column.

Higher level libraries will most likely not make use of this class, but use their own set of rules to choose suitable encoders and decoders.

Example:

    conn = PG::Connection.new
    # Assign a default ruleset for type casts of input and output values.
    conn.type_mapping = PG::BasicTypeMapping.new(conn)
    # Execute a query.
    res = conn.exec_params( "SELECT $1::INT", ['5'] )
    # Retrieve and cast the result value. Value format is 0 (text) and OID is 20. Therefore typecasting
    # is done by PG::TextDecoder::Integer internally for all value retrieval methods.
    res.values  # => [[5]]

PG::TypeMapByOid#fit_to_result(result, false) can be used to generate a result independent PG::TypeMapByColumn type map, which can subsequently be used to cast get_copy_data fields. See also PG::BasicTypeMapBasedOnResult .

### Public Class Methods

new(connection) click to toggle source

    # File lib/pg/basic_type_mapping.rb, line 261
    def initialize(connection)
            @coder_maps = build_coder_maps(connection)

            # Populate TypeMapByOid hash with decoders
            @coder_maps.map{|f| f[:decoder].coders }.flatten.each do |coder|
                    add_coder(coder)
            end

            typenames = @coder_maps.map{|f| f[:decoder].typenames_by_oid }
            self.default_type_map = WarningTypeMap.new(typenames)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.