File: 027_named_parameters.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 (56 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use Test::More tests => 5;

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

my $dbh = DBI->connect( 'DBI:Mock:', '', '' );

my $session = DBD::Mock::Session->new(
    (
        {
            statement    => 'SELECT * FROM foo WHERE id = ? and active = ?',
            bound_params => [ '613', 'yes' ],
            results      => [ ['foo'], [10] ]
        },
        {
            statement    => 'SELECT * FROM foo WHERE id = ? and active = ?',
            bound_params => [ '613', 'yes' ],
            results      => [ ['foo'], [10] ]
        },
        {
            statement =>
              'SELECT * FROM foo WHERE id = :id and active = :active',
            bound_params => [ '101', 'no' ],
            results => [ ['bar'], [15] ]
        },
        {
            statement =>
              'SELECT * FROM foo WHERE id = :id and active = :active',
            bound_params => [ '101', 'no' ],
            results => [ ['bar'], [15] ]
        },

    )
);

$dbh->{mock_session} = $session;

my $sth = $dbh->prepare('SELECT * FROM foo WHERE id = ? and active = ?');
$sth->bind_param( 1 => '613' );
$sth->bind_param( 2 => 'yes' );
ok( $sth->execute, 'Execute using positional parameters' );

$sth = $dbh->prepare('SELECT * FROM foo WHERE id = ? and active = ?');
ok( $sth->execute( '613', 'yes' ), 'Execute using positional parameters #2' );

$sth = $dbh->prepare('SELECT * FROM foo WHERE id = :id and active = :active');
$sth->bind_param( ':id'     => '101' );
$sth->bind_param( ':active' => 'no' );
ok( $sth->execute, 'Execute using named parameters' );

$sth = $dbh->prepare('SELECT * FROM foo WHERE id = :id and active = :active');
ok( $sth->execute( '101', 'no' ), 'Execute using named parameters #2' );