Tom Molesworth > Protocol-PostgreSQL-0.008 > Protocol::PostgreSQL

Download:
Protocol-PostgreSQL-0.008.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.008   Source  

NAME ^

Protocol::PostgreSQL - support for the PostgreSQL wire protocol

VERSION ^

version 0.008

SYNOPSIS ^

 use strict; use warnings;
 package PostgreSQL::Client;
 use parent q{Protocol::PostgreSQL::Client};

 sub new { my $self = shift->SUPER::new(@_); $self->{socket} = $self->connect(...); $self }
 sub on_send_request { shift->socket->send(@_) }
 sub socket { shift->{socket} }

 sub connect { ... } # provide a method to connect to the server
 sub incoming { shift->socket->read(@_) } # provide a method which passes on data from server

 package main;
 my $client = PostgreSQL::Client->new(user => ..., server => ..., database => ...);
 $client->simple_query(sql => q{select * from table}, on_data_row => sub {
        my ($client, %args) = @_;
        my @cols = $args{row};
        print join(',', @cols) . "\n";
 });

DESCRIPTION ^

Provides protocol-level support for PostgreSQL 7.4+, as defined in http://www.postgresql.org/docs/current/static/protocol.html.

CALLBACKS

The following callbacks can be provided either as parameters to "new" or as methods in subclasses:

For the client, the following additional callbacks are available:

And the server can send these events:

METHODS ^

new

Instantiate a new object. Blesses an empty hashref and calls "configure", subclasses can bypass this entirely and just call "configure" directly after instantiation.

configure

Does the real preparation for the object.

Takes callbacks as named parameters, including:

has_queued

Returns number of queued messages.

is_authenticated

Returns true if we are authenticated (and can start sending real data).

is_first_message

Returns true if this is the first message, as per http://developer.postgresql.org/pgdocs/postgres/protocol-overview.html:

 "For historical reasons, the very first message sent by the client (the startup message)
  has no initial message-type byte."

initial_request

Generate and send the startup request.

send_message

Send a message.

queue

Queue up a message for sending. The message will only be sent when we're in ReadyForQuery mode, which could be immediately or later.

send_next_in_queue

Send the next queued message.

message

Creates a new message of the given type.

attach_event

Attach new handler(s) to the given event(s).

detach_event

Detach handler(s) from the given event(s). Not implemented.

debug

Helper method to report debug information. Can take a string or a coderef.

handle_message

Handle an incoming message from the server.

message_length

Returns the length of the given message.

simple_query

Send a simple query to the server - only supports plain queries (no bind parameters).

copy_data

Send copy data to the server.

copy_done

Indicate that the COPY data from the client is complete.

backend_state

Accessor for current backend state.

active_statement

Returns the currently active Protocol::PostgreSQL::Statement if we have one.

row_description

Accessor for row description.

prepare

Prepare a Protocol::PostgreSQL::Statement. Intended to be mostly compatible with the DBI ->prepare method.

prepare_async

Set up a Protocol::PostgreSQL::Statement allowing callbacks and other options to be provided.

is_ready

Returns true if we're ready to send more data to the server.

send_copy_data

Send COPY data to the server. Takes an arrayref and replaces any reserved characters with quoted versions.

_build_message

Construct a new message.

SEE ALSO ^

DBD::Pg, which uses the official library and (unlike this module) provides full support for DBI.

AUTHOR ^

Tom Molesworth <cpan@entitymodel.com>

LICENSE ^

Copyright Tom Molesworth 2010-2011. Licensed under the same terms as Perl itself.

syntax highlighting: