| 1 |
use 5.008; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
use_ok('DBD::Mock'); |
| 10 |
use_ok('DBI'); |
| 11 |
} |
| 12 |
|
| 13 |
# test misc. attributes |
| 14 |
|
| 15 |
{ |
| 16 |
my $dbh = DBI->connect('DBI:Mock:', 'user', 'pass'); |
| 17 |
isa_ok($dbh, 'DBI::db'); |
| 18 |
|
| 19 |
is($dbh->{Name}, '', '... if no db-name is given'); |
| 20 |
ok( $dbh->{AutoCommit}, |
| 21 |
'... AutoCommit DB attribute defaults to set' ); |
| 22 |
|
| 23 |
# DBI will handle attributes with 'private_', 'dbi_' or , |
| 24 |
# 'dbd_' prefixes but all others, we need to handle. |
| 25 |
|
| 26 |
$dbh->{mysql_insertid} = 10; |
| 27 |
is($dbh->{mysql_insertid}, 10, '... this attribute should be 10'); |
| 28 |
|
| 29 |
# DBI will handle these |
| 30 |
|
| 31 |
$dbh->{private_insert_id} = 15; |
| 32 |
is($dbh->{private_insert_id}, 15, '... this attribute should be 15'); |
| 33 |
|
| 34 |
$dbh->{dbi_attribute} = 2000; |
| 35 |
is($dbh->{dbi_attribute}, 2000, '... this attribute should be 2000'); |
| 36 |
|
| 37 |
$dbh->{dbd_attr} = 15_000; |
| 38 |
is($dbh->{dbd_attr}, 15_000, '... this attribute should be 15,000'); |
| 39 |
|
| 40 |
$dbh->disconnect(); |
| 41 |
} |
| 42 |
|
| 43 |
# test setting attributes post-connect |
| 44 |
|
| 45 |
{ |
| 46 |
|
| 47 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ); |
| 48 |
$dbh->{RaiseError} = 1; |
| 49 |
$dbh->{PrintError} = 1; |
| 50 |
$dbh->{AutoCommit} = 1; |
| 51 |
|
| 52 |
ok( $dbh->{RaiseError}, |
| 53 |
'RaiseError DB attribute set after connect()' ); |
| 54 |
ok( $dbh->{PrintError}, |
| 55 |
'PrintError DB attribute set after connect()' ); |
| 56 |
ok( $dbh->{AutoCommit}, |
| 57 |
'AutoCommit DB attribute set after connect()' ); |
| 58 |
|
| 59 |
$dbh->disconnect(); |
| 60 |
} |
| 61 |
|
| 62 |
# test setting them during connect |
| 63 |
|
| 64 |
{ |
| 65 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '', |
| 66 |
{ RaiseError => 1, |
| 67 |
PrintError => 1, |
| 68 |
AutoCommit => 1 } ); |
| 69 |
ok( $dbh->{RaiseError}, |
| 70 |
'RaiseError DB attribute set in connect()' ); |
| 71 |
ok( $dbh->{PrintError}, |
| 72 |
'PrintError DB attribute set in connect()' ); |
| 73 |
ok( $dbh->{AutoCommit}, |
| 74 |
'AutoCommit DB attribute set in connect()' ); |
| 75 |
|
| 76 |
$dbh->disconnect(); |
| 77 |
} |
| 78 |
|
| 79 |
# test setting attributes with false values during connect |
| 80 |
|
| 81 |
{ |
| 82 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '', |
| 83 |
{ RaiseError => 0, |
| 84 |
PrintError => 0, |
| 85 |
AutoCommit => 0 } ); |
| 86 |
ok( ! $dbh->{RaiseError}, |
| 87 |
'RaiseError DB attribute unset in connect()' ); |
| 88 |
ok( ! $dbh->{PrintError}, |
| 89 |
'PrintError DB attribute unset in connect()' ); |
| 90 |
ok( ! $dbh->{AutoCommit}, |
| 91 |
'AutoCommit DB attribute unset in connect()' ); |
| 92 |
|
| 93 |
$dbh->disconnect(); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
{ |
| 98 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ); |
| 99 |
is_deeply( |
| 100 |
[ $dbh->data_sources() ], |
| 101 |
[ 'DBI:Mock:' ], |
| 102 |
'... got the right data sources'); |
| 103 |
|
| 104 |
$dbh->{'mock_add_data_sources'} = 'foo'; |
| 105 |
|
| 106 |
is_deeply( |
| 107 |
[ $dbh->data_sources() ], |
| 108 |
[ 'DBI:Mock:', 'DBI:Mock:foo' ], |
| 109 |
'... got the right data sources'); |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
{ |
| 114 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '', |
| 115 |
{ RaiseError => 0, |
| 116 |
PrintError => 0, |
| 117 |
PrintWarn => 0, |
| 118 |
AutoCommit => 0, |
| 119 |
} ); |
| 120 |
$dbh->{RaiseError} = 1; |
| 121 |
$dbh->{PrintError} = 1; |
| 122 |
$dbh->{PrintWarn} = 1; |
| 123 |
$dbh->{AutoCommit} = 1; |
| 124 |
|
| 125 |
ok( $dbh->{RaiseError}, |
| 126 |
'RaiseError DB attribute set in connect() and then changed' ); |
| 127 |
ok( $dbh->{PrintError}, |
| 128 |
'PrintError DB attribute set in connect() and then changed' ); |
| 129 |
ok( $dbh->{PrintWarn}, |
| 130 |
'PrintWarn DB attribute set in connect() and then changed' ); |
| 131 |
ok( $dbh->{AutoCommit}, |
| 132 |
'AutoCommit DB attribute set in connect() and then changed' ); |
| 133 |
|
| 134 |
$dbh->disconnect(); |
| 135 |
} |
| 136 |
|
| 137 |
done_testing(); |