| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBD::Mock; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- # |
|
4
|
|
|
|
|
|
|
# Copyright (c) 2004-2007 Stevan Little, Chris Winters |
|
5
|
|
|
|
|
|
|
# (spawned from original code Copyright (c) 1994 Tim Bunce) |
|
6
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- # |
|
7
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public |
|
8
|
|
|
|
|
|
|
# License or the Artistic License, as specified in the Perl README file. |
|
9
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- # |
|
10
|
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
2552655
|
use 5.008001; |
|
|
40
|
|
|
|
|
584
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
40
|
|
|
40
|
|
258
|
use strict; |
|
|
40
|
|
|
|
|
77
|
|
|
|
40
|
|
|
|
|
929
|
|
|
14
|
40
|
|
|
40
|
|
252
|
use warnings; |
|
|
40
|
|
|
|
|
92
|
|
|
|
40
|
|
|
|
|
1324
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
40
|
|
|
40
|
|
49501
|
use DBI; |
|
|
40
|
|
|
|
|
572030
|
|
|
|
40
|
|
|
|
|
2665
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
40
|
|
|
40
|
|
21705
|
use DBD::Mock::dr; |
|
|
40
|
|
|
|
|
111
|
|
|
|
40
|
|
|
|
|
1324
|
|
|
19
|
40
|
|
|
40
|
|
19352
|
use DBD::Mock::db; |
|
|
40
|
|
|
|
|
168
|
|
|
|
40
|
|
|
|
|
1726
|
|
|
20
|
40
|
|
|
40
|
|
21067
|
use DBD::Mock::st; |
|
|
40
|
|
|
|
|
118
|
|
|
|
40
|
|
|
|
|
1755
|
|
|
21
|
40
|
|
|
40
|
|
19944
|
use DBD::Mock::StatementTrack; |
|
|
40
|
|
|
|
|
114
|
|
|
|
40
|
|
|
|
|
1520
|
|
|
22
|
40
|
|
|
40
|
|
19278
|
use DBD::Mock::StatementTrack::Iterator; |
|
|
40
|
|
|
|
|
110
|
|
|
|
40
|
|
|
|
|
1247
|
|
|
23
|
40
|
|
|
40
|
|
17811
|
use DBD::Mock::Session; |
|
|
40
|
|
|
|
|
107
|
|
|
|
40
|
|
|
|
|
1419
|
|
|
24
|
40
|
|
|
40
|
|
17416
|
use DBD::Mock::Pool; |
|
|
40
|
|
|
|
|
104
|
|
|
|
40
|
|
|
|
|
1232
|
|
|
25
|
40
|
|
|
40
|
|
17252
|
use DBD::Mock::Pool::db; |
|
|
40
|
|
|
|
|
110
|
|
|
|
40
|
|
|
|
|
17827
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub import { |
|
28
|
34
|
|
|
34
|
|
356
|
shift; |
|
29
|
34
|
100
|
66
|
|
|
4287
|
$DBI::connect_via = "DBD::Mock::Pool::connect" |
|
30
|
|
|
|
|
|
|
if ( @_ && lc( $_[0] ) eq "pool" ); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '1.59'; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $drh = undef; # will hold driver handle |
|
36
|
|
|
|
|
|
|
our $err = 0; # will hold any error codes |
|
37
|
|
|
|
|
|
|
our $errstr = ''; # will hold any error messages |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Defaulting a result set's fields to undef changes the way DBD::Mock responds, so we default it to off |
|
40
|
|
|
|
|
|
|
our $DefaultFieldsToUndef = 0; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub driver { |
|
44
|
38
|
50
|
|
38
|
0
|
14096
|
return $drh if defined $drh; |
|
45
|
38
|
|
|
|
|
123
|
my ( $class, $attributes ) = @_; |
|
46
|
38
|
50
|
33
|
|
|
354
|
$attributes = {} |
|
47
|
|
|
|
|
|
|
unless ( defined($attributes) && ( ref($attributes) eq 'HASH' ) ); |
|
48
|
|
|
|
|
|
|
$drh = DBI::_new_drh( |
|
49
|
|
|
|
|
|
|
"${class}::dr", |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
Name => 'Mock', |
|
52
|
|
|
|
|
|
|
Version => $DBD::Mock::VERSION, |
|
53
|
|
|
|
|
|
|
Attribution => |
|
54
|
|
|
|
|
|
|
'DBD Mock driver by Chris Winters & Stevan Little (orig. from Tim Bunce)', |
|
55
|
|
|
|
|
|
|
Err => \$DBD::Mock::err, |
|
56
|
|
|
|
|
|
|
Errstr => \$DBD::Mock::errstr, |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# mock attributes |
|
59
|
|
|
|
|
|
|
mock_connect_fail => 0, |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# and pass in any extra attributes given |
|
62
|
38
|
|
|
|
|
210
|
%{$attributes} |
|
|
38
|
|
|
|
|
369
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
); |
|
65
|
38
|
|
|
|
|
2612
|
return $drh; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
|
0
|
sub CLONE { undef $drh } |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# NOTE: |
|
71
|
|
|
|
|
|
|
# this feature is still quite experimental. It is defaulted to |
|
72
|
|
|
|
|
|
|
# be off, but it can be turned on by doing this: |
|
73
|
|
|
|
|
|
|
# $DBD::Mock::AttributeAliasing++; |
|
74
|
|
|
|
|
|
|
# and then turned off by doing: |
|
75
|
|
|
|
|
|
|
# $DBD::Mock::AttributeAliasing = 0; |
|
76
|
|
|
|
|
|
|
# we shall see how this feature works out. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
our $AttributeAliasing = 0; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my %AttributeAliases = ( |
|
81
|
|
|
|
|
|
|
mysql => { |
|
82
|
|
|
|
|
|
|
db => { |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# aliases can either be a string which is obvious |
|
85
|
|
|
|
|
|
|
mysql_insertid => 'mock_last_insert_id' |
|
86
|
|
|
|
|
|
|
}, |
|
87
|
|
|
|
|
|
|
st => { |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# but they can also be a subroutine reference whose |
|
90
|
|
|
|
|
|
|
# first argument will be either the $dbh or the $sth |
|
91
|
|
|
|
|
|
|
# depending upon which context it is aliased in. |
|
92
|
|
|
|
|
|
|
mysql_insertid => |
|
93
|
|
|
|
|
|
|
sub { (shift)->{Database}->{'mock_last_insert_id'} } |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
mariadb => { |
|
98
|
|
|
|
|
|
|
db => { |
|
99
|
|
|
|
|
|
|
mariadb_insertid => 'mock_last_insert_id' |
|
100
|
|
|
|
|
|
|
}, |
|
101
|
|
|
|
|
|
|
st => { |
|
102
|
|
|
|
|
|
|
mariadb_insertid => |
|
103
|
|
|
|
|
|
|
sub { (shift)->{Database}->{'mock_last_insert_id'} } |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _get_mock_attribute_aliases { |
|
109
|
7
|
|
|
7
|
|
12
|
my ($dbname) = @_; |
|
110
|
7
|
100
|
|
|
|
43
|
( exists $AttributeAliases{ lc($dbname) } ) |
|
111
|
|
|
|
|
|
|
|| die "Attribute aliases not available for '$dbname'"; |
|
112
|
6
|
|
|
|
|
16
|
return $AttributeAliases{ lc($dbname) }; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _set_mock_attribute_aliases { |
|
116
|
0
|
|
|
0
|
|
|
my ( $dbname, $dbh_or_sth, $key, $value ) = @_; |
|
117
|
0
|
|
|
|
|
|
return $AttributeAliases{ lc($dbname) }->{$dbh_or_sth}->{$key} = $value; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
## Some useful constants |
|
121
|
|
|
|
|
|
|
|
|
122
|
40
|
|
|
40
|
|
358
|
use constant NULL_RESULTSET => [ [] ]; |
|
|
40
|
|
|
|
|
98
|
|
|
|
40
|
|
|
|
|
5207
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |