Debian Codegraph @

t/028_bind_columns.t

raw
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/,
18 bound_params => [ 'US', '%joe%' ],
19 results => [
20 [
21 'person.person_id', 'person.person_country',
22 'person.person_name'
23 ],
24 [ 1, 'AR', 'Joe Something' ],
25 [ 2, 'UY', 'Joe That' ],
26 [ 3, 'AR', 'Joe' ],
27 ]
28 }
29 );
30
31 $dbh->{mock_session} = $mock_session;
32
33 my $sth = $dbh->prepare("SELECT ...");
34 $sth->execute( 'US', '%joe%' );
35
36 my %row;
37
38 lives_ok(
39 sub {
40 $sth->bind_columns( \( @row{ @{ $sth->{NAME_lc} } } ) );
41 },
42 'Bind columns'
43 );
44
45 ok( exists $row{'person.person_name'}, 'First column' );
46 ok( exists $row{'person.person_country'}, 'Second column' );
47 ok( exists $row{'person.person_id'}, 'Third column' );
48
49 done_testing();