This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
forked from autarch/dbd-mock
-
Notifications
You must be signed in to change notification settings - Fork 4
/
027_named_parameters.t
56 lines (46 loc) · 1.69 KB
/
027_named_parameters.t
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' );