File: 013_st_execute_bound_params.t

package info (click to toggle)
libdbd-mock-perl 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 416 kB
  • sloc: perl: 1,135; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 2,562 bytes parent folder | download | duplicates (5)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;

use Test::More tests => 18;

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

my $sql = 'SELECT * FROM foo WHERE bar = ? AND baz = ?';

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
    my $sth = eval { $dbh->prepare( $sql ) };
    eval {
        $sth->bind_param( 2, 'bar' );
        $sth->bind_param( 1, 'baz' );
    };
    ok( ! $@, 'Parameters bound to statement handle with bind_param()' );
    eval { $sth->execute() };
    ok( ! $@, 'Called execute() ok (empty, after bind_param calls)' );
    my $t_params = $sth->{mock_my_history}->bound_params;
    is( scalar @{ $t_params }, 2,
        'Correct number of parameters bound (method on tracker)' );
    is( $t_params->[0], 'baz',
        'Statement handle stored bound parameter from bind_param() (method on tracker)' );
    is( $t_params->[1], 'bar',
        'Statement handle stored bound parameter from bind_param() (method on tracker)' );
    my $a_params = $sth->{mock_params};
    is( scalar @{ $a_params }, 2, 'Correct number of parameters bound (attribute)' );
    is( $a_params->[0], 'baz',
        'Statement handle stored bound parameter from bind_param() (attribute)' );
    is( $a_params->[1], 'bar',
        'Statement handle stored bound parameter from bind_param() (attribute)' );
}

{
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
    my $sth = eval { $dbh->prepare( 'begin dbms_output.get_line(?,?); end;' ) };
    my ($bar, $baz) = ('bar', 'baz');
    eval {
        $sth->bind_param_inout( 2, \$bar, 10 );
        $sth->bind_param_inout( 1, \$baz, 100 );
    };
    diag $@ if $@;
    ok(!$@, 'Parameters bound to statement handle with bind_param_inout()' );
    eval { $sth->execute() };
    ok( ! $@, 'Called execute() ok (empty, after bind_param_inout calls)' );
    my $t_params = $sth->{mock_my_history}->bound_params;
    is( scalar @{ $t_params }, 2, 'Correct number of parameters bound (method on tracker)' );
    is( $t_params->[0], \$baz,
        'Statement handle stored bound parameter from bind_param_inout() (method on tracker)' );
    is( $t_params->[1], \$bar,
        'Statement handle stored bound parameter from bind_param_inout() (method on tracker)' );
    my $a_params = $sth->{mock_params};
    is( scalar @{ $a_params }, 2,
        'Correct number of parameters bound (attribute)' );
    is( $a_params->[0], \$baz,
        'Statement handle stored bound parameter from bind_param_inout() (attribute)' );
    is( $a_params->[1], \$bar,
        'Statement handle stored bound parameter from bind_param_inout() (attribute)' );
}