Amon2-DBI
view release on metacpan or search on metacpan
1234567891011121314151617181920# =========================================================================
# 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
=> {
141516171819202122232425262728293031323334353637
[BROKEN VERSION. DO NOT USE THIS VERSION.]
- fixed cicric reference
0.30 2012-10-20
[INCOMPATBILE CHANGE]
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
111213141516171819202122232425262728293031323334# 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
1112131415161718192021222324252627282930313233343536
$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) {
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)
;
lib/Amon2/DBI.pm view on Meta::CPAN
727374757677787980818283848586878889909192}
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
96979899100101102103104105106107108109110111112113114115116117118119Amon2::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
12345678910111213use
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
891011121314151617181920212223242526272829
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
{
$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
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
{
__PACKAGE__->load_plugin(
qw/DBI/
);
my
$filename
= tmpnam();
sub
config { +{
DBI
=> [
"dbi:SQLite:dbname=$filename"
,
''
,
''
, {}] } }
t/05_mysql.t view on Meta::CPAN
910111213141516171819202122232425262728293031
'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
{
$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/
;
78910111213141516171819202122232425262728my
$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
{
$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
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Amon2::DBI;
my
$COUNTER
= 0;
{
no
warnings
'once'
;
my
$orig
= Amon2::DBI::db->can(
'DESTROY'
) or
die
;
*Amon2::DBI::db::DESTROY
=
sub
{
$COUNTER
++;
( run in 1.064 second using v1.01-cache-2.11-cpan-49f99fa48dc )