| 1 |
use 5.008; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
use Test::Exception; |
| 8 |
|
| 9 |
BEGIN { |
| 10 |
use_ok('DBD::Mock'); |
| 11 |
use_ok('DBI'); |
| 12 |
} |
| 13 |
|
| 14 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '', { RaiseError => 1 } ); |
| 15 |
my $mock_session = DBD::Mock::Session->new( |
| 16 |
{ |
| 17 |
statement => qr/SELECT name, id FROM person/, |
| 18 |
results => [ [ 'name', 'id' ], [ 'Charles', 2 ], [ 'Wall', 3 ], ] |
| 19 |
}, |
| 20 |
{ |
| 21 |
statement => qr/SELECT email FROM client/, |
| 22 |
results => [ |
| 23 |
[ 'name', 'email' ], |
| 24 |
[ 'Charles', '[email protected]' ], |
| 25 |
[ 'Wall', '[email protected]' ], |
| 26 |
] |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
$dbh->{mock_session} = $mock_session; |
| 31 |
|
| 32 |
my $first_sth; |
| 33 |
my $second_sth; |
| 34 |
|
| 35 |
lives_ok( |
| 36 |
sub { |
| 37 |
$second_sth = $dbh->prepare("SELECT email FROM client"); |
| 38 |
$first_sth = $dbh->prepare("SELECT name, id FROM person"); |
| 39 |
|
| 40 |
$first_sth->execute(); |
| 41 |
$second_sth->execute(); |
| 42 |
|
| 43 |
my $row = $first_sth->fetchrow_hashref; |
| 44 |
is( $row->{name}, 'Charles', 'First statement first column' ); |
| 45 |
is( $row->{id}, '2', 'First statement second column' ); |
| 46 |
|
| 47 |
$row = $second_sth->fetchrow_hashref; |
| 48 |
is( $row->{name}, 'Charles', 'Second statement first column' ); |
| 49 |
is( $row->{email}, '[email protected]', |
| 50 |
'Second statement second column' ); |
| 51 |
|
| 52 |
}, |
| 53 |
'Prepare two statements' |
| 54 |
); |
| 55 |
|
| 56 |
done_testing(); |