Module: DBI::DBD::Pg

### Home Classes Methods

### In Files

- lib/dbd/Pg.rb
- lib/dbd/pg/exec.rb

### Namespace

- MODULE DBI::DBD::Pg::Type
- CLASS DBI::DBD::Pg::Database
- CLASS DBI::DBD::Pg::Driver
- CLASS DBI::DBD::Pg::PgExecutor
- CLASS DBI::DBD::Pg::PgExecutorAsync
- CLASS DBI::DBD::Pg::Statement
- CLASS DBI::DBD::Pg::Tuples

### Methods

- ::driver_name
- ::generate_array
- ::parse_type
- ::quote

### Files

- ChangeLog
- LICENSE
- README

### Class/Module Index

Quicksearch

- DBI
- DBI::DBD
- DBI::DBD::Pg
- DBI::DBD::Pg::Database
- DBI::DBD::Pg::Driver
- DBI::DBD::Pg::PgExecutor
- DBI::DBD::Pg::PgExecutorAsync
- DBI::DBD::Pg::Statement
- DBI::DBD::Pg::Statement::DummyQuoter
- DBI::DBD::Pg::Tuples
- DBI::DBD::Pg::Type
- DBI::DBD::Pg::Type::Array
- DBI::DBD::Pg::Type::ByteA

No matching classes.

# DBI::DBD::Pg

DBD::Pg - Database Driver for the PostgreSQL database system.

Requires DBI and the 'pg' gem or package to work.

Only things that extend DBI's results are documented.

### Constants

DESCRIPTION
VERSION

### Public Class Methods

driver_name() click to toggle source

returns 'Pg'

See DBI::TypeUtil#convert for more information.

    # File lib/dbd/Pg.rb, line 60
    def self.driver_name
        "Pg"
    end

generate_array(obj) click to toggle source

This method takes a ruby Array and converts it to PostgreSQL array syntax.

    # File lib/dbd/Pg.rb, line 67
    def self.generate_array(obj)
        # XXX yarr, there be recursion here, and it's probably not a good idea.
        output = "{"
        obj.each do |item|
            case item
            when ::Array
                output += generate_array(item)
            else
                generated = DBI::TypeUtil.convert(driver_name, item)
                generated = case item
                            when String
                                # in strings, escapes are doubled and the quotes are different.
                                # this gets *really* ugly and needs to be well-tested
                                "\"#{generated.gsub(/\\/) { "\\\\" }}\""
                            when Fixnum
                                generated.to_s
                            end
                output += generated
            end
            output += "," # FIXME technically, delimiters are variable
        end

        output.sub(/,$/, '}')
    end

parse_type(ftype) click to toggle source

Parse a postgresql type. Returns a hash with these fields (as Symbol)

- ftype: the full type, as passed in to this method.

- type: the type stripped of all attribute information.

- size: the LHS of the attribute information, typically the precision.

- decimal: the RHS of the attribute information, typically the scale.

- array: true if this type is actually an array of that type.

    # File lib/dbd/Pg.rb, line 108
    def self.parse_type(ftype)
        type = ftype
        pos = ftype.index('(')
        decimal = nil
        size = nil
        array_of_type = nil

        if pos != nil
            type = ftype[0..pos-1]
            size = ftype[pos+1..-2]
            pos = size.index(',')
            if pos != nil
                size, decimal = size.split(',', 2)
                size = size.to_i
                decimal = decimal.to_i
            else
                size = size.to_i
            end
        end

        if type =~ /\[\]$/
            type.sub!(/\[\]$/, '')
            array_of_type = true
        end

        return {
            :ftype   => ftype.dup,
            :type    => type,
            :size    => size,
            :decimal => decimal,
            :array   => array_of_type
        }
    end

quote(value) click to toggle source

A quote helper, this uses the new syntax in PostgreSQL 8.2 and up.

    # File lib/dbd/Pg.rb, line 95
    def self.quote(value)
        "E'#{ value.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' } }'"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.