blib/lib/DBD/Gofer.pm

filter: Statementstmt 89.6% 345 / 385 Branchbran 72.1% 140 / 194 Conditioncond 65.6% 63 / 96 MC/DCmcdc 37.0% 20 / 54 Subroutinesub 88.6% 39 / 44 Podpod 0.0% 0 / 4 totaltotal 78.1% 607 / 777 CC 146 SCAR 25.8
CC
146
Cov
81%
connect
32.5
go_sth_method
19.3
__ANON__
17.8
CRAP 13.2
« blib/lib/DBD/Gofer/Transport/stream.pm ↑ Summary blib/lib/Win32/DBIODBC.pm »
1 {
2 package DBD::Gofer;
3  
4 63 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 63 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 63 require DBI;
8 63 require DBI::Gofer::Request;
9 63 require DBI::Gofer::Response;
10 63 require Carp;
11  
12 63 our $VERSION = "0.015327";
13  
14 # $Id: Gofer.pm 15326 2012-06-06 16:32:38Z Tim $
15 #
16 # Copyright (c) 2007, Tim Bunce, Ireland
17 #
18 # You may distribute under the terms of either the GNU General Public
19 # License or the Artistic License, as specified in the Perl README file.
20  
21  
22  
23 # attributes we'll allow local STORE
24 63 our %xxh_local_store_attrib = map { $_=>1 } qw(
25 Active
26 CachedKids
27 Callbacks
28 DbTypeSubclass
29 ErrCount Executed
30 FetchHashKeyName
31 HandleError HandleSetErr
32 InactiveDestroy
33 AutoInactiveDestroy
34 PrintError PrintWarn
35 Profile
36 RaiseError RaiseWarn
37 RootClass
38 ShowErrorStatement
39 Taint TaintIn TaintOut
40 TraceLevel
41 Warn
42 dbi_quote_identifier_cache
43 dbi_connect_closure
44 dbi_go_execute_unique
45 );
46 63 our %xxh_local_store_attrib_if_same_value = map { $_=>1 } qw(
47 Username
48 dbi_connect_method
49 );
50  
51 63 our $drh = undef; # holds driver handle once initialized
52 63 our $methods_already_installed;
53  
54 63 ▶ sub driver{
Subroutine driver: called CC=3 SCAR=11.0
Pod undocumented
55 63 ▶ return $drh if $drh;
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::Gofer::drh 0 63 63
56  
57 63 DBI->setup_driver('DBD::Gofer');
58  
59 63 ▶ unless ($methods_already_installed++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($DBD::Gofer::methods_already_installed++) 63 0 63
60 63 my $opts = { O=> 0x0004 }; # IMA_KEEP_ERR
61 63 DBD::Gofer::db->install_method('go_dbh_method', $opts);
62 63 DBD::Gofer::st->install_method('go_sth_method', $opts);
63 63 DBD::Gofer::st->install_method('go_clone_sth', $opts);
64 63 DBD::Gofer::db->install_method('go_cache', $opts);
65 63 DBD::Gofer::st->install_method('go_cache', $opts);
66 }
67  
68 63 my($class, $attr) = @_;
69 63 $class .= "::dr";
70 63 ($drh) = DBI::_new_drh($class, {
71 'Name' => 'Gofer',
72 'Version' => $VERSION,
73 'Attribution' => 'DBD Gofer by Tim Bunce',
74 });
75  
76 63 $drh;
77 }
78  
79  
80 0 ▶ sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
81 0 undef $drh;
82 }
83  
84  
85 4 ▶ sub go_cache {
Subroutine go_cache: called CC=3 SCAR=11.0
Pod undocumented
86 4 my $h = shift;
87 4 ▶ $h->{go_cache} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
88 # return handle's override go_cache, if it has one
89 4 ▶ return $h->{go_cache} if defined $h->{go_cache};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{"go_cache"} 2 2 4
90 # or else the transports default go_cache
91 2 return $h->{go_transport}->{go_cache};
92 }
93  
94  
95 7242 ▶ sub set_err_from_response { # set error/warn/info and propagate warnings
Subroutine set_err_from_response: called CC=4 SCAR=13.9
Pod undocumented
96 7242 my $h = shift;
97 7242 my $response = shift;
98 7242 ▶ if (my $warnings = $response->warnings) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $warnings = $response->warnings) 22 7220 7242
99 22 warn $_ for @$warnings;
100 }
101 7242 my ($err, $errstr, $state) = $response->err_errstr_state;
102 # Only set_err() if there's an error else leave the current values
103 # (The current values will normally be set undef by the DBI dispatcher
104 # except for methods marked KEEPERR such as ping.)
105 7242 ▶ $h->set_err($err, $errstr, $state) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 1559 5683 7242
106 7242 return undef;
107 }
108  
109  
110 603 ▶ sub install_methods_proxy {
Subroutine install_methods_proxy: called CC=7 SCAR=19.9
Pod undocumented
111 603 my ($installed_methods) = @_;
112 603 ▶ while ( my ($full_method, $attr) = each %$installed_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$installed_methods) 5094 603 5697
113 # need to install both a DBI dispatch stub and a proxy stub
114 # (the dispatch stub may be already here due to local driver use)
115  
116 DBI->_install_method($full_method, "", $attr||{})
117 5094 ▶ unless defined &{$full_method};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$full_method;} 0 5094 5094
Condition0%0/2
$attr || {}
l!l
00
MC/DC0%0/1
$attr || {}
$attr
Truth table0%0/2
A
A= $attr
Aresult
11
00
118  
119 # now install proxy stubs on the driver side
120 5094 ▶ $full_method =~ m/^DBI::(\w\w)::(\w+)$/
Branch: 1 branch
BranchTrueFalseTotal
$full_method =~ /^DBI::(\w\w)::(\w+)$/ or die "Invalid method name '${full_method}' for install_method" 5094 0 5094
121 or die "Invalid method name '$full_method' for install_method";
122 5094 my ($type, $method) = ($1, $2);
123 5094 my $driver_method = "DBD::Gofer::${type}::${method}";
124 5094 ▶ next if defined &{$driver_method};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$driver_method;} 4899 195 5094
125 195 my $sub;
126 195 ▶ if ($type eq 'db') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'db') { } 147 48 195
127 147 ▶ $sub = sub { return shift->go_dbh_method(undef, $method, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
128 }
129 else {
130 0 ▶ $sub = sub { shift->set_err($DBI::stderr, "Can't call \$${type}h->$method when using DBD::Gofer"); return; };
Subroutine __ANON__: not called CC=1 SCAR=2.6
131 }
132 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
133 195 *$driver_method = $sub;
134 }
135 }
136 }
137  
138  
139 63 { package DBD::Gofer::dr; # ====== DRIVER ======
140  
141 63 $imp_data_size = 0;
142 63 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
143  
144 10 ▶ sub connect_cached {
Subroutine connect_cached: called CC=3 SCAR=11.7
145 10 my ($drh, $dsn, $user, $auth, $attr)= @_;
146 10 ▶ $attr ||= {};
Condition50%1/2
$attr ||= {}
l!l
100
MC/DC0%0/1
$attr ||= {}
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
147 return $drh->SUPER::connect_cached($dsn, $user, $auth, {
148 (%$attr),
149 10 ▶ go_connect_method => $attr->{go_connect_method} || 'connect_cached',
Condition50%1/2
$attr->{'go_connect_method'} || 'connect_cached'
l!l
010
MC/DC0%0/1
$attr->{'go_connect_method'} || 'connect_cached'
$attr->{'go_connect_method'}
Truth table50%1/2
A
A= $attr->{'go_connect_method'}
Aresult
11
00
150 });
151 }
152  
153  
154 747 ▶ sub connect {
Subroutine connect: called CC=27 SCAR=34.8
155 747 my($drh, $dsn, $user, $auth, $attr)= @_;
156 747 my $orig_dsn = $dsn;
157  
158 # first remove dsn= and everything after it
159 747 ▶ my $remote_dsn = ($dsn =~ s/;?\bdsn=(.*)$// && $1)
Branch: 1 branch
BranchTrueFalseTotal
my $remote_dsn = $dsn =~ s/;?\bdsn=(.*)$// && $1 or return $drh->set_err($DBI::stderr, "No dsn= argument in '${orig_dsn}'") 747 0 747
Condition33%1/3
$dsn =~ s/;?\bdsn=(.*)$// && $1
!ll&&!rl&&r
00747
MC/DC0%0/2
$dsn =~ s/;?\bdsn=(.*)$// && $1
$dsn =~ s/;?\bdsn=(.*)$// $1
Truth table33%1/3
A && B
A= $dsn =~ s/;?\bdsn=(.*)$//B= $1
ABresult
0X0
100
111
160 or return $drh->set_err($DBI::stderr, "No dsn= argument in '$orig_dsn'");
161  
162 747 ▶ if ($attr->{go_bypass}) { # don't use DBD::Gofer for this connection
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"go_bypass"}) 1 746 747
163 # useful for testing with DBI_AUTOPROXY, e.g., t/03handle.t
164 1 return DBI->connect($remote_dsn, $user, $auth, $attr);
165 }
166  
167 746 my %go_attr;
168 # extract any go_ attributes from the connect() attr arg
169 746 for my $k (grep { /^go_/ } keys %$attr) {
170 13 $go_attr{$k} = delete $attr->{$k};
171 }
172 # then override those with any attributes embedded in our dsn (not remote_dsn)
173 746 for my $kv (grep /=/, split /;/, $dsn, -1) {
174 2170 my ($k, $v) = split /=/, $kv, 2;
175 2170 $go_attr{ "go_$k" } = $v;
176 }
177  
178 746 ▶ if (not ref $go_attr{go_policy}) { # if not a policy object already
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $go_attr{"go_policy"}) 746 0 746
179 746 ▶ my $policy_class = $go_attr{go_policy} || 'classic';
Condition50%1/2
$go_attr{'go_policy'} || 'classic'
l!l
7460
MC/DC0%0/1
$go_attr{'go_policy'} || 'classic'
$go_attr{'go_policy'}
Truth table50%1/2
A
A= $go_attr{'go_policy'}
Aresult
11
00
180 746 ▶ $policy_class = "DBD::Gofer::Policy::$policy_class"
Branch: 1 branch
BranchTrueFalseTotal
unless $policy_class =~ /::/ 746 0 746
181 unless $policy_class =~ /::/;
182 746 ▶ _load_class($policy_class)
Branch: 1 branch
BranchTrueFalseTotal
_load_class($policy_class) or return $drh->set_err($DBI::stderr, "Can't load ${policy_class}: $@") 746 0 746
183 or return $drh->set_err($DBI::stderr, "Can't load $policy_class: $@");
184 # replace policy name in %go_attr with policy object
185 746 ▶ $go_attr{go_policy} = eval { $policy_class->new(\%go_attr) }
Branch: 1 branch
BranchTrueFalseTotal
$go_attr{"go_policy"} = eval { do { $policy_class->new(\%go_attr) } } or return $drh->set_err($DBI::stderr, "Can't instanciate ${policy_class}: $@") 746 0 746
186 or return $drh->set_err($DBI::stderr, "Can't instanciate $policy_class: $@");
187 }
188 # policy object is left in $go_attr{go_policy} so transport can see it
189 746 my $go_policy = $go_attr{go_policy};
190  
191 746 ▶ if ($go_attr{go_cache} and not ref $go_attr{go_cache}) { # if not a cache object already
Branch: 1 branch
BranchTrueFalseTotal
if ($go_attr{"go_cache"} and not ref $go_attr{"go_cache"}) 4 742 746
Condition100%3/3
$go_attr{"go_cache"} and not ref $go_attr{"go_cache"}
!ll&&!rl&&r
74024
MC/DC100%2/2
$go_attr{"go_cache"} and not ref $go_attr{"go_cache"}
$go_attr{"go_cache"} not ref $go_attr{"go_cache"}
Truth table100%3/3
A and not(B)
A= $go_attr{"go_cache"}B= not ref $go_attr{"go_cache"}
ABresult
0X0
100
111
192 4 my $cache_class = $go_attr{go_cache};
193 4 ▶ $cache_class = "DBI::Util::CacheMemory" if $cache_class eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $cache_class eq 1 4 0 4
194 4 ▶ _load_class($cache_class)
Branch: 1 branch
BranchTrueFalseTotal
_load_class($cache_class) or return $drh->set_err($DBI::stderr, "Can't load $cache_class $@") 4 0 4
195 or return $drh->set_err($DBI::stderr, "Can't load $cache_class $@");
196 4 ▶ $go_attr{go_cache} = eval { $cache_class->new() }
Branch: 1 branch
BranchTrueFalseTotal
$go_attr{"go_cache"} = eval { do { $cache_class->new } } or $drh->set_err(0, "Can't instanciate ${cache_class}: $@") 4 0 4
197 or $drh->set_err(0, "Can't instanciate $cache_class: $@"); # warning
198 }
199  
200 # delete any other attributes that don't apply to transport
201 746 my $go_connect_method = delete $go_attr{go_connect_method};
202  
203 my $transport_class = delete $go_attr{go_transport}
204 746 ▶ or return $drh->set_err($DBI::stderr, "No transport= argument in '$orig_dsn'");
Branch: 1 branch
BranchTrueFalseTotal
my $transport_class = delete $go_attr{"go_transport"} or return $drh->set_err($DBI::stderr, "No transport= argument in '${orig_dsn}'") 746 0 746
205 746 ▶ $transport_class = "DBD::Gofer::Transport::$transport_class"
Branch: 1 branch
BranchTrueFalseTotal
unless $transport_class =~ /::/ 746 0 746
206 unless $transport_class =~ /::/;
207 746 ▶ _load_class($transport_class)
Branch: 1 branch
BranchTrueFalseTotal
_load_class($transport_class) or return $drh->set_err($DBI::stderr, "Can't load ${transport_class}: $@") 746 0 746
208 or return $drh->set_err($DBI::stderr, "Can't load $transport_class: $@");
209 746 ▶ my $go_transport = eval { $transport_class->new(\%go_attr) }
Branch: 1 branch
BranchTrueFalseTotal
my $go_transport = eval { do { $transport_class->new(\%go_attr) } } or return $drh->set_err($DBI::stderr, "Can't instanciate ${transport_class}: $@") 746 0 746
210 or return $drh->set_err($DBI::stderr, "Can't instanciate $transport_class: $@");
211  
212 746 my $request_class = "DBI::Gofer::Request";
213 746 ▶ my $go_request = eval {
Branch: 1 branch
BranchTrueFalseTotal
my $go_request = eval { do { my $go_attr = {%$attr}; if ($user) { $go_attr->{"Username"} = $user; $go_attr->{"Password"} = $auth; } ; delete @{$go_attr;}{"Profile", "HandleError", "HandleSetErr", "Callbacks"}; delete @{$go_attr;}{"RootClass", "DbTypeSubclass"}; $go_connect_method ||= $go_policy->connect_method($remote_dsn, $go_attr) || "connect"; $request_class->new({"dbh_connect_call", [$go_connect_method, $remote_dsn, $user, $auth, $go_attr]}) } } or return $drh->set_err($DBI::stderr, "Can't instanciate ${request_class}: $@") 746 0 746
214 746 my $go_attr = { %$attr };
215 # XXX user/pass of fwd server vs db server ? also impact of autoproxy
216 746 ▶ if ($user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 14 732 746
217 14 $go_attr->{Username} = $user;
218 14 $go_attr->{Password} = $auth;
219 }
220 # delete any attributes we can't serialize (or don't want to)
221 746 delete @{$go_attr}{qw(Profile HandleError HandleSetErr Callbacks)};
222 # delete any attributes that should only apply to the client-side
223 746 delete @{$go_attr}{qw(RootClass DbTypeSubclass)};
224  
225 746 ▶ $go_connect_method ||= $go_policy->connect_method($remote_dsn, $go_attr) || 'connect';
Condition60%3/5
$go_connect_method ||= $go_policy->connect_method($remote_dsn, $go_attr) || "connect"
l!l&&r!l&&!r
57410
$go_policy->connect_method($remote_dsn, $go_attr) || 'connect'
l!l
7410
MC/DC0%0/2
$go_connect_method ||= $go_policy->connect_method($remote_dsn, $go_attr) || "connect"
$go_connect_method $go_policy->connect_method($remote_dsn, $go_attr)
Truth table66%2/3
A ||= B
A= $go_connect_methodB= $go_policy->connect_method($remote_dsn, $go_attr)
ABresult
1X1
011
000
226 746 $request_class->new({
227 dbh_connect_call => [ $go_connect_method, $remote_dsn, $user, $auth, $go_attr ],
228 })
229 } or return $drh->set_err($DBI::stderr, "Can't instanciate $request_class: $@");
230  
231 746 my ($dbh, $dbh_inner) = DBI::_new_dbh($drh, {
232 'Name' => $dsn,
233 'USER' => $user,
234 go_transport => $go_transport,
235 go_request => $go_request,
236 go_policy => $go_policy,
237 });
238  
239 # mark as inactive temporarily for STORE. Active not set until connected() called.
240 746 $dbh->STORE(Active => 0);
241  
242 # should we ping to check the connection
243 # and fetch dbh attributes
244 746 my $skip_connect_check = $go_policy->skip_connect_check($attr, $dbh);
245 746 ▶ if (not $skip_connect_check) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip_connect_check) 561 185 746
246 561 ▶ if (not $dbh->go_dbh_method(undef, 'ping')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh->go_dbh_method(undef, "ping")) 34 527 561
247 34 ▶ return undef if $dbh->err; # error already recorded, typically
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->err 34 0 34
248 0 return $dbh->set_err($DBI::stderr, "ping failed");
249 }
250 }
251  
252 712 return $dbh;
253 }
254  
255 1496 ▶ sub _load_class { # return true or false+$@
Subroutine _load_class: called CC=2 SCAR=7.6
256 1496 my $class = shift;
257 1496 (my $pm = $class) =~ s{::}{/}g;
258 1496 $pm .= ".pm";
259 1496 ▶ return 1 if eval { require $pm };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { require $pm } } 1496 0 1496
260 0 delete $INC{$pm}; # shouldn't be needed (perl bug?) and assigning undef isn't enough
261 0 undef; # error in $@
262 }
263  
264 }
265  
266  
267 63 { package DBD::Gofer::db; # ====== DATABASE ======
268 63 $imp_data_size = 0;
269 63 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
270 63 ▶ use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
271  
272 63 my %dbh_local_store_attrib = %DBD::Gofer::xxh_local_store_attrib;
273  
274 717 ▶ sub connected {
Subroutine connected: called CC=1 SCAR=0.0
275 717 shift->STORE(Active => 1);
276 }
277  
278 4145 ▶ sub go_dbh_method {
Subroutine go_dbh_method: called CC=16 SCAR=28.5
279 4145 my $dbh = shift;
280 4145 my $meta = shift;
281 # @_ now contains ($method_name, @args)
282  
283 4145 my $request = $dbh->{go_request};
284 4145 $request->init_request([ wantarray, @_ ], $dbh);
285 4145 ++$dbh->{go_request_count};
286  
287 4145 my $go_policy = $dbh->{go_policy};
288 4145 my $dbh_attribute_update = $go_policy->dbh_attribute_update();
289 $request->dbh_attributes( $go_policy->dbh_attribute_list() )
290 if $dbh_attribute_update eq 'every'
291 4145 ▶ or $dbh->{go_request_count}==1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1 1161 2984 4145
Condition100%3/3
$dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1
l!l&&r!l&&!r
9112502984
MC/DC100%2/2
$dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1
$dbh_attribute_update eq "every" $dbh->{"go_request_count"} == 1
Truth table100%3/3
A or B
A= $dbh_attribute_update eq "every"B= $dbh->{"go_request_count"} == 1
ABresult
1X1
011
000
292  
293 $request->dbh_last_insert_id_args($meta->{go_last_insert_id_args})
294 4145 ▶ if $meta->{go_last_insert_id_args};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"go_last_insert_id_args"} 0 4145 4145
295  
296 my $transport = $dbh->{go_transport}
297 4145 ▶ or return $dbh->set_err($DBI::stderr, "Not connected (no transport)");
Branch: 1 branch
BranchTrueFalseTotal
my $transport = $dbh->{"go_transport"} or return $dbh->set_err($DBI::stderr, "Not connected (no transport)") 4145 0 4145
298  
299 local $transport->{go_cache} = $dbh->{go_cache}
300 4145 ▶ if defined $dbh->{go_cache};
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbh->{"go_cache"} 0 4145 4145
301  
302 4145 my ($response, $retransmit_sub) = $transport->transmit_request($request);
303 4145 ▶ $response ||= $transport->receive_response($request, $retransmit_sub);
Condition33%1/3
$response ||= $transport->receive_response($request, $retransmit_sub)
l!l&&r!l&&!r
041450
MC/DC0%0/2
$response ||= $transport->receive_response($request, $retransmit_sub)
$response $transport->receive_response($request, $retransmit_sub)
Truth table33%1/3
A ||= B
A= $responseB= $transport->receive_response($request, $retransmit_sub)
ABresult
1X1
011
000
304 4145 ▶ $dbh->{go_response} = $response
Branch: 1 branch
BranchTrueFalseTotal
$dbh->{"go_response"} = $response or die "No response object returned by $transport" 4145 0 4145
305 or die "No response object returned by $transport";
306  
307 4145 ▶ die "response '$response' returned by $transport is not a response object"
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($response, "DBI::Gofer::Response") 0 4145 4145
308 unless UNIVERSAL::isa($response,"DBI::Gofer::Response");
309  
310 4145 ▶ if (my $dbh_attributes = $response->dbh_attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh_attributes = $response->dbh_attributes) 1127 3018 4145
311  
312 # XXX installed_methods piggybacks on dbh_attributes for now
313 1127 ▶ if (my $installed_methods = delete $dbh_attributes->{dbi_installed_methods}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $installed_methods = delete $dbh_attributes->{"dbi_installed_methods"}) 1127 0 1127
314 DBD::Gofer::install_methods_proxy($installed_methods)
315 1127 ▶ if $dbh->{go_request_count}==1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"go_request_count"} == 1 603 524 1127
316 }
317  
318 # XXX we don't STORE here, we just stuff the value into the attribute cache
319 $dbh->{$_} = $dbh_attributes->{$_}
320 1127 for keys %$dbh_attributes;
321 }
322  
323 4145 my $rv = $response->rv;
324 4145 ▶ if (my $resultset_list = $response->sth_resultsets) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $resultset_list = $response->sth_resultsets) { } 10 4135 4145
elsif (not $rv) { } 0 4135 4135
325 # dbh method call returned one or more resultsets
326 # (was probably a metadata method like table_info)
327 #
328 # setup an sth but don't execute/forward it
329 10 my $sth = $dbh->prepare(undef, { go_skip_prepare_check => 1 });
330 # set the sth response to our dbh response
331 10 (tied %$sth)->{go_response} = $response;
332 # setup the sth with the results in our response
333 10 $sth->more_results;
334 # and return that new sth as if it came from original request
335 10 $rv = [ $sth ];
336 }
337 elsif (!$rv) { # should only occur for major transport-level error
338 #carp("no rv in response { @{[ %$response ]} }");
339 0 $rv = [ ];
340 }
341  
342 4145 DBD::Gofer::set_err_from_response($dbh, $response);
343  
344 4145 ▶ return (wantarray) ? @$rv : $rv->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 58 4087 4145
345 }
346  
347  
348 # Methods that should be forwarded but can be cached
349 63 for my $method (qw(
350 tables table_info column_info primary_key_info foreign_key_info statistics_info
351 data_sources type_info_all get_info
352 parse_trace_flags parse_trace_flag
353 func
354 )) {
355 756 my $policy_name = "cache_$method";
356 756 my $super_name = "SUPER::$method";
357 209 ▶ my $sub = sub {
Subroutine __ANON__: called CC=16 SCAR=28.8
358 209 my $dbh = shift;
359 209 my $rv;
360  
361 # if we know the remote side doesn't override the DBI's default method
362 # then we might as well just call the DBI's default method on the client
363 # (which may, in turn, call other methods that are forwarded, like get_info)
364 209 ▶ if ($dbh->{dbi_default_methods}{$method} && $dbh->{go_policy}->skip_default_methods()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods) 0 209 209
Condition66%2/3
$dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods
!ll&&!rl&&r
145640
MC/DC0%0/2
$dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods
$dbh->{"dbi_default_methods"}{$method} $dbh->{"go_policy"}->skip_default_methods
Truth table66%2/3
A and B
A= $dbh->{"dbi_default_methods"}{$method}B= $dbh->{"go_policy"}->skip_default_methods
ABresult
0X0
100
111
365 0 $dbh->trace_msg(" !! $method: using local default as remote method is also default\n");
366 0 return $dbh->$super_name(@_);
367 }
368  
369 209 my $cache;
370 my $cache_key;
371 209 ▶ if (my $cache_it = $dbh->{go_policy}->$policy_name(undef, $dbh, @_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache_it = $dbh->{"go_policy"}->$policy_name(undef, $dbh, @_)) 185 24 209
372 185 ▶ $cache = $dbh->{go_meta_cache} ||= {}; # keep separate from go_cache
Condition100%2/2
$dbh->{"go_meta_cache"} ||= {}
l!l
14243
MC/DC100%1/1
$dbh->{"go_meta_cache"} ||= {}
$dbh->{"go_meta_cache"}
Truth table100%2/2
A
A= $dbh->{"go_meta_cache"}
Aresult
11
00
373 $cache_key = sprintf "%s_wa%d(%s)", $policy_name, wantarray||0,
374 join(",\t", map { # XXX basic but sufficient for now
375 185 ▶ !ref($_) ? DBI::neat($_,1e6)
Condition100%2/2
wantarray || 0
l!l
36149
MC/DC100%1/1
wantarray || 0
wantarray
Truth table100%2/2
A
A= wantarray
Aresult
11
00
376 : ref($_) eq 'ARRAY' ? DBI::neat_list($_,1e6,",\001")
377 108 : ref($_) eq 'HASH' ? do { my @k = sort keys %$_; DBI::neat_list([@k,@{$_}{@k}],1e6,",\002") }
378 0 ▶ : do { warn "unhandled argument type ($_)"; $_ }
Branch: 3 branches
BranchTrueFalseTotal
!ref($_) ? : 74 108 182
ref $_ eq 'ARRAY' ? : 0 108 108
ref $_ eq 'HASH' ? : 108 0 108
379 } @_);
380 185 ▶ if ($rv = $cache->{$cache_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv = $cache->{$cache_key}) 58 127 185
381 58 $dbh->trace_msg("$method(@_) returning previously cached value ($cache_key)\n",4);
382 58 my @cache_rv = @$rv;
383 # if it's an sth we have to clone it
384 58 ▶ $cache_rv[0] = $cache_rv[0]->go_clone_sth if UNIVERSAL::isa($cache_rv[0],'DBI::st');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($cache_rv[0], "DBI::st") 0 58 58
385 58 ▶ return (wantarray) ? @cache_rv : $cache_rv[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 58 58
386 }
387 }
388  
389 $rv = [ (wantarray)
390 151 ▶ ? ($dbh->go_dbh_method(undef, $method, @_))
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 50 101 151
391 : scalar $dbh->go_dbh_method(undef, $method, @_)
392 ];
393  
394 151 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 127 24 151
395 127 $dbh->trace_msg("$method(@_) caching return value ($cache_key)\n",4);
396 127 my @cache_rv = @$rv;
397 # if it's an sth we have to clone it
398 #$cache_rv[0] = $cache_rv[0]->go_clone_sth
399 # if UNIVERSAL::isa($cache_rv[0],'DBI::st');
400 127 ▶ $cache->{$cache_key} = \@cache_rv
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($cache_rv[0], "DBI::st") 127 0 127
401 unless UNIVERSAL::isa($cache_rv[0],'DBI::st'); # XXX cloning sth not yet done
402 }
403  
404 151 ▶ return (wantarray) ? @$rv : $rv->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 50 101 151
405 756 };
406 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
407 756 *$method = $sub;
408 }
409  
410  
411 # Methods that can use the DBI defaults for some situations/drivers
412 63 for my $method (qw(
413 quote quote_identifier
414 )) { # XXX keep DBD::Gofer::Policy::Base in sync
415 126 my $policy_name = "locally_$method";
416 126 my $super_name = "SUPER::$method";
417 18 ▶ my $sub = sub {
Subroutine __ANON__: called CC=5 SCAR=22.3
418 18 my $dbh = shift;
419  
420 # if we know the remote side doesn't override the DBI's default method
421 # then we might as well just call the DBI's default method on the client
422 # (which may, in turn, call other methods that are forwarded, like get_info)
423 18 ▶ if ($dbh->{dbi_default_methods}{$method} && $dbh->{go_policy}->skip_default_methods()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods) 0 18 18
Condition33%1/3
$dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods
!ll&&!rl&&r
0180
MC/DC0%0/2
$dbh->{"dbi_default_methods"}{$method} and $dbh->{"go_policy"}->skip_default_methods
$dbh->{"dbi_default_methods"}{$method} $dbh->{"go_policy"}->skip_default_methods
Truth table33%1/3
A and B
A= $dbh->{"dbi_default_methods"}{$method}B= $dbh->{"go_policy"}->skip_default_methods
ABresult
0X0
100
111
424 0 $dbh->trace_msg(" !! $method: using local default as remote method is also default\n");
425 0 return $dbh->$super_name(@_);
426 }
427  
428 # false: use remote gofer
429 # 1: use local DBI default method
430 # code ref: use the code ref
431 18 my $locally = $dbh->{go_policy}->$policy_name($dbh, @_);
432 18 ▶ if ($locally) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locally) 0 18 18
433 0 ▶ return $locally->($dbh, @_) if ref $locally eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $locally eq "CODE" 0 0 0
434 0 return $dbh->$super_name(@_);
435 }
436 18 return $dbh->go_dbh_method(undef, $method, @_); # propagate context
437 126 };
438 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
439 126 *$method = $sub;
440 }
441  
442  
443 # Methods that should always fail
444 63 for my $method (qw(
445 begin_work commit rollback
446 )) {
447 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
448 1 ▶ *$method = sub { return shift->set_err($DBI::stderr, "$method not available with DBD::Gofer") }
Subroutine __ANON__: called CC=1 SCAR=0.0
449 189 }
450  
451  
452 3353 ▶ sub do {
Subroutine do: called CC=1 SCAR=0.0
453 3353 my ($dbh, $sql, $attr, @args) = @_;
454 3353 delete $dbh->{Statement}; # avoid "Modification of non-creatable hash value attempted"
455 3353 $dbh->{Statement} = $sql; # for profiling and ShowErrorStatement
456 3353 my $meta = { go_last_insert_id_args => $attr->{go_last_insert_id_args} };
457 3353 return $dbh->go_dbh_method($meta, 'do', $sql, $attr, @args);
458 }
459  
460 61 ▶ sub ping {
Subroutine ping: called CC=3 SCAR=11.0
461 61 my $dbh = shift;
462 61 ▶ return $dbh->set_err('', "can't ping while not connected") # info
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->SUPER::FETCH("Active") 6 55 61
463 unless $dbh->SUPER::FETCH('Active');
464 55 my $skip_ping = $dbh->{go_policy}->skip_ping();
465 55 ▶ return ($skip_ping) ? 1 : $dbh->go_dbh_method(undef, 'ping', @_);
Branch: 1 branch
BranchTrueFalseTotal
$skip_ping ? : 24 31 55
466 }
467  
468 0 ▶ sub last_insert_id {
Subroutine last_insert_id: not called CC=2 SCAR=17.9
469 0 my $dbh = shift;
470 0 ▶ my $response = $dbh->{go_response} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $dbh->{"go_response"} or return undef 0 0 0
471 0 return $response->last_insert_id;
472 }
473  
474 2444 ▶ sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.0
475 2444 my ($dbh, $attrib) = @_;
476  
477 # FETCH is effectively already cached because the DBI checks the
478 # attribute cache in the handle before calling FETCH
479 # and this FETCH copies the value into the attribute cache
480  
481 # forward driver-private attributes (except ours)
482 2444 ▶ if ($attrib =~ m/^[a-z]/ && $attrib !~ /^go_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib =~ /^[a-z]/ and not $attrib =~ /^go_/) 7 2437 2444
Condition66%2/3
$attrib =~ /^[a-z]/ and not $attrib =~ /^go_/
!ll&&!rl&&r
243707
MC/DC50%1/2
$attrib =~ /^[a-z]/ and not $attrib =~ /^go_/
$attrib =~ /^[a-z]/ not $attrib =~ /^go_/
Truth table66%2/3
A and not(B)
A= $attrib =~ /^[a-z]/B= not $attrib =~ /^go_/
ABresult
0X0
100
111
483 7 my $value = $dbh->go_dbh_method(undef, 'FETCH', $attrib);
484 7 $dbh->{$attrib} = $value; # XXX forces caching by DBI
485 7 return $dbh->{$attrib} = $value;
486 }
487  
488 # else pass up to DBI to handle
489 2437 return $dbh->SUPER::FETCH($attrib);
490 }
491  
492 7585 ▶ sub STORE {
Subroutine STORE: called CC=11 SCAR=24.3
493 7585 my ($dbh, $attrib, $value) = @_;
494 7585 ▶ if ($attrib eq 'AutoCommit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "AutoCommit") 719 6866 7585
495 719 ▶ croak "Can't enable transactions when using DBD::Gofer" if !$value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 719 719
496 719 ▶ return $dbh->SUPER::STORE($attrib => ($value) ? -901 : -900);
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 719 0 719
497 }
498 return $dbh->SUPER::STORE($attrib => $value)
499 # we handle this attribute locally
500 6866 ▶ if $dbh_local_store_attrib{$attrib}
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_local_store_attrib{$attrib} or $attrib =~ /^private_/ or not $dbh->FETCH("Active") 6852 14 6866
Condition100%6/6
$dbh_local_store_attrib{$attrib} or $attrib =~ /^private_/ or not $dbh->FETCH("Active")
l!l&&r!l&&!r
603581714
$dbh_local_store_attrib{$attrib} or $attrib =~ /^private_/
l!l&&r!l&&!r
60332831
MC/DC100%3/3
$dbh_local_store_attrib{$attrib} or $attrib =~ /^private_/ or not $dbh->FETCH("Active")
$dbh_local_store_attrib{$attrib} $attrib =~ /^private_/ not $dbh->FETCH("Active")
Truth table100%4/4
A or B or not(C)
A= $dbh_local_store_attrib{$attrib}B= $attrib =~ /^private_/C= not $dbh->FETCH("Active")
ABCresult
1XX1
01X1
0011
0000
501 # or it's a private_ (application) attribute
502 or $attrib =~ /^private_/
503 # or not yet connected (ie being called by DBI->connect)
504 or not $dbh->FETCH('Active');
505  
506 return $dbh->SUPER::STORE($attrib => $value)
507 if $DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib}
508 14 ▶ && do { # values are the same
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib} and do { my $crnt = $dbh->FETCH($attrib); no warnings; defined $value ^ defined $crnt ? 0 : $value eq $crnt } 10 4 14
Condition66%2/3
$DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib} and do { my $crnt = $dbh->FETCH($attrib); no warnings; defined $value ^ defined $crnt ? 0 : $value eq $crnt }
!ll&&!rl&&r
4010
MC/DC50%1/2
$DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib} and do { my $crnt = $dbh->FETCH($attrib); no warnings; defined $value ^ defined $crnt ? 0 : $value eq $crnt }
$DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib} do { my $crnt = $dbh->FETCH($attrib); no warnings; defined $value ^ defined $crnt ? 0 : $value eq $crnt }
Truth table66%2/3
A and B
A= $DBD::Gofer::xxh_local_store_attrib_if_same_value{$attrib}B= do { my $crnt = $dbh->FETCH($attrib); no warnings; defined $value ^ defined $crnt ? 0 : $value eq $crnt }
ABresult
0X0
100
111
509 10 my $crnt = $dbh->FETCH($attrib);
510 63 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
511 10 ▶ (defined($value) ^ defined($crnt))
Branch: 1 branch
BranchTrueFalseTotal
defined $value ^ defined $crnt ? : 0 10 10
512 ? 0 # definedness differs
513 : $value eq $crnt;
514 };
515  
516 # dbh attributes are set at connect-time - see connect()
517 4 ▶ carp("Can't alter \$dbh->{$attrib} after handle created with DBD::Gofer") if $dbh->FETCH('Warn');
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->FETCH("Warn") 4 0 4
518 4 return $dbh->set_err($DBI::stderr, "Can't alter \$dbh->{$attrib} after handle created with DBD::Gofer");
519 }
520  
521 123 ▶ sub disconnect {
Subroutine disconnect: called CC=1 SCAR=0.0
522 123 my $dbh = shift;
523 123 $dbh->{go_transport} = undef;
524 123 $dbh->STORE(Active => 0);
525 }
526  
527 1122 ▶ sub prepare {
Subroutine prepare: called CC=11 SCAR=24.2
528 1122 my ($dbh, $statement, $attr)= @_;
529  
530 1122 ▶ return $dbh->set_err($DBI::stderr, "Can't prepare when disconnected")
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->FETCH("Active") 0 1122 1122
531 unless $dbh->FETCH('Active');
532  
533 1122 ▶ $attr = { %$attr } if $attr; # copy so we can edit
Branch: 1 branch
BranchTrueFalseTotal
if $attr 38 1084 1122
534  
535 1122 ▶ my $policy = delete($attr->{go_policy}) || $dbh->{go_policy};
Condition33%1/3
delete $attr->{'go_policy'} || $dbh->{'go_policy'}
l!l&&r!l&&!r
011220
MC/DC0%0/2
delete $attr->{'go_policy'} || $dbh->{'go_policy'}
delete $attr->{'go_policy'} $dbh->{'go_policy'}
Truth table33%1/3
A || B
A= delete $attr->{'go_policy'}B= $dbh->{'go_policy'}
ABresult
1X1
011
000
536 1122 my $lii_args = delete $attr->{go_last_insert_id_args};
537 my $go_prepare = delete($attr->{go_prepare_method})
538 || $dbh->{go_prepare_method}
539 1122 ▶ || $policy->prepare_method($dbh, $statement, $attr)
Condition87%7/8
delete $attr->{'go_prepare_method'} || $dbh->{'go_prepare_method'} || $policy->prepare_method($dbh, $statement, $attr) || 'prepare'
l!l
622500
delete $attr->{"go_prepare_method"} or $dbh->{"go_prepare_method"} or $policy->prepare_method($dbh, $statement, $attr)
l!l&&r!l&&!r
10612500
delete $attr->{"go_prepare_method"} or $dbh->{"go_prepare_method"}
l!l&&r!l&&!r
1001112
MC/DC66%2/3
delete $attr->{'go_prepare_method'} || $dbh->{'go_prepare_method'} || $policy->prepare_method($dbh, $statement, $attr) || 'prepare'
delete $attr->{"go_prepare_method"} $dbh->{"go_prepare_method"} $policy->prepare_method($dbh, $statement, $attr)
Truth table75%3/4
A or B or C
A= delete $attr->{"go_prepare_method"}B= $dbh->{"go_prepare_method"}C= $policy->prepare_method($dbh, $statement, $attr)
ABCresult
1XX1
01X1
0011
0000
540 || 'prepare'; # e.g. for code not using placeholders
541 1122 my $go_cache = delete $attr->{go_cache};
542 # set to undef if there are no attributes left for the actual prepare call
543 1122 ▶ $attr = undef if $attr and not %$attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr and not %$attr 1102 20 1122
Condition66%2/3
$attr and not %$attr
!ll&&!rl&&r
0201102
MC/DC50%1/2
$attr and not %$attr
$attr not %$attr
Truth table66%2/3
A and not(B)
A= $attrB= not %$attr
ABresult
0X0
100
111
544  
545 my ($sth, $sth_inner) = DBI::_new_sth($dbh, {
546 Statement => $statement,
547 go_prepare_call => [ 0, $go_prepare, $statement, $attr ],
548 # go_method_calls => [], # autovivs if needed
549 go_request => $dbh->{go_request},
550 go_transport => $dbh->{go_transport},
551 1122 go_policy => $policy,
552 go_last_insert_id_args => $lii_args,
553 go_cache => $go_cache,
554 });
555 1122 $sth->STORE(Active => 0); # XXX needed? It should be the default
556  
557 1122 my $skip_prepare_check = $policy->skip_prepare_check($attr, $dbh, $statement, $attr, $sth);
558 1122 ▶ if (not $skip_prepare_check) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip_prepare_check) 612 510 1122
559 612 ▶ $sth->go_sth_method() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth->go_sth_method or return undef 540 72 612
560 }
561  
562 1050 return $sth;
563 }
564  
565 14 ▶ sub prepare_cached {
Subroutine prepare_cached: called CC=3 SCAR=11.1
566 14 my ($dbh, $sql, $attr, $if_active)= @_;
567 14 ▶ $attr ||= {};
Condition100%2/2
$attr ||= {}
l!l
212
MC/DC100%1/1
$attr ||= {}
$attr
Truth table100%2/2
A
A= $attr
Aresult
11
00
568 return $dbh->SUPER::prepare_cached($sql, {
569 %$attr,
570 14 ▶ go_prepare_method => $attr->{go_prepare_method} || 'prepare_cached',
Condition50%1/2
$attr->{'go_prepare_method'} || 'prepare_cached'
l!l
014
MC/DC0%0/1
$attr->{'go_prepare_method'} || 'prepare_cached'
$attr->{'go_prepare_method'}
Truth table50%1/2
A
A= $attr->{'go_prepare_method'}
Aresult
11
00
571 }, $if_active);
572 }
573  
574 63 *go_cache = \&DBD::Gofer::go_cache;
575 }
576  
577  
578 63 { package DBD::Gofer::st; # ====== STATEMENT ======
579 63 $imp_data_size = 0;
580 63 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
581  
582 63 my %sth_local_store_attrib = (%DBD::Gofer::xxh_local_store_attrib, NUM_OF_FIELDS => 1);
583  
584 3097 ▶ sub go_sth_method {
Subroutine go_sth_method: called CC=18 SCAR=29.6
585 3097 my ($sth, $meta) = @_;
586  
587 3097 ▶ if (my $ParamValues = $sth->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ParamValues = $sth->{"ParamValues"}) 2157 940 3097
588 2157 my $ParamAttr = $sth->{ParamAttr};
589 # XXX the sort here is a hack to work around a DBD::Sybase bug
590 # but only works properly for params 1..9
591 # (reverse because of the unshift)
592 2157 my @params = reverse sort keys %$ParamValues;
593 2157 ▶ if (@params > 9 && ($sth->{Database}{go_dsn}||'') =~ /dbi:Sybase/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@params > 9 and ($sth->{"Database"}{"go_dsn"} || "") =~ /dbi:Sybase/) 0 2157 2157
Condition60%3/5
@params > 9 and ($sth->{"Database"}{"go_dsn"} || "") =~ /dbi:Sybase/
!ll&&!rl&&r
215250
$sth->{'Database'}{'go_dsn'} || ''
l!l
05
MC/DC0%0/2
@params > 9 and ($sth->{"Database"}{"go_dsn"} || "") =~ /dbi:Sybase/
@params > 9 $sth->{'Database'}{'go_dsn'}
Truth table66%2/3
A and B
A= @params > 9B= $sth->{'Database'}{'go_dsn'}
ABresult
0X0
100
111
594 # if more than 9 then we need to do a proper numeric sort
595 # also warn to alert user of this issue
596 0 warn "Sybase param binding order hack in use";
597 0 @params = sort { $b <=> $a } @params;
598 }
599 2157 for my $p (@params) {
600 # unshift to put binds before execute call
601 5418 unshift @{ $sth->{go_method_calls} },
602 5418 [ 'bind_param', $p, $ParamValues->{$p}, $ParamAttr->{$p} ];
603 }
604 }
605  
606 3097 ▶ my $dbh = $sth->{Database} or die "panic";
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $sth->{"Database"} or die "panic" 3097 0 3097
607 3097 ++$dbh->{go_request_count};
608  
609 3097 my $request = $sth->{go_request};
610 3097 $request->init_request($sth->{go_prepare_call}, $sth);
611 $request->sth_method_calls(delete $sth->{go_method_calls})
612 3097 ▶ if $sth->{go_method_calls};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"go_method_calls"} 2485 612 3097
613 3097 $request->sth_result_attr({}); # (currently) also indicates this is an sth request
614  
615 $request->dbh_last_insert_id_args($meta->{go_last_insert_id_args})
616 3097 ▶ if $meta->{go_last_insert_id_args};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"go_last_insert_id_args"} 0 3097 3097
617  
618 3097 my $go_policy = $sth->{go_policy};
619 3097 my $dbh_attribute_update = $go_policy->dbh_attribute_update();
620 $request->dbh_attributes( $go_policy->dbh_attribute_list() )
621 if $dbh_attribute_update eq 'every'
622 3097 ▶ or $dbh->{go_request_count}==1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1 2941 156 3097
Condition100%3/3
$dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1
l!l&&r!l&&!r
289348156
MC/DC100%2/2
$dbh_attribute_update eq "every" or $dbh->{"go_request_count"} == 1
$dbh_attribute_update eq "every" $dbh->{"go_request_count"} == 1
Truth table100%3/3
A or B
A= $dbh_attribute_update eq "every"B= $dbh->{"go_request_count"} == 1
ABresult
1X1
011
000
623  
624 my $transport = $sth->{go_transport}
625 3097 ▶ or return $sth->set_err($DBI::stderr, "Not connected (no transport)");
Branch: 1 branch
BranchTrueFalseTotal
my $transport = $sth->{"go_transport"} or return $sth->set_err($DBI::stderr, "Not connected (no transport)") 3097 0 3097
626  
627 local $transport->{go_cache} = $sth->{go_cache}
628 3097 ▶ if defined $sth->{go_cache};
Branch: 1 branch
BranchTrueFalseTotal
if defined $sth->{"go_cache"} 2 3095 3097
629  
630 3097 my ($response, $retransmit_sub) = $transport->transmit_request($request);
631 3097 ▶ $response ||= $transport->receive_response($request, $retransmit_sub);
Condition66%2/3
$response ||= $transport->receive_response($request, $retransmit_sub)
l!l&&r!l&&!r
430930
MC/DC0%0/2
$response ||= $transport->receive_response($request, $retransmit_sub)
$response $transport->receive_response($request, $retransmit_sub)
Truth table66%2/3
A ||= B
A= $responseB= $transport->receive_response($request, $retransmit_sub)
ABresult
1X1
011
000
632 3097 ▶ $sth->{go_response} = $response
Branch: 1 branch
BranchTrueFalseTotal
$sth->{"go_response"} = $response or die "No response object returned by $transport" 3097 0 3097
633 or die "No response object returned by $transport";
634 3097 $dbh->{go_response} = $response; # mainly for last_insert_id
635  
636 3097 ▶ if (my $dbh_attributes = $response->dbh_attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh_attributes = $response->dbh_attributes) 2953 144 3097
637 # XXX we don't STORE here, we just stuff the value into the attribute cache
638 $dbh->{$_} = $dbh_attributes->{$_}
639 2953 for keys %$dbh_attributes;
640 # record the values returned, so we know that we have fetched
641 # values are which we have fetched (see dbh->FETCH method)
642 2953 $dbh->{go_dbh_attributes_fetched} = $dbh_attributes;
643 }
644  
645 3097 my $rv = $response->rv; # may be undef on error
646 3097 ▶ if ($response->sth_resultsets) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->sth_resultsets) { } 3025 72 3097
647 # setup first resultset - including sth attributes
648 3025 $sth->more_results;
649 }
650 else {
651 72 $sth->STORE(Active => 0);
652 72 $sth->{go_rows} = $rv;
653 }
654 # set error/warn/info (after more_results as that'll clear err)
655 3097 DBD::Gofer::set_err_from_response($sth, $response);
656  
657 3097 return $rv;
658 }
659  
660  
661 5378 ▶ sub bind_param {
Subroutine bind_param: called CC=2 SCAR=7.0
662 5378 my ($sth, $param, $value, $attr) = @_;
663 5378 $sth->{ParamValues}{$param} = $value;
664 5378 ▶ $sth->{ParamAttr}{$param} = $attr
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr 0 5378 5378
665 if defined $attr; # attr is sticky if not explicitly set
666 5378 return 1;
667 }
668  
669  
670 2485 ▶ sub execute {
Subroutine execute: called CC=2 SCAR=6.9
671 2485 my $sth = shift;
672 2485 $sth->bind_param($_, $_[$_-1]) for (1..@_);
673 2485 push @{ $sth->{go_method_calls} }, [ 'execute' ];
674 2485 my $meta = { go_last_insert_id_args => $sth->{go_last_insert_id_args} };
675 2485 return $sth->go_sth_method($meta);
676 }
677  
678  
679 3311 ▶ sub more_results {
Subroutine more_results: called CC=10 SCAR=23.0
680 3311 my $sth = shift;
681  
682 3311 $sth->finish;
683  
684 3311 ▶ my $response = $sth->{go_response} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $response = $sth->{"go_response"} or do { $sth->trace_msg(" No response object present", 3); return } 3215 96 3311
685 # e.g., we haven't sent a request yet (ie prepare then more_results)
686 96 $sth->trace_msg(" No response object present", 3);
687 96 return;
688 };
689  
690 3215 ▶ my $resultset_list = $response->sth_resultsets
Branch: 1 branch
BranchTrueFalseTotal
my $resultset_list = $response->sth_resultsets or return $sth->set_err($DBI::stderr, "No sth_resultsets") 3215 0 3215
691 or return $sth->set_err($DBI::stderr, "No sth_resultsets");
692  
693 3215 ▶ my $meta = shift @$resultset_list
Branch: 1 branch
BranchTrueFalseTotal
my $meta = shift @$resultset_list or return undef 3035 180 3215
694 or return undef; # no more result sets
695 #warn "more_results: ".Data::Dumper::Dumper($meta);
696  
697 # pull out the special non-attributes first
698 my ($rowset, $err, $errstr, $state)
699 3035 = delete @{$meta}{qw(rowset err errstr state)};
700  
701 # copy meta attributes into attribute cache
702 3035 my $NUM_OF_FIELDS = delete $meta->{NUM_OF_FIELDS};
703 3035 $sth->STORE('NUM_OF_FIELDS', $NUM_OF_FIELDS);
704 # XXX need to use STORE for some?
705 3035 $sth->{$_} = $meta->{$_} for keys %$meta;
706  
707 3035 ▶ if (($NUM_OF_FIELDS||0) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (($NUM_OF_FIELDS || 0) > 0) 2496 539 3035
Condition100%2/2
$NUM_OF_FIELDS || 0
l!l
2496539
MC/DC100%1/1
$NUM_OF_FIELDS || 0
$NUM_OF_FIELDS
Truth table100%2/2
A
A= $NUM_OF_FIELDS
Aresult
11
00
708 2496 ▶ $sth->{go_rows} = ($rowset) ? @$rowset : -1;
Branch: 1 branch
BranchTrueFalseTotal
$rowset ? : 2198 298 2496
709 2496 $sth->{go_current_rowset} = $rowset;
710 2496 ▶ $sth->{go_current_rowset_err} = [ $err, $errstr, $state ]
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 298 2198 2496
711 if defined $err;
712 2496 ▶ $sth->STORE(Active => 1) if $rowset;
Branch: 1 branch
BranchTrueFalseTotal
if $rowset 2198 298 2496
713 }
714  
715 3035 return $sth;
716 }
717  
718  
719 0 ▶ sub go_clone_sth {
Subroutine go_clone_sth: not called CC=3 SCAR=24.8
720 0 my ($sth1) = @_;
721 # clone an (un-fetched-from) sth - effectively undoes the initial more_results
722 # not 100% so just for use in caching returned sth e.g. table_info
723 0 my $sth2 = $sth1->{Database}->prepare($sth1->{Statement}, { go_skip_prepare_check => 1 });
724 0 $sth2->STORE($_, $sth1->{$_}) for qw(NUM_OF_FIELDS Active);
725 0 my $sth2_inner = tied %$sth2;
726 0 $sth2_inner->{$_} = $sth1->{$_} for qw(NUM_OF_PARAMS FetchHashKeyName);
727 0 die "not fully implemented yet";
728 0 return $sth2;
729 }
730  
731  
732 4838 ▶ sub fetchrow_arrayref {
Subroutine fetchrow_arrayref: called CC=4 SCAR=16.6
733 4838 my ($sth) = @_;
734 4838 ▶ my $resultset = $sth->{go_current_rowset} || do {
Condition33%1/3
$sth->{'go_current_rowset'} || do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
l!l&&r!l&&!r
483800
MC/DC0%0/2
$sth->{'go_current_rowset'} || do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
$sth->{'go_current_rowset'} do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
Truth table33%1/3
A || B
A= $sth->{'go_current_rowset'}B= do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
ABresult
1X1
011
000
735 # should only happen if fetch called after execute failed
736 my $rowset_err = $sth->{go_current_rowset_err}
737 0 ▶ || [ 1, 'no result set (did execute fail)' ];
Condition0%0/2
$sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']
l!l
00
MC/DC0%0/1
$sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']
$sth->{'go_current_rowset_err'}
Truth table0%0/2
A
A= $sth->{'go_current_rowset_err'}
Aresult
11
00
738 0 return $sth->set_err( @$rowset_err );
739 };
740 4838 ▶ return $sth->_set_fbav(shift @$resultset) if @$resultset;
Branch: 1 branch
BranchTrueFalseTotal
if @$resultset 4685 153 4838
741 153 $sth->finish; # no more data so finish
742 153 return undef;
743 }
744 63 *fetch = \&fetchrow_arrayref; # alias
745  
746  
747 250 ▶ sub fetchall_arrayref {
Subroutine fetchall_arrayref: called CC=6 SCAR=18.1
748 250 my ($sth, $slice, $max_rows) = @_;
749 250 ▶ my $resultset = $sth->{go_current_rowset} || do {
Condition66%2/3
$sth->{'go_current_rowset'} || do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
l!l&&r!l&&!r
226240
MC/DC0%0/2
$sth->{'go_current_rowset'} || do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
$sth->{'go_current_rowset'} do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
Truth table33%1/3
A || B
A= $sth->{'go_current_rowset'}B= do { my $rowset_err = $sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']; return $sth->set_err(@$rowset_err) }
ABresult
1X1
011
000
750 # should only happen if fetch called after execute failed
751 my $rowset_err = $sth->{go_current_rowset_err}
752 24 ▶ || [ 1, 'no result set (did execute fail)' ];
Condition50%1/2
$sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']
l!l
240
MC/DC0%0/1
$sth->{'go_current_rowset_err'} || [1, 'no result set (did execute fail)']
$sth->{'go_current_rowset_err'}
Truth table50%1/2
A
A= $sth->{'go_current_rowset_err'}
Aresult
11
00
753 24 return $sth->set_err( @$rowset_err );
754 };
755 226 ▶ my $mode = ref($slice) || 'ARRAY';
Condition100%2/2
ref $slice || 'ARRAY'
l!l
30196
MC/DC100%1/1
ref $slice || 'ARRAY'
ref $slice
Truth table100%2/2
A
A= ref $slice
Aresult
11
00
756 226 ▶ return $sth->SUPER::fetchall_arrayref($slice, $max_rows)
Branch: 1 branch
BranchTrueFalseTotal
if ref $slice or defined $max_rows 30 196 226
Condition66%2/3
ref $slice or defined $max_rows
l!l&&r!l&&!r
300196
MC/DC50%1/2
ref $slice or defined $max_rows
ref $slice defined $max_rows
Truth table66%2/3
A or B
A= ref $sliceB= defined $max_rows
ABresult
1X1
011
000
757 if ref($slice) or defined $max_rows;
758 196 $sth->finish; # no more data after this so finish
759 196 return $resultset;
760 }
761  
762  
763 36 ▶ sub rows {
Subroutine rows: called CC=1 SCAR=0.0
764 36 return shift->{go_rows};
765 }
766  
767  
768 6512 ▶ sub STORE {
Subroutine STORE: called CC=4 SCAR=22.3
769 6512 my ($sth, $attrib, $value) = @_;
770  
771 return $sth->SUPER::STORE($attrib => $value)
772 6512 ▶ if $sth_local_store_attrib{$attrib} # handle locally
Branch: 1 branch
BranchTrueFalseTotal
if $sth_local_store_attrib{$attrib} or $attrib =~ /^private_/ 6512 0 6512
Condition33%1/3
$sth_local_store_attrib{$attrib} or $attrib =~ /^private_/
l!l&&r!l&&!r
651200
MC/DC0%0/2
$sth_local_store_attrib{$attrib} or $attrib =~ /^private_/
$sth_local_store_attrib{$attrib} $attrib =~ /^private_/
Truth table33%1/3
A or B
A= $sth_local_store_attrib{$attrib}B= $attrib =~ /^private_/
ABresult
1X1
011
000
773 # or it's a private_ (application) attribute
774 or $attrib =~ /^private_/;
775  
776 # otherwise warn but do it anyway
777 # this will probably need refining later
778 0 my $msg = "Altering \$sth->{$attrib} won't affect proxied handle";
779 0 ▶ Carp::carp($msg) if $sth->FETCH('Warn');
Branch: 1 branch
BranchTrueFalseTotal
if $sth->FETCH("Warn") 0 0 0
780  
781 # XXX could perhaps do
782 # push @{ $sth->{go_method_calls} }, [ 'STORE', $attrib, $value ]
783 # if not $sth->FETCH('Executed');
784 # but how to handle repeat executions? How to we know when an
785 # attribute is being set to affect the current resultset or the
786 # next execution?
787 # Could just always use go_method_calls I guess.
788  
789 # do the store locally anyway, just in case
790 0 $sth->SUPER::STORE($attrib => $value);
791  
792 0 return $sth->set_err($DBI::stderr, $msg);
793 }
794  
795 # sub bind_param_array
796 # we use DBI's default, which sets $sth->{ParamArrays}{$param} = $value
797 # and calls bind_param($param, undef, $attr) if $attr.
798  
799 0 ▶ sub execute_array {
Subroutine execute_array: not called CC=2 SCAR=17.9
800 0 my $sth = shift;
801 0 my $attr = shift;
802 0 $sth->bind_param_array($_, $_[$_-1]) for (1..@_);
803 0 push @{ $sth->{go_method_calls} }, [ 'execute_array', $attr ];
804 0 return $sth->go_sth_method($attr);
805 }
806  
807 63 *go_cache = \&DBD::Gofer::go_cache;
808 }
809  
810 63 1;
811  
812 __END__
« blib/lib/DBD/Gofer/Transport/stream.pm ↑ Summary blib/lib/Win32/DBIODBC.pm »