| 1 |
# this is bug RT #71438 |
| 2 |
use 5.008; |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
|
| 7 |
use Test::More; |
| 8 |
use DBI; |
| 9 |
|
| 10 |
my $dbh = DBI->connect('dbi:Mock:', '', '', { PrintError => 0, RaiseError => 1}); |
| 11 |
|
| 12 |
my $query = 'SELECT foo, bar FROM baz WHERE id=?'; |
| 13 |
my @session = ( |
| 14 |
{ |
| 15 |
statement => $query, |
| 16 |
results => [ |
| 17 |
['foo', 'bar'], |
| 18 |
[1, 'test1'], |
| 19 |
[2, 'test2'] |
| 20 |
], |
| 21 |
bound_params => [ 1 ], |
| 22 |
}, |
| 23 |
{ |
| 24 |
statement => $query, |
| 25 |
results => [ |
| 26 |
['abc', 'xyz'], |
| 27 |
[7, 'test7'], |
| 28 |
[8, 'test8'] |
| 29 |
], |
| 30 |
bound_params => [ 2 ], |
| 31 |
}, |
| 32 |
); |
| 33 |
$dbh->{mock_session} = DBD::Mock::Session->new(@session); |
| 34 |
|
| 35 |
# First query |
| 36 |
my $sth = $dbh->prepare($query); |
| 37 |
$sth->execute(1); |
| 38 |
|
| 39 |
is_deeply( |
| 40 |
$sth->fetchrow_hashref(), |
| 41 |
{foo => 1, bar => 'test1'} |
| 42 |
); |
| 43 |
|
| 44 |
is_deeply( |
| 45 |
$sth->fetchrow_hashref(), |
| 46 |
{foo => 2, bar => 'test2'} |
| 47 |
); |
| 48 |
|
| 49 |
is_deeply( |
| 50 |
$sth->fetchrow_hashref(), |
| 51 |
undef |
| 52 |
); |
| 53 |
|
| 54 |
# Second query |
| 55 |
$sth = $dbh->prepare($query); |
| 56 |
$sth->execute(2); |
| 57 |
|
| 58 |
is_deeply( |
| 59 |
$sth->fetchrow_hashref(), |
| 60 |
{abc => 7, xyz => 'test7'} |
| 61 |
); |
| 62 |
|
| 63 |
is_deeply( |
| 64 |
$sth->fetchrow_hashref(), |
| 65 |
{abc => 8, xyz => 'test8'} |
| 66 |
); |
| 67 |
|
| 68 |
is_deeply( |
| 69 |
$sth->fetchrow_hashref(), |
| 70 |
undef |
| 71 |
); |
| 72 |
|
| 73 |
done_testing(); |