In Files

Parent

Class/Module Index [+]

Quicksearch

PGconn

The PG connection class.

Constants

CONNECT_ARGUMENT_ORDER

The order the options are passed to the ::connect method.

Public Class Methods

parse_connect_args( *args ) click to toggle source

Parse the connection args into a connection-parameter string @param [Array<String>] args the connection parameters @return [String] a connection parameters string

# File lib/pg.rb, line 35
def self::parse_connect_args( *args )
    return '' if args.empty?

    # This will be swapped soon for code that makes options like those required for
    # PQconnectdbParams()/PQconnectStartParams(). For now, stick to an options string for
    # PQconnectdb()/PQconnectStart().
    connopts = []

    # Handle an options hash first
    if args.last.is_a?( Hash )
        opthash = args.pop 
        opthash.each do |key, val|
            connopts.push( "%s=%s" % [key, PGconn.quote_connstr(val)] )
        end
    end

    # Option string style
    if args.length == 1 && args.first.to_s.index( '=' )
        connopts.unshift( args.first )

    # Append positional parameters
    else
        args.each_with_index do |val, i|
            next unless val # Skip nil placeholders

            key = CONNECT_ARGUMENT_ORDER[ i ] or
                raise ArgumentError, "Extra positional parameter %d: %p" % [ i+1, val ]
            connopts.push( "%s=%s" % [key, PGconn.quote_connstr(val.to_s)] )
        end
    end

    return connopts.join(' ')
end
quote_connstr( value ) click to toggle source

Quote the given value for use in a connection-parameter string. @param [String] value the option value to be quoted. @return [String]

# File lib/pg.rb, line 27
def self::quote_connstr( value )
    return "'" + value.to_s.gsub( /[\\']/ ) {|m| '\' + m } + "'"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.