Amon2-DBI
view release on metacpan or search on metacpan
# =========================================================================
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
# DO NOT EDIT DIRECTLY.
# =========================================================================
use 5.008_001;
use strict;
use warnings;
use utf8;
use Module::Build;
use File::Basename;
use File::Spec;
my %args = (
license => 'perl',
dynamic_config => 0,
configure_requires => {
[BROKEN VERSION. DO NOT USE THIS VERSION.]
- fixed cicric reference
0.30 2012-10-20
[INCOMPATBILE CHANGE]
- do not handle exception in Amon2::DBI, and use RaiseError.
0.08 2011-11-08
- fixed charset in 05_mysql.t utf8 subtest(makamaka)
0.07 2011-11-07
- added auto pg_enable_utf8 setting(makamaka)
- made dsn check case-insensitive(makamaka)
0.06 2011-10-01
- [BUG FIX] fixed error handler on mysql
0.05 2011-05-14
- specify the version number of depended moduels
# DESCRIPTION
Amon2::DBI is a simple DBI wrapper. It provides better usability for you.
# FEATURES
- Set AutoInactiveDestroy to true.
If your DBI version is higher than 1.614, Amon2::DBI set AutoInactiveDestroy as true.
- Set sqlite\_unicode and mysql\_enable\_utf8 and pg\_enable\_utf8 automatically
Amon2::DBI set sqlite\_unicode and mysql\_enable\_utf8 automatically.
If using DBD::Pg version less than 2.99, pg\_enable\_utf8 too.
- Nested transaction management.
Amon2::DBI supports nested transaction management based on RAII like DBIx::Class or DBIx::Skinny. It uses [DBIx::TransactionManager](https://metacpan.org/pod/DBIx::TransactionManager) internally.
- Raising error when you occurred.
Amon2::DBI raises exception if your $dbh occurred exception.
# ADDITIONAL METHODS
lib/Amon2/DBI.pm view on Meta::CPAN
$attr->{RaiseError} = 1;
$attr->{PrintError} = 0;
$attr->{ShowErrorStatement} = 1;
if ($DBI::VERSION >= 1.614) {
$attr->{AutoInactiveDestroy} = 1 unless exists $attr->{AutoInactiveDestroy};
}
if ($dsn =~ /^dbi:SQLite:/i) {
$attr->{sqlite_unicode} = 1 unless exists $attr->{sqlite_unicode};
}
elsif ($dsn =~ /^dbi:mysql:/i) {
$attr->{mysql_enable_utf8} = 1 unless exists $attr->{mysql_enable_utf8};
}
elsif ($dsn =~ /^dbi:Pg:/i) {
my $dbd_pg_version = eval { require DBD::Pg; (DBD::Pg->VERSION =~ /^([.0-9]+)\./)[0] };
if ( !$@ and $dbd_pg_version < 2.99 ) { # less than DBD::Pg 2.99, pg_enable_utf8 must be set for utf8.
$attr->{pg_enable_utf8} = 1 unless exists $attr->{pg_enable_utf8};
}
}
my $self = $class->SUPER::connect($dsn, $user, $pass, $attr) or die "Cannot connect to server: $DBI::errstr";
return $self;
}
package Amon2::DBI::dr;
our @ISA = qw(DBI::dr);
package Amon2::DBI::db; # database handler
lib/Amon2/DBI.pm view on Meta::CPAN
}
package Amon2::DBI::st; # statement handler
our @ISA = qw(DBI::st);
sub sql { $_[0]->{private_sql} }
1;
__END__
=encoding utf8
=head1 NAME
Amon2::DBI - Simple DBI wrapper
=head1 SYNOPSIS
use Amon2::DBI;
my $dbh = Amon2::DBI->connect(...);
lib/Amon2/DBI.pm view on Meta::CPAN
Amon2::DBI is a simple DBI wrapper. It provides better usability for you.
=head1 FEATURES
=over 4
=item Set AutoInactiveDestroy to true.
If your DBI version is higher than 1.614, Amon2::DBI set AutoInactiveDestroy as true.
=item Set sqlite_unicode and mysql_enable_utf8 and pg_enable_utf8 automatically
Amon2::DBI set sqlite_unicode and mysql_enable_utf8 automatically.
If using DBD::Pg version less than 2.99, pg_enable_utf8 too.
=item Nested transaction management.
Amon2::DBI supports nested transaction management based on RAII like DBIx::Class or DBIx::Skinny. It uses L<DBIx::TransactionManager> internally.
=item Raising error when you occurred.
Amon2::DBI raises exception if your $dbh occurred exception.
=back
lib/Amon2/Plugin/DBI.pm view on Meta::CPAN
use strict;
use warnings;
use utf8;
package Amon2::Plugin::DBI;
use Amon2::DBI;
sub init {
my ($class, $context_class, $config) = @_;
no strict 'refs';
*{"$context_class\::dbh"} = \&_dbh;
}
t/01_simple.t view on Meta::CPAN
Amon2::DBI->connect('dbi:unknown:', '', '');
};
ok $@, "dies with unknown driver, automatically.";
my $dbh = Amon2::DBI->connect('dbi:SQLite::memory:', '', '');
$dbh->do(q{CREATE TABLE foo (e)});
$dbh->insert('foo', {e => 3});
$dbh->do_i('INSERT INTO foo ', {e => 4});
is join(',', map { @$_ } @{$dbh->selectall_arrayref('SELECT * FROM foo ORDER BY e')}), '3,4';
subtest 'utf8' => sub {
use utf8;
$dbh->do(q{CREATE TABLE bar (x)});
$dbh->insert(bar => { x => "ããã«ã¡ã¯" });
my ($x) = $dbh->selectrow_array(q{SELECT x FROM bar});
is $x, "ããã«ã¡ã¯";
};
eval {
$dbh->insert('bar', {e => 3});
}; note $@;
ok $@, "Dies with unknown table name automatically.";
t/02_integrate.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Requires qw/DBD::SQLite Amon2/;
{
package MyApp;
use parent qw/Amon2/;
__PACKAGE__->load_plugin(qw/DBI/);
use File::Temp qw/tmpnam/;
my $filename = tmpnam();
sub config { +{ DBI => ["dbi:SQLite:dbname=$filename", '', '', {}] } }
t/05_mysql.t view on Meta::CPAN
'skip-networking' => ''
}
) or plan skip_all => $Test::mysqld::errstr;
my $dbh = Amon2::DBI->connect($mysqld->dsn());
$dbh->do(q{CREATE TABLE foo (e int unsigned not null)});
$dbh->insert('foo', {e => 3});
$dbh->do_i('INSERT INTO foo ', {e => 4});
is join(',', map { @$_ } @{$dbh->selectall_arrayref('SELECT * FROM foo ORDER BY e')}), '3,4';
subtest 'utf8' => sub {
use utf8;
$dbh->do(q{CREATE TABLE bar (x varchar(255)) DEFAULT CHARACTER SET utf8});
$dbh->insert(bar => { x => "ããã«ã¡ã¯" });
my ($x) = $dbh->selectrow_array(q{SELECT x FROM bar});
is $x, "ããã«ã¡ã¯";
};
eval {
$dbh->insert('bar', {e => 3});
}; note $@;
ok $@, "Dies with unknown table name automatically.";
like $@, qr/failed/;
my $pg = eval { Test::postgresql->new(
initdb_args => $Test::postgresql::Defaults{initdb_args} . ' -E UTF8',
) } or plan skip_all => $Test::postgresql::errstr;
my $dbh = Amon2::DBI->connect($pg->dsn);
$dbh->do(q{CREATE TABLE foo (e int not null)});
$dbh->insert('foo', {e => 3});
$dbh->do_i('INSERT INTO foo ', {e => 4});
is join(',', map { @$_ } @{$dbh->selectall_arrayref('SELECT * FROM foo ORDER BY e')}), '3,4';
subtest 'utf8' => sub {
use utf8;
$dbh->do(q{CREATE TABLE bar (x varchar(255))});
$dbh->insert(bar => { x => "ããã«ã¡ã¯" });
my ($x) = $dbh->selectrow_array(q{SELECT x FROM bar});
is $x, "ããã«ã¡ã¯";
};
eval {
$dbh->insert('bar', {e => 3});
}; note $@;
ok $@, "Dies with unknown table name automatically.";
t/07_nested_transaction.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More;
use Amon2::DBI;
use Test::Requires 'DBD::SQLite';
my $COUNTER = 0;
{
no warnings 'once';
my $orig = Amon2::DBI::db->can('DESTROY') or die;
*Amon2::DBI::db::DESTROY = sub {
$COUNTER++;
( run in 1.051 second using v1.01-cache-2.11-cpan-49f99fa48dc )