File: 028_bind_columns.t

package info (click to toggle)
libdbd-mock-perl 1.59-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 512 kB
  • sloc: perl: 1,251; makefile: 7
file content (49 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use 5.008;

use strict;
use warnings;

use Test::More;
use Test::Exception;

BEGIN {
    use_ok('DBD::Mock');
    use_ok('DBI');
}

my $dbh = DBI->connect( 'DBI:Mock:', '', '', { RaiseError => 1 } );
my $mock_session = DBD::Mock::Session->new(
    {
        statement    => qr/SELECT/,
        bound_params => [ 'US', '%joe%' ],
        results      => [
            [
                'person.person_id', 'person.person_country',
                'person.person_name'
            ],
            [ 1, 'AR', 'Joe Something' ],
            [ 2, 'UY', 'Joe That' ],
            [ 3, 'AR', 'Joe' ],
        ]
    }
);

$dbh->{mock_session} = $mock_session;

my $sth = $dbh->prepare("SELECT ...");
$sth->execute( 'US', '%joe%' );

my %row;

lives_ok(
    sub {
        $sth->bind_columns( \( @row{ @{ $sth->{NAME_lc} } } ) );
    },
    'Bind columns'
);

ok( exists $row{'person.person_name'},    'First column' );
ok( exists $row{'person.person_country'}, 'Second column' );
ok( exists $row{'person.person_id'},      'Third column' );

done_testing();