SYNOPSIS

        use NetSDS::DBI;

        $dbh = NetSDS::DBI->new(
                dsn    => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432',
                login  => 'user',
                passwd => 'topsecret',
        );

        print $db->call("select md5(?)", 'zuka')->fetchrow_hashref->{md5};

DESCRIPTION

\*(C`NetSDS::DBI\*(C' module provides wrapper around \s-1DBI\s0 module.

CLASS API

new(%params) - class constructor

$dbh = NetSDS::DBI->new( dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432', login => 'user', passwd => 'topsecret', );

dbh() - \s-1DBI\s0 connection handler accessor

Returns: \s-1DBI\s0 object This method provides accessor to \s-1DBI\s0 object and for low level access to database specific methods. Example (access to specific method): my $quoted = $db->dbh->quote_identifier(undef, 'auth', 'services'); # $quoted contains "auth"."services" now Method \*(C`call()\*(C' implements the following functionality: * check connection to DBMS and restore it * prepare chached SQL statement * execute statement with bind parameters Parameters: * SQL query with placeholders * bind parameters Return: * statement handler from DBI Example: $sth = $dbh->call("select * from users"); while (my $row = $sth->fetchrow_hashref()) { print $row->{username}; } Paramters: \s-1SQL\s0 query, parameters Returns: arrayref of records as hashrefs Example: # SQL DDL script: # create table users ( # id serial, # login varchar(32), # passwd varchar(32) # );

# Now we fetch all data to perl structure my $table_data = $db->fetch_call("select * from users");

# Process this data foreach my $user (@{$table_data}) { print "User ID: " . $user->{id}; print "Login: " . $user->{login}; }

begin() - start transaction
commit() - commit transaction
rollback() - rollback transaction
quote() - quote \s-1SQL\s0 string

Example: # Encode $str to use in queries my $str = "some crazy' string; with (dangerous characters"; $str = $db->quote($str);

INTERNAL METHODS

_add_sets() - add initial \s-1SQL\s0 query

Example: $obj->_add_sets("set search_path to myscheme"); $obj->_add_sets("set client_encoding to 'UTF-8'");

_add_attrs() - add \s-1DBI\s0 handler attributes

$self->_add_attrs(AutoCommit => 1);

_check_connection() - ping and reconnect

Internal method checking connection and implement reconnect

_connect() - connect to \s-1DBMS\s0

Internal method starting connection to \s-1DBMS\s0

EXAMPLES

samples/testdb.pl

RELATED TO NetSDS::DBI…

\s-1DBI\s0, DBD::Pg

TODO

1. Make module less PostgreSQL specific.

AUTHOR

Michael Bochkaryov <[email protected]>

LICENSE

Copyright (C) 2008-2009 Net Style Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the \s-1GNU\s0 General Public License for more details.

You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, \s-1MA\s0 02111-1307 \s-1USA\s0