NAME
POE::Component::MDBA::Backend::DBI - Simple DBI Backend
SYNOPSIS
use POE qw(Component::MDBA);
POE::Component::MDBA->spawn(
alias => $alias,
backend => 'DBI', # optional
backend_args => [ ... list of connection sources ... ]
);
# else where in your code...
POE::Kernel->post($alias, 'execute', {
args => [ ... list database arguments ... ]
});
DESCRIPTION
This module allows you simple access to DBI via POE::Component::MDBA.
MDBA ARGUMENTS
POE::Component::MDBA::Backend::DBI influences the arguments passed to POE::Component::MDBA methods:
spawn ARGUMENTS
- backend_args
-
backend_args takes an arrayref of arrayrefs. Each arrayref contains the arguments to DBI->connect().
POE::Component::MDBA->spawn( backend_args => [ [ 'dbi:Pg:dbname=foo1', 'username1', 'password1', \%attr ], [ 'dbi:Pg:dbname=foo2', 'username2', 'password2', \%attr ], [ 'dbi:Pg:dbname=foo3', 'username3', 'password3', \%attr ], ... ] );
execute ARGUMENTS
execute takes a list of hashref which each contain the following:
- sql
-
This specifies the raw SQL string that needs to be executed. Placeholders are allowed - see placeholders below.
- placeholders
-
This specifies the list of placeholders passed to $sth->execute()
- select_method
-
This specifies the method to use when selecting data from the statement handle. If you are not using SELECT'able sql, then you can leave it as it is.
POE::Kernel->post( $alias, 'execute', {
args => [
{
select_method => 'fetchrow_hashref', # optional
sql => 'SELECT foo FROM bar',
placeholders => [ $arg1, $arg2, $arg3 ... ]
}
]
});
aggregate ARGUMENTS
aggregate function takes the usual arguments received from POE::Component::Generic. ARG0 contains $ref, which is a cookie sent by POE::Component::MDBA. ARG1 contains $result, which is the return value from POE::Component::MDBA::Backend::DBI::execute().
The $result value is a hashref containing the following keys:
- rv
-
The value returned by $sth->execute().
- rows
-
An arrayref containing the rows resulting from executing the SQL and fetching results from it. The type of each value depends on the value of
select_mode
passed to execute().Note that if select_mode is not specified, then the value of this slot is always an empty list.
- error
-
If execute() fails at any point because of an error, then this value is populated with the value of the error
{
rv => $rv,
rows => [
{ col1 => $val1, col2 => $val2 ... }, # if you specified fetchrow_hashref
...
],
error => undef, # undef if no error
}
METHODS
new
Creates a new POE::Component::MDBA::Backend::DBI instance. Takes a list of arguments, which are directly passed to DBI->connect()
dbh
Returns a connect database handle.
execute
Executes the given query
AUTHOR
Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
SEE ALSO
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html