blib/lib/DBI.pm

filter: Statementstmt 83.2% 813 / 977 Branchbran 67.1% 396 / 590 Conditioncond 54.8% 222 / 405 MC/DCmcdc 35.7% 80 / 224 Subroutinesub 81.2% 91 / 112 Podpod 100% 24 / 24 totaltotal 69.7% 1626 / 2332 CC 918 SCAR 36.4
CC
918
Cov
73%
connect_test_perf
380.0
connect_test_perf
380.0
_dbtype_names
240.0
CRAP 38.1
« blib/lib/DBI/Const/GetInfoReturn.pm ↑ Summary blib/lib/DBI/DBD.pm »
1 # $Id$
2 # vim: ts=8:sw=4:et
3 #
4 # Copyright (c) 2024-2026 DBI Team
5 # Copyright (c) 1994-2024 Tim Bunce Ireland
6 #
7 # See COPYRIGHT section in pod text below for usage and distribution rights.
8 #
9  
10 package DBI;
11  
12 214 require 5.012000;
13  
14 214 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 214 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 214 our ($XS_VERSION, $VERSION);
18 214 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
19 214 $VERSION = "1.656"; # ==> ALSO update the version in the pod text below!
20 214 $XS_VERSION = $VERSION;
21 214 $VERSION =~ tr/_//d;
22 }
23  
24 =head1 NAME
25  
26 DBI - Database independent interface for Perl
27  
28 =head1 SYNOPSIS
29  
30 use DBI;
31  
32 @driver_names = DBI->available_drivers;
33 %drivers = DBI->installed_drivers;
34 @data_sources = DBI->data_sources($driver_name, \%attr);
35  
36 $dbh = DBI->connect($data_source, $username, $auth, \%attr);
37  
38 $rv = $dbh->do($statement);
39 $rv = $dbh->do($statement, \%attr);
40 $rv = $dbh->do($statement, \%attr, @bind_values);
41  
42 $ary_ref = $dbh->selectall_arrayref($statement);
43 $hash_ref = $dbh->selectall_hashref($statement, $key_field);
44  
45 $ary_ref = $dbh->selectcol_arrayref($statement);
46 $ary_ref = $dbh->selectcol_arrayref($statement, \%attr);
47  
48 @row_ary = $dbh->selectrow_array($statement);
49 $ary_ref = $dbh->selectrow_arrayref($statement);
50 $hash_ref = $dbh->selectrow_hashref($statement);
51  
52 $sth = $dbh->prepare($statement);
53 $sth = $dbh->prepare_cached($statement);
54  
55 $rc = $sth->bind_param($p_num, $bind_value);
56 $rc = $sth->bind_param($p_num, $bind_value, $bind_type);
57 $rc = $sth->bind_param($p_num, $bind_value, \%attr);
58  
59 $rv = $sth->execute;
60 $rv = $sth->execute(@bind_values);
61 $rv = $sth->execute_array(\%attr, ...);
62  
63 $rc = $sth->bind_col($col_num, \$col_variable);
64 $rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);
65  
66 @row_ary = $sth->fetchrow_array;
67 $ary_ref = $sth->fetchrow_arrayref;
68 $hash_ref = $sth->fetchrow_hashref;
69  
70 $ary_ref = $sth->fetchall_arrayref;
71 $ary_ref = $sth->fetchall_arrayref( $slice, $max_rows );
72  
73 $hash_ref = $sth->fetchall_hashref( $key_field );
74  
75 $rv = $sth->rows;
76  
77 $rc = $dbh->begin_work;
78 $rc = $dbh->commit;
79 $rc = $dbh->rollback;
80  
81 $quoted_string = $dbh->quote($string);
82  
83 $rc = $h->err;
84 $str = $h->errstr;
85 $rv = $h->state;
86  
87 $rc = $dbh->disconnect;
88  
89 I<The synopsis above only lists the major methods and parameters.>
90  
91  
92 =head2 GETTING HELP
93  
94 =head3 General
95  
96 Before asking any questions, reread this document, consult the archives and
97 read the DBI FAQ. The archives are listed at the end of this document and on
98 the DBI home page L<http://dbi.perl.org/support/>
99  
100 You might also like to read the Advanced DBI Tutorial at
101 L<http://www.slideshare.net/Tim.Bunce/dbi-advanced-tutorial-2007>
102  
103 To help you make the best use of the dbi-users mailing list,
104 and any other lists or forums you may use, I recommend that you read
105 "Getting Answers" by Mike Ash: L<http://mikeash.com/getting_answers.html>.
106  
107 =head3 Mailing Lists
108  
109 If you have questions about DBI, or DBD driver modules, you can get
110 help from the I<dbi-users@perl.org> mailing list. This is the best way to get
111 help. You don't have to subscribe to the list in order to post, though I'd
112 recommend it. You can get help on subscribing and using the list by emailing
113 I<dbi-users-help@perl.org>.
114  
115 Please note that Tim Bunce does not maintain the mailing lists or the
116 web pages (generous volunteers do that). So please don't send mail
117 directly to him; he just doesn't have the time to answer questions
118 personally. The I<dbi-users> mailing list has lots of experienced
119 people who should be able to help you if you need it. If you do email
120 Tim he is very likely to just forward it to the mailing list.
121  
122 =head3 IRC
123  
124 DBI IRC Channel: #dbi on irc.perl.org (L<irc://irc.perl.org/#dbi>)
125  
126 =for html <a href="http://chat.mibbit.com/#dbi@irc.perl.org">(click for instant chatroom login)</a>
127  
128 =head3 Online
129  
130 StackOverflow has a DBI tag L<https://stackoverflow.com/questions/tagged/dbi>
131 with over 800 questions.
132  
133 The DBI home page at L<https://dbi.perl.org/> might be worth a visit.
134 It includes links to other resources, but I<is rather out-dated>.
135  
136 =head3 Reporting a Bug
137  
138 If you think you've found a bug then please read
139 "How to Report Bugs Effectively" by Simon Tatham:
140 L<https://www.chiark.greenend.org.uk/~sgtatham/bugs.html>.
141  
142 If you think you've found a memory leak then read L</Memory Leaks>.
143  
144 Your problem is most likely related to the specific DBD driver module you're
145 using. If that's the case then click on the 'Bugs' link on the L<https://metacpan.org>
146 page for your driver. Only submit a bug report against the DBI itself if you're
147 sure that your issue isn't related to the driver you're using.
148  
149 =head2 NOTES
150  
151 This is the DBI specification that corresponds to DBI version 1.656
152 (see L<DBI::Changes> for details).
153  
154 The DBI is evolving at a steady pace, so it's good to check that
155 you have the latest copy.
156  
157 The significant user-visible changes in each release are documented
158 in the L<DBI::Changes> module so you can read them by executing
159 C<perldoc DBI::Changes>.
160  
161 Some DBI changes require changes in the drivers, but the drivers
162 can take some time to catch up. Newer versions of the DBI have
163 added features that may not yet be supported by the drivers you
164 use. Talk to the authors of your drivers if you need a new feature
165 that is not yet supported.
166  
167 Features added after DBI 1.21 (February 2002) are marked in the
168 text with the version number of the DBI release they first appeared in.
169  
170 Extensions to the DBI API often use the C<DBIx::*> namespace.
171 See L</Naming Conventions and Name Space>. DBI extension modules
172 can be found at L<https://metacpan.org/search?q=DBIx>. And all modules
173 related to the DBI can be found at L<https://metacpan.org/search?q=DBI>.
174  
175 =cut
176  
177 # The POD text continues at the end of the file.
178  
179 214 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
180 214 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
181 214 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
182 214 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 214 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
185 214 ▶BEGIN {
Subroutine BEGIN: called CC=6 SCAR=18.6
186 214 @ISA = qw(Exporter);
187  
188 # Make some utility functions available if asked for
189 214 @EXPORT = (); # we export nothing by default
190 214 @EXPORT_OK = qw(%DBI %DBI_methods hash); # also populated by export_ok_tags:
191 214 %EXPORT_TAGS = (
192 sql_types => [ qw(
193 SQL_GUID
194 SQL_WLONGVARCHAR
195 SQL_WVARCHAR
196 SQL_WCHAR
197 SQL_BIGINT
198 SQL_BIT
199 SQL_TINYINT
200 SQL_LONGVARBINARY
201 SQL_VARBINARY
202 SQL_BINARY
203 SQL_LONGVARCHAR
204 SQL_UNKNOWN_TYPE
205 SQL_ALL_TYPES
206 SQL_CHAR
207 SQL_NUMERIC
208 SQL_DECIMAL
209 SQL_INTEGER
210 SQL_SMALLINT
211 SQL_FLOAT
212 SQL_REAL
213 SQL_DOUBLE
214 SQL_DATETIME
215 SQL_DATE
216 SQL_INTERVAL
217 SQL_TIME
218 SQL_TIMESTAMP
219 SQL_VARCHAR
220 SQL_BOOLEAN
221 SQL_UDT
222 SQL_UDT_LOCATOR
223 SQL_ROW
224 SQL_REF
225 SQL_BLOB
226 SQL_BLOB_LOCATOR
227 SQL_CLOB
228 SQL_CLOB_LOCATOR
229 SQL_ARRAY
230 SQL_ARRAY_LOCATOR
231 SQL_MULTISET
232 SQL_MULTISET_LOCATOR
233 SQL_TYPE_DATE
234 SQL_TYPE_TIME
235 SQL_TYPE_TIMESTAMP
236 SQL_TYPE_TIME_WITH_TIMEZONE
237 SQL_TYPE_TIMESTAMP_WITH_TIMEZONE
238 SQL_INTERVAL_YEAR
239 SQL_INTERVAL_MONTH
240 SQL_INTERVAL_DAY
241 SQL_INTERVAL_HOUR
242 SQL_INTERVAL_MINUTE
243 SQL_INTERVAL_SECOND
244 SQL_INTERVAL_YEAR_TO_MONTH
245 SQL_INTERVAL_DAY_TO_HOUR
246 SQL_INTERVAL_DAY_TO_MINUTE
247 SQL_INTERVAL_DAY_TO_SECOND
248 SQL_INTERVAL_HOUR_TO_MINUTE
249 SQL_INTERVAL_HOUR_TO_SECOND
250 SQL_INTERVAL_MINUTE_TO_SECOND
251 ) ],
252 sql_cursor_types => [ qw(
253 SQL_CURSOR_FORWARD_ONLY
254 SQL_CURSOR_KEYSET_DRIVEN
255 SQL_CURSOR_DYNAMIC
256 SQL_CURSOR_STATIC
257 SQL_CURSOR_TYPE_DEFAULT
258 ) ], # for ODBC cursor types
259 utils => [ qw(
260 neat neat_list $neat_maxlen dump_results looks_like_number
261 data_string_diff data_string_desc data_diff sql_type_cast
262 DBIstcf_DISCARD_STRING
263 DBIstcf_STRICT
264 ) ],
265 profile => [ qw(
266 dbi_profile dbi_profile_merge dbi_profile_merge_nodes dbi_time
267 ) ], # notionally "in" DBI::Profile and normally imported from there
268 );
269  
270 214 $DBI::dbi_debug = 0; # mixture of bit fields and int sub-fields
271 214 $DBI::neat_maxlen = 1000;
272 214 $DBI::stderr = 2_000_000_000; # a very round number below 2**31
273  
274 # If you get an error here like "Can't find loadable object ..."
275 # then you haven't installed the DBI correctly. Read the README
276 # then install it again.
277 214 ▶if ( $ENV{DBI_PUREPERL} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'DBI_PUREPERL'}) { } 107 107 214
278 0 ▶ eval { XSLoader::load('DBI', $XS_VERSION) } if $ENV{DBI_PUREPERL} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DBI_PUREPERL"} == 1 0 107 107
279 107 ▶ require DBI::PurePerl if $@ or $ENV{DBI_PUREPERL} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $@ or $ENV{"DBI_PUREPERL"} >= 2 107 0 107
Condition33%1/3
$@ or $ENV{"DBI_PUREPERL"} >= 2
l!l&&r!l&&!r
01070
MC/DC0%0/2
$@ or $ENV{"DBI_PUREPERL"} >= 2
$@ $ENV{"DBI_PUREPERL"} >= 2
Truth table33%1/3
A or B
A= $@B= $ENV{"DBI_PUREPERL"} >= 2
ABresult
1X1
011
000
280 107 ▶ $DBI::PurePerl ||= 0; # just to silence "only used once" warnings
Condition50%1/2
$DBI::PurePerl ||= 0
l!l
1070
MC/DC0%0/1
$DBI::PurePerl ||= 0
$DBI::PurePerl
Truth table50%1/2
A
A= $DBI::PurePerl
Aresult
11
00
281 }
282 else {
283 107 XSLoader::load( 'DBI', $XS_VERSION);
284 }
285  
286 214 $EXPORT_TAGS{preparse_flags} = [ grep { /^DBIpp_\w\w_/ } keys %DBI:: ];
287  
288 214 Exporter::export_ok_tags(keys %EXPORT_TAGS);
289  
290 }
291  
292 # Alias some handle methods to also be DBI class methods
293 214 for (qw(trace_msg set_err parse_trace_flag parse_trace_flags)) {
294 214 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
295 856 *$_ = \&{"DBD::_::common::$_"};
296 }
297  
298 214 ▶DBI->trace(split /=/, $ENV{DBI_TRACE}, 2) if $ENV{DBI_TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DBI_TRACE"} 0 214 214
299  
300 214 ▶$DBI::connect_via ||= "connect";
Condition50%1/2
$DBI::connect_via ||= "connect"
l!l
0214
MC/DC0%0/1
$DBI::connect_via ||= "connect"
$DBI::connect_via
Truth table50%1/2
A
A= $DBI::connect_via
Aresult
11
00
301  
302 # check if user wants a persistent database connection ( Apache + mod_perl )
303 214 ▶if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}) 0 214 214
Condition33%1/3
$INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}
!ll&&!rl&&r
21400
MC/DC0%0/2
$INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}
$INC{"Apache/DBI.pm"} $ENV{"MOD_PERL"}
Truth table33%1/3
A and B
A= $INC{"Apache/DBI.pm"}B= $ENV{"MOD_PERL"}
ABresult
0X0
100
111
304 0 $DBI::connect_via = "Apache::DBI::connect";
305 0 DBI->trace_msg("DBI connect via $DBI::connect_via in $INC{'Apache/DBI.pm'}\n");
306 }
307  
308 214 %DBI::installed_drh = (); # maps driver names to installed driver handles
309 24 ▶sub installed_drivers { %DBI::installed_drh }
Subroutine installed_drivers: called CC=1 SCAR=0.0
Pod documented
310 214 %DBI::installed_methods = (); # XXX undocumented, may change
311 3524 ▶sub installed_methods { %DBI::installed_methods }
Subroutine installed_methods: called CC=1 SCAR=0.0
Pod documented
312  
313 # Setup special DBI dynamic variables. See DBI::var::FETCH for details.
314 # These are dynamically associated with the last handle used.
315 214 tie $DBI::err, 'DBI::var', '*err'; # special case: referenced via IHA list
316 214 tie $DBI::state, 'DBI::var', '"state'; # special case: referenced via IHA list
317 214 tie $DBI::lasth, 'DBI::var', '!lasth'; # special case: return boolean
318 214 tie $DBI::errstr, 'DBI::var', '&errstr'; # call &errstr in last used pkg
319 214 tie $DBI::rows, 'DBI::var', '&rows'; # call &rows in last used pkg
320 1070 ▶sub DBI::var::TIESCALAR{ my $var = $_[1]; bless \$var, 'DBI::var'; }
Subroutine TIESCALAR: called CC=1 SCAR=0.0
321 2 ▶sub DBI::var::STORE { Carp::croak("Can't modify \$DBI::${$_[0]} special variable") }
Subroutine STORE: called CC=1 SCAR=0.0
322  
323 # --- Driver Specific Prefix Registry ---
324  
325 214 my $dbd_prefix_registry = {
326 ad_ => { class => 'DBD::AnyData', },
327 ad2_ => { class => 'DBD::AnyData2', },
328 ado_ => { class => 'DBD::ADO', },
329 amzn_ => { class => 'DBD::Amazon', },
330 best_ => { class => 'DBD::BestWins', },
331 csv_ => { class => 'DBD::CSV', },
332 cubrid_ => { class => 'DBD::cubrid', },
333 db2_ => { class => 'DBD::DB2', },
334 dbi_ => { class => 'DBI', },
335 dbm_ => { class => 'DBD::DBM', },
336 df_ => { class => 'DBD::DF', },
337 examplep_ => { class => 'DBD::ExampleP', },
338 f_ => { class => 'DBD::File', },
339 file_ => { class => 'DBD::TextFile', },
340 go_ => { class => 'DBD::Gofer', },
341 ib_ => { class => 'DBD::InterBase', },
342 ing_ => { class => 'DBD::Ingres', },
343 ix_ => { class => 'DBD::Informix', },
344 jdbc_ => { class => 'DBD::JDBC', },
345 mariadb_ => { class => 'DBD::MariaDB', },
346 mem_ => { class => 'DBD::Mem', },
347 mo_ => { class => 'DBD::MO', },
348 monetdb_ => { class => 'DBD::monetdb', },
349 msql_ => { class => 'DBD::mSQL', },
350 mvsftp_ => { class => 'DBD::MVS_FTPSQL', },
351 mysql_ => { class => 'DBD::mysql', },
352 multi_ => { class => 'DBD::Multi' },
353 mx_ => { class => 'DBD::Multiplex', },
354 neo_ => { class => 'DBD::Neo4p', },
355 nullp_ => { class => 'DBD::NullP', },
356 odbc_ => { class => 'DBD::ODBC', },
357 ora_ => { class => 'DBD::Oracle', },
358 pg_ => { class => 'DBD::Pg', },
359 pgpp_ => { class => 'DBD::PgPP', },
360 plb_ => { class => 'DBD::Plibdata', },
361 po_ => { class => 'DBD::PO', },
362 proxy_ => { class => 'DBD::Proxy', },
363 ram_ => { class => 'DBD::RAM', },
364 rdb_ => { class => 'DBD::RDB', },
365 sapdb_ => { class => 'DBD::SAP_DB', },
366 snmp_ => { class => 'DBD::SNMP', },
367 solid_ => { class => 'DBD::Solid', },
368 spatialite_ => { class => 'DBD::Spatialite', },
369 sponge_ => { class => 'DBD::Sponge', },
370 sql_ => { class => 'DBI::DBD::SqlEngine', },
371 sqlite_ => { class => 'DBD::SQLite', },
372 syb_ => { class => 'DBD::Sybase', },
373 sys_ => { class => 'DBD::Sys', },
374 tdat_ => { class => 'DBD::Teradata', },
375 tmpl_ => { class => 'DBD::Template', },
376 tmplss_ => { class => 'DBD::TemplateSS', },
377 tree_ => { class => 'DBD::TreeData', },
378 tuber_ => { class => 'DBD::Tuber', },
379 uni_ => { class => 'DBD::Unify', },
380 vt_ => { class => 'DBD::Vt', },
381 wmi_ => { class => 'DBD::WMI', },
382 x_ => { }, # for private use
383 xbase_ => { class => 'DBD::XBase', },
384 xmlsimple_ => { class => 'DBD::XMLSimple', },
385 xl_ => { class => 'DBD::Excel', },
386 yaswi_ => { class => 'DBD::Yaswi', },
387 };
388  
389 12840 my %dbd_class_registry = map { $dbd_prefix_registry->{$_}->{class} => { prefix => $_ } }
390 13054 grep { exists $dbd_prefix_registry->{$_}->{class} }
391 214 keys %{$dbd_prefix_registry};
392  
393 0 ▶sub dump_dbd_registry {
Subroutine dump_dbd_registry: not called CC=1 SCAR=6.9
Pod documented
394 0 require Data::Dumper;
395 0 local $Data::Dumper::Sortkeys=1;
396 0 local $Data::Dumper::Indent=1;
397 0 print Data::Dumper->Dump([$dbd_prefix_registry], [qw($dbd_prefix_registry)]);
398 }
399  
400 # --- Dynamically create the DBI Standard Interface
401  
402 214 my $keeperr = { O=>0x0004 };
403  
404 214 %DBI::DBI_methods = ( # Define the DBI interface methods per class:
405  
406 common => { # Interface methods common to all DBI handle classes
407 'DESTROY' => { O=>0x004|0x10000 },
408 'CLEAR' => $keeperr,
409 'EXISTS' => $keeperr,
410 'FETCH' => { O=>0x0404 },
411 'FETCH_many' => { O=>0x0404 },
412 'FIRSTKEY' => $keeperr,
413 'NEXTKEY' => $keeperr,
414 'STORE' => { O=>0x0418 | 0x4 },
415 'DELETE' => { O=>0x0404 },
416 can => { O=>0x0100 }, # special case, see dispatch
417 debug => { U =>[1,2,'[$debug_level]'], O=>0x0004 }, # old name for trace
418 dump_handle => { U =>[1,3,'[$message [, $level]]'], O=>0x0004 },
419 err => $keeperr,
420 errstr => $keeperr,
421 state => $keeperr,
422 func => { O=>0x0006 },
423 parse_trace_flag => { U =>[2,2,'$name'], O=>0x0404, T=>8 },
424 parse_trace_flags => { U =>[2,2,'$flags'], O=>0x0404, T=>8 },
425 private_data => { U =>[1,1], O=>0x0004 },
426 set_err => { U =>[3,6,'$err, $errmsg [, $state, $method, $rv]'], O=>0x0010 },
427 trace => { U =>[1,3,'[$trace_level, [$filename]]'], O=>0x0004 },
428 trace_msg => { U =>[2,3,'$message_text [, $min_level ]' ], O=>0x0004, T=>8 },
429 swap_inner_handle => { U =>[2,3,'$h [, $allow_reparent ]'] },
430 private_attribute_info => { },
431 visit_child_handles => { U => [2,3,'$coderef [, $info ]'], O=>0x0404, T=>4 },
432 },
433 dr => { # Database Driver Interface
434 'connect' => { U =>[1,5,'[$db [,$user [,$passwd [,\%attr]]]]'], H=>3, O=>0x8000, T=>0x200 },
435 'connect_cached'=>{U=>[1,5,'[$db [,$user [,$passwd [,\%attr]]]]'], H=>3, O=>0x8000, T=>0x200 },
436 'disconnect_all'=>{ U =>[1,1], O=>0x0800, T=>0x200 },
437 data_sources => { U =>[1,2,'[\%attr]' ], O=>0x0800, T=>0x200 },
438 default_user => { U =>[3,4,'$user, $pass [, \%attr]' ], T=>0x200 },
439 dbixs_revision => $keeperr,
440 },
441 db => { # Database Session Class Interface
442 data_sources => { U =>[1,2,'[\%attr]' ], O=>0x0200 },
443 take_imp_data => { U =>[1,1], O=>0x10000 },
444 clone => { U =>[1,2,'[\%attr]'], T=>0x200 },
445 connected => { U =>[1,0], O => 0x0004, T=>0x200, H=>3 },
446 begin_work => { U =>[1,2,'[ \%attr ]'], O=>0x0400, T=>0x1000 },
447 commit => { U =>[1,1], O=>0x0480|0x0800, T=>0x1000 },
448 rollback => { U =>[1,1], O=>0x0480|0x0800, T=>0x1000 },
449 'do' => { U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x3200 },
450 last_insert_id => { U =>[1,6,'[$catalog [,$schema [,$table_name [,$field_name [, \%attr ]]]]]'], O=>0x2800 },
451 preparse => { }, # XXX
452 prepare => { U =>[2,3,'$statement [, \%attr]'], O=>0xA200 },
453 prepare_cached => { U =>[2,4,'$statement [, \%attr [, $if_active ] ]'], O=>0xA200 },
454 selectrow_array => { U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
455 selectrow_arrayref=>{U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
456 selectrow_hashref=>{ U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
457 selectall_arrayref=>{U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
458 selectall_array =>{U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
459 selectall_hashref=>{ U =>[3,0,'$statement, $keyfield [, \%attr [, @bind_params ] ]'], O=>0x2000 },
460 selectcol_arrayref=>{U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'], O=>0x2000 },
461 ping => { U =>[1,1], O=>0x0404 },
462 disconnect => { U =>[1,1], O=>0x0400|0x0800|0x10000, T=>0x200 },
463 quote => { U =>[2,3, '$string [, $data_type ]' ], O=>0x0430, T=>2 },
464 quote_identifier=> { U =>[2,6, '$name [, ...] [, \%attr ]' ], O=>0x0430, T=>2 },
465 rows => $keeperr,
466  
467 tables => { U =>[1,6,'$catalog, $schema, $table, $type [, \%attr ]' ], O=>0x2200 },
468 table_info => { U =>[1,6,'$catalog, $schema, $table, $type [, \%attr ]' ], O=>0x2200|0x8800 },
469 column_info => { U =>[5,6,'$catalog, $schema, $table, $column [, \%attr ]'],O=>0x2200|0x8800 },
470 primary_key_info=> { U =>[4,5,'$catalog, $schema, $table [, \%attr ]' ], O=>0x2200|0x8800 },
471 primary_key => { U =>[4,5,'$catalog, $schema, $table [, \%attr ]' ], O=>0x2200 },
472 foreign_key_info=> { U =>[7,8,'$pk_catalog, $pk_schema, $pk_table, $fk_catalog, $fk_schema, $fk_table [, \%attr ]' ], O=>0x2200|0x8800 },
473 statistics_info => { U =>[6,7,'$catalog, $schema, $table, $unique_only, $quick, [, \%attr ]' ], O=>0x2200|0x8800 },
474 type_info_all => { U =>[1,1], O=>0x2200|0x0800 },
475 type_info => { U =>[1,2,'$data_type'], O=>0x2200 },
476 get_info => { U =>[2,2,'$info_type'], O=>0x2200|0x0800 },
477 },
478 st => { # Statement Class Interface
479 bind_col => { U =>[3,4,'$column, \\$var [, \%attr]'] },
480 bind_columns => { U =>[2,0,'\\$var1 [, \\$var2, ...]'] },
481 bind_param => { U =>[3,4,'$parameter, $var [, \%attr]'] },
482 bind_param_inout=> { U =>[4,5,'$parameter, \\$var, $maxlen, [, \%attr]'] },
483 execute => { U =>[1,0,'[@args]'], O=>0x1040 },
484 last_insert_id => { U =>[1,6,'[$catalog [,$schema [,$table_name [,$field_name [, \%attr ]]]]]'], O=>0x2800 },
485  
486 bind_param_array => { U =>[3,4,'$parameter, $var [, \%attr]'] },
487 bind_param_inout_array => { U =>[4,5,'$parameter, \\@var, $maxlen, [, \%attr]'] },
488 execute_array => { U =>[2,0,'\\%attribs [, @args]'], O=>0x1040|0x4000 },
489 execute_for_fetch => { U =>[2,3,'$fetch_sub [, $tuple_status]'], O=>0x1040|0x4000 },
490  
491 fetch => undef, # alias for fetchrow_arrayref
492 fetchrow_arrayref => undef,
493 fetchrow_hashref => undef,
494 fetchrow_array => undef,
495 fetchrow => undef, # old alias for fetchrow_array
496  
497 fetchall_arrayref => { U =>[1,3, '[ $slice [, $max_rows]]'] },
498 fetchall_hashref => { U =>[2,2,'$key_field'] },
499  
500 blob_read => { U =>[4,5,'$field, $offset, $len [, \\$buf [, $bufoffset]]'] },
501 blob_copy_to_file => { U =>[3,3,'$field, $filename_or_handleref'] },
502 dump_results => { U =>[1,5,'$maxfieldlen, $linesep, $fieldsep, $filehandle'] },
503 more_results => { U =>[1,1] },
504 finish => { U =>[1,1] },
505 cancel => { U =>[1,1], O=>0x0800 },
506 rows => $keeperr,
507  
508 _get_fbav => undef,
509 _set_fbav => { T=>6 },
510 },
511 );
512  
513 214 ▶while ( my ($class, $meths) = each %DBI::DBI_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %DBI::DBI_methods) 856 214 1070
514 856 ▶ my $ima_trace = 0+($ENV{DBI_IMA_TRACE}||0);
Condition50%1/2
$ENV{'DBI_IMA_TRACE'} || 0
l!l
0856
MC/DC0%0/1
$ENV{'DBI_IMA_TRACE'} || 0
$ENV{'DBI_IMA_TRACE'}
Truth table50%1/2
A
A= $ENV{'DBI_IMA_TRACE'}
Aresult
11
00
515 856 ▶ while ( my ($method, $info) = each %$meths ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$meths) 19474 856 20330
516 19474 my $fullmeth = "DBI::${class}::$method";
517 19474 ▶ if (($DBI::dbi_debug & 0xF) == 15) { # quick hack to list DBI methods
Branch: 1 branch
BranchTrueFalseTotal
if (($DBI::dbi_debug & 15) == 15) 0 19474 19474
518 # and optionally filter by IMA flags
519 0 ▶ my $O = $info->{O}||0;
Condition0%0/2
$info->{'O'} || 0
l!l
00
MC/DC0%0/1
$info->{'O'} || 0
$info->{'O'}
Truth table0%0/2
A
A= $info->{'O'}
Aresult
11
00
520 0 ▶ printf "0x%04x %-20s\n", $O, $fullmeth
Branch: 1 branch
BranchTrueFalseTotal
unless $ima_trace and not $O & $ima_trace 0 0 0
Condition0%0/3
$ima_trace and not $O & $ima_trace
!ll&&!rl&&r
000
MC/DC0%0/2
$ima_trace and not $O & $ima_trace
$ima_trace not $O & $ima_trace
Truth table0%0/3
A and not(B)
A= $ima_traceB= not $O & $ima_trace
ABresult
0X0
100
111
521 unless $ima_trace && !($O & $ima_trace);
522 }
523 19474 DBI->_install_method($fullmeth, 'DBI.pm', $info);
524 }
525 }
526  
527 {
528 214 package DBI::common;
529 214 @DBI::dr::ISA = ('DBI::common');
530 214 @DBI::db::ISA = ('DBI::common');
531 214 @DBI::st::ISA = ('DBI::common');
532 }
533  
534 # End of init code
535  
536 214 ▶END {
Subroutine END: called CC=5 SCAR=23.8
537 0 ▶ return unless defined &DBI::trace_msg; # return unless bootstrap'd ok
Subroutine END: not called CC=5 SCAR=23.8
Branch: 2 branches
BranchTrueFalseTotal
unless defined &DBI::trace_msg 0 214 214
unless defined &DBI::trace_msg 0 0 0
538 0 local ($!,$?);
539 0 ▶ DBI->trace_msg(sprintf(" -- DBI::END (\$\@: %s, \$!: %s)\n", $@||'', $!||''), 2);
Condition25%2/8
$@ || ''
l!l
0214
$! || ''
l!l
0214
$@ || ''
l!l
00
$! || ''
l!l
00
MC/DC0%0/1
$@ || ''
$@
MC/DC0%0/1
$! || ''
$!
MC/DC0%0/1
$@ || ''
$@
MC/DC0%0/1
$! || ''
$!
Truth table50%1/2
A
A= $@
Aresult
11
00
Truth table50%1/2
A
A= $!
Aresult
11
00
Truth table0%0/2
A
A= $@
Aresult
11
00
Truth table0%0/2
A
A= $!
Aresult
11
00
540 # Let drivers know why we are calling disconnect_all:
541 0 $DBI::PERL_ENDING = $DBI::PERL_ENDING = 1; # avoid typo warning
542 0 ▶ DBI->disconnect_all() if %DBI::installed_drh;
Branch: 2 branches
BranchTrueFalseTotal
if %DBI::installed_drh 158 56 214
if %DBI::installed_drh 0 0 0
543 }
544  
545  
546 0 ▶sub CLONE {
Subroutine CLONE: not called CC=4 SCAR=25.3
547 0 ▶ _clone_dbis() unless $DBI::PurePerl; # clone the DBIS structure
Branch: 1 branch
BranchTrueFalseTotal
unless $DBI::PurePerl 0 0 0
548 0 DBI->trace_msg("CLONE DBI for new thread\n");
549 0 ▶ while ( my ($driver, $drh) = each %DBI::installed_drh) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %DBI::installed_drh) 0 0 0
550 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
551 0 ▶ next if defined &{"DBD::${driver}::CLONE"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"DBD::${driver}::CLONE";} 0 0 0
552 0 warn("$driver has no driver CLONE() function so is unsafe threaded\n");
553 }
554 0 %DBI::installed_drh = (); # clear loaded drivers so they have a chance to reinitialize
555 }
556  
557 2 ▶sub parse_dsn {
Subroutine parse_dsn: called CC=5 SCAR=18.9
Pod documented
558 2 my ($class, $dsn) = @_;
559 2 ▶ $dsn =~ s/^(dbi):(\w*?)(?:\((.*?)\))?://i or return;
Branch: 1 branch
BranchTrueFalseTotal
$dsn =~ s/^(dbi):(\w*?)(?:\((.*?)\))?://i or return 2 0 2
560 2 my ($scheme, $driver, $attr, $attr_hash) = (lc($1), $2, $3);
561 2 ▶ $driver ||= $ENV{DBI_DRIVER} || '';
Condition20%1/5
$driver ||= $ENV{"DBI_DRIVER"} || ""
l!l&&r!l&&!r
200
$ENV{'DBI_DRIVER'} || ''
l!l
00
MC/DC0%0/2
$driver ||= $ENV{"DBI_DRIVER"} || ""
$driver $ENV{'DBI_DRIVER'}
Truth table33%1/3
A ||= B
A= $driverB= $ENV{'DBI_DRIVER'}
ABresult
1X1
011
000
562 2 ▶ $attr_hash = { split /\s*=>?\s*|\s*,\s*/, $attr, -1 } if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 0 2 2
563 2 return ($scheme, $driver, $attr, $attr_hash, $dsn);
564 }
565  
566 8 ▶sub visit_handles {
Subroutine visit_handles: called CC=4 SCAR=14.1
Pod documented
567 8 my ($class, $code, $outer_info) = @_;
568 8 ▶ $outer_info = {} if not defined $outer_info;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $outer_info 0 8 8
569 8 my %drh = DBI->installed_drivers;
570 8 for my $h (values %drh) {
571 12 ▶ my $child_info = $code->($h, $outer_info)
Branch: 1 branch
BranchTrueFalseTotal
my $child_info = &$code($h, $outer_info) or next 12 0 12
572 or next;
573 12 $h->visit_child_handles($code, $child_info);
574 }
575 8 return $outer_info;
576 }
577  
578  
579 # --- The DBI->connect Front Door methods
580  
581 3146 ▶sub connect_cached {
Subroutine connect_cached: called CC=3 SCAR=11.4
Pod documented
582 # For library code using connect_cached() with mod_perl
583 # we redirect those calls to Apache::DBI::connect() as well
584 3146 my ($class, $dsn, $user, $pass, $attr) = @_;
585 3146 ▶ my $dbi_connect_method = ($DBI::connect_via eq "Apache::DBI::connect")
Branch: 1 branch
BranchTrueFalseTotal
$DBI::connect_via eq 'Apache::DBI::connect' ? : 0 3146 3146
586 ? 'Apache::DBI::connect' : 'connect_cached';
587 3146 ▶ $attr = {
Branch: 1 branch
BranchTrueFalseTotal
$attr ? : 3146 0 3146
588 $attr ? %$attr : (), # clone, don't modify callers data
589 dbi_connect_method => $dbi_connect_method,
590 };
591 3146 return $class->connect($dsn, $user, $pass, $attr);
592 }
593  
594 7153 ▶sub connect {
Subroutine connect: called CC=39 SCAR=40.7
Pod documented
595 7153 my $class = shift;
596 7153 my ($dsn, $user, $pass, $attr, $old_driver) = my @orig_args = @_;
597 7153 my $driver;
598  
599 7153 ▶ if ($attr and !ref($attr)) { # switch $old_driver<->$attr if called in old style
Branch: 1 branch
BranchTrueFalseTotal
if ($attr and not ref $attr) 0 7153 7153
Condition66%2/3
$attr and not ref $attr
!ll&&!rl&&r
12070330
MC/DC0%0/2
$attr and not ref $attr
$attr not ref $attr
Truth table66%2/3
A and not(B)
A= $attrB= not ref $attr
ABresult
0X0
100
111
600 0 Carp::carp("DBI->connect using 'old-style' syntax is deprecated and will be an error in future versions");
601 0 ($old_driver, $attr) = ($attr, $old_driver);
602 }
603  
604 7153 my $connect_meth = $attr->{dbi_connect_method};
605 7153 ▶ $connect_meth ||= $DBI::connect_via; # fallback to default
Condition66%2/3
$connect_meth ||= $DBI::connect_via
l!l&&r!l&&!r
314640070
MC/DC0%0/2
$connect_meth ||= $DBI::connect_via
$connect_meth $DBI::connect_via
Truth table66%2/3
A ||= B
A= $connect_methB= $DBI::connect_via
ABresult
1X1
011
000
606  
607 7153 ▶ $dsn ||= $ENV{DBI_DSN} || $ENV{DBI_DBNAME} || '' unless $old_driver;
Branch: 1 branch
BranchTrueFalseTotal
unless $old_driver 7153 0 7153
Condition12%1/8
$dsn ||= $ENV{"DBI_DSN"} || $ENV{"DBI_DBNAME"} || ""
l!l&&r!l&&!r
715300
$ENV{'DBI_DSN'} || $ENV{'DBI_DBNAME'} || ''
l!l
00
$ENV{"DBI_DSN"} or $ENV{"DBI_DBNAME"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$dsn ||= $ENV{"DBI_DSN"} || $ENV{"DBI_DBNAME"} || ""
$dsn $ENV{"DBI_DSN"} $ENV{"DBI_DBNAME"}
Truth table0%0/4
A ||= B or C
A= $dsnB= $ENV{"DBI_DSN"}C= $ENV{"DBI_DBNAME"}
ABCresult
1XX1
01X1
0011
0000
608  
609 7153 ▶ if ($DBI::dbi_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::dbi_debug) 29 7124 7153
610 214 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
611 29 ▶ pop @_ if $connect_meth ne 'connect';
Branch: 1 branch
BranchTrueFalseTotal
if $connect_meth ne "connect" 0 29 29
612 29 my @args = @_; $args[2] = '****'; # hide password
613 29 DBI->trace_msg(" -> $class->$connect_meth(".join(", ",@args).")\n");
614 }
615 7153 ▶ Carp::croak('Usage: $class->connect([$dsn [,$user [,$passwd [,\%attr]]]])')
Branch: 1 branch
BranchTrueFalseTotal
if ref $old_driver or $attr and not ref $attr or ref $pass and not defined builtin::blessed($pass) 4 7149 7153
Condition58%7/12
ref $old_driver or $attr and not ref $attr or ref $pass and not defined builtin::blessed($pass)
l!l&&r!l&&!r
047149
ref $old_driver or $attr and not ref $attr
l!l&&r!l&&!r
007153
$attr and not ref $attr
!ll&&!rl&&r
071530
ref $pass and not defined builtin::blessed($pass)
!ll&&!rl&&r
714544
MC/DC40%2/5
ref $old_driver or $attr and not ref $attr or ref $pass and not defined builtin::blessed($pass)
ref $old_driver $attr not ref $attr ref $pass not defined builtin::blessed($pass)
Truth table37%3/8
A or B and not(C) or D and not(E)
A= ref $old_driverB= $attrC= not ref $attrD= ref $passE= not defined builtin::blessed($pass)
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
616 if (ref $old_driver or ($attr and not ref $attr) or
617 (ref $pass and not defined Scalar::Util::blessed($pass)));
618  
619 # extract dbi:driver prefix from $dsn into $1
620 7149 my $orig_dsn = $dsn;
621 7149 ▶ $dsn =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i
Branch: 1 branch
BranchTrueFalseTotal
$dsn =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i or "" =~ /()/ 7149 0 7149
622 or '' =~ /()/; # ensure $1 etc are empty if match fails
623 7149 ▶ my $driver_attrib_spec = $2 || '';
Condition100%2/2
$2 || ''
l!l
167133
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
624  
625 # Set $driver. Old style driver, if specified, overrides new dsn style.
626 $driver = $old_driver || $1 || $ENV{DBI_DRIVER}
627 7149 ▶ or Carp::croak("Can't connect to data source '$orig_dsn' "
Branch: 1 branch
BranchTrueFalseTotal
$driver = $old_driver || $1 || $ENV{"DBI_DRIVER"} or Carp::croak("Can't connect to data source '${orig_dsn}' " . q[because I can't work out what driver to use ] . "(it doesn't seem to contain a 'dbi:driver:' prefix " . 'and the DBI_DRIVER env var is not set)') 7149 0 7149
Condition33%2/6
$old_driver || $1 || $ENV{'DBI_DRIVER'}
l!l&&r!l&&!r
714900
$old_driver or $1
l!l&&r!l&&!r
071490
MC/DC0%0/3
$old_driver || $1 || $ENV{'DBI_DRIVER'}
$old_driver $1 $ENV{'DBI_DRIVER'}
Truth table25%1/4
A or B || C
A= $old_driverB= $1C= $ENV{'DBI_DRIVER'}
ABCresult
1XX1
01X1
0011
0000
628 ."because I can't work out what driver to use "
629 ."(it doesn't seem to contain a 'dbi:driver:' prefix "
630 ."and the DBI_DRIVER env var is not set)");
631  
632 7149 my $proxy;
633 7149 ▶ if ($ENV{DBI_AUTOPROXY} && $driver ne 'Proxy' && $driver ne 'Sponge' && $driver ne 'Switch') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DBI_AUTOPROXY"} and $driver ne "Proxy" and $driver ne "Sponge" and $driver ne "Switch") 225 6924 7149
Condition77%7/9
$ENV{"DBI_AUTOPROXY"} and $driver ne "Proxy" and $driver ne "Sponge" and $driver ne "Switch"
!ll&&!rl&&r
69240225
$ENV{"DBI_AUTOPROXY"} and $driver ne "Proxy" and $driver ne "Sponge"
!ll&&!rl&&r
688539225
$ENV{"DBI_AUTOPROXY"} and $driver ne "Proxy"
!ll&&!rl&&r
68850264
MC/DC50%2/4
$ENV{"DBI_AUTOPROXY"} and $driver ne "Proxy" and $driver ne "Sponge" and $driver ne "Switch"
$ENV{"DBI_AUTOPROXY"} $driver ne "Proxy" $driver ne "Sponge" $driver ne "Switch"
Truth table60%3/5
A and B and C and D
A= $ENV{"DBI_AUTOPROXY"}B= $driver ne "Proxy"C= $driver ne "Sponge"D= $driver ne "Switch"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
634 225 my $dbi_autoproxy = $ENV{DBI_AUTOPROXY};
635 225 $proxy = 'Proxy';
636 225 ▶ if ($dbi_autoproxy =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_autoproxy =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i) 225 0 225
637 225 $proxy = $1;
638 225 ▶ $driver_attrib_spec = join ",",
Branch: 2 branches
BranchTrueFalseTotal
$driver_attrib_spec ? : 6 219 225
$2 ? : 0 225 225
639 ($driver_attrib_spec) ? $driver_attrib_spec : (),
640 ($2 ) ? $2 : ();
641 }
642 225 $dsn = "$dbi_autoproxy;dsn=dbi:$driver:$dsn";
643 225 $driver = $proxy;
644 225 DBI->trace_msg(" DBI_AUTOPROXY: dbi:$driver($driver_attrib_spec):$dsn\n");
645 }
646 # avoid recursion if proxy calls DBI->connect itself
647 7149 ▶ local $ENV{DBI_AUTOPROXY} if $ENV{DBI_AUTOPROXY};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DBI_AUTOPROXY"} 264 6885 7149
648  
649 7149 my %attributes; # take a copy we can delete from
650 7149 ▶ if ($old_driver) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_driver) { } 0 7149 7149
651 0 ▶ %attributes = %$attr if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 0 0 0
652 }
653 else { # new-style connect so new default semantics
654 7149 ▶ %attributes = (
Branch: 2 branches
BranchTrueFalseTotal
ref $attr ? : 7149 0 7149
$driver_attrib_spec ? : 16 7133 7149
655 PrintError => 1,
656 AutoCommit => 1,
657 ref $attr ? %$attr : (),
658 # attributes in DSN take precedence over \%attr connect parameter
659 $driver_attrib_spec ? (split /\s*=>?\s*|\s*,\s*/, $driver_attrib_spec, -1) : (),
660 );
661 }
662 7149 $attr = \%attributes; # now set $attr to refer to our local copy
663  
664 7149 ▶ my $drh = $DBI::installed_drh{$driver} || $class->install_driver($driver)
Branch: 1 branch
BranchTrueFalseTotal
my $drh = $DBI::installed_drh{$driver} || $class->install_driver($driver) or die "panic: $class->install_driver($driver) failed" 7143 0 7143
Condition66%2/3
$DBI::installed_drh{$driver} || $class->install_driver($driver)
l!l&&r!l&&!r
69042450
MC/DC0%0/2
$DBI::installed_drh{$driver} || $class->install_driver($driver)
$DBI::installed_drh{$driver} $class->install_driver($driver)
Truth table66%2/3
A || B
A= $DBI::installed_drh{$driver}B= $class->install_driver($driver)
ABresult
1X1
011
000
665 or die "panic: $class->install_driver($driver) failed";
666  
667 # attributes in DSN take precedence over \%attr connect parameter
668 7143 ▶ $user = $attr->{Username} if defined $attr->{Username};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr->{"Username"} 5151 1992 7143
669 7143 ▶ $pass = $attr->{Password} if defined $attr->{Password};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr->{"Password"} 5151 1992 7143
670 7143 delete $attr->{Password}; # always delete Password as closure stores it securely
671 7143 ▶ if ( !(defined $user && defined $pass) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user and defined $pass) 1758 5385 7143
Condition66%2/3
defined $user and defined $pass
!ll&&!rl&&r
175805385
MC/DC50%1/2
defined $user and defined $pass
defined $user defined $pass
Truth table66%2/3
A and B
A= defined $userB= defined $pass
ABresult
0X0
100
111
672 1758 ($user, $pass) = $drh->default_user($user, $pass, $attr);
673 }
674 7143 $attr->{Username} = $user; # force the Username to be the actual one used
675  
676 7159 ▶ my $connect_closure = sub {
Subroutine __ANON__: called CC=24 SCAR=33.3
677 7159 my ($old_dbh, $override_attr) = @_;
678  
679 #use Data::Dumper;
680 #warn "connect_closure: ".Data::Dumper::Dumper([$attr,\%attributes, $override_attr]);
681  
682 7159 my $dbh;
683 7159 ▶ unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $attr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $attr)) 90 7061 7151
684 90 ▶ $user //= '';
Condition100%2/2
$user //= ""
l!l
288
MC/DC100%1/1
$user //= ""
$user
Truth table100%2/2
A
A= $user
Aresult
11
00
685 90 ▶ $dsn //= '';
Condition50%1/2
$dsn //= ""
l!l
900
MC/DC0%0/1
$dsn //= ""
$dsn
Truth table50%1/2
A
A= $dsn
Aresult
11
00
686 # $drh->errstr isn't safe here because $dbh->DESTROY may not have
687 # been called yet and so the dbh errstr would not have been copied
688 # up to the drh errstr. Certainly true for connect_cached!
689 90 my $errstr = $DBI::errstr;
690 # Getting '(no error string)' here is a symptom of a ref loop
691 90 ▶ $errstr //= '(no error string)';
Condition50%1/2
$errstr //= "(no error string)"
l!l
900
MC/DC0%0/1
$errstr //= "(no error string)"
$errstr
Truth table50%1/2
A
A= $errstr
Aresult
11
00
692 90 my $msg = "$class connect('$dsn','$user',...) failed: $errstr";
693 90 DBI->trace_msg(" $msg\n");
694 # XXX HandleWarn
695 90 ▶ unless ($attr->{HandleError} && $attr->{HandleError}->($msg, $drh, $dbh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr->{"HandleError"} and $attr->{"HandleError"}->($msg, $drh, $dbh)) 90 0 90
Condition33%1/3
$attr->{"HandleError"} and $attr->{"HandleError"}->($msg, $drh, $dbh)
!ll&&!rl&&r
9000
MC/DC0%0/2
$attr->{"HandleError"} and $attr->{"HandleError"}->($msg, $drh, $dbh)
$attr->{"HandleError"} $attr->{"HandleError"}->($msg, $drh, $dbh)
Truth table33%1/3
A and B
A= $attr->{"HandleError"}B= $attr->{"HandleError"}->($msg, $drh, $dbh)
ABresult
0X0
100
111
696 90 ▶ Carp::croak($msg) if $attr->{RaiseError};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"RaiseError"} 62 28 90
697 28 ▶ Carp::carp ($msg) if $attr->{PrintError};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"PrintError"} 4 24 28
698 }
699 28 $! = 0; # for the daft people who do DBI->connect(...) || die "$!";
700 28 return $dbh; # normally undef, but HandleError could change it
701 }
702  
703 # merge any attribute overrides but don't change $attr itself (for closure)
704 7061 ▶ my $apply = { ($override_attr) ? (%$attr, %$override_attr ) : %$attr };
Branch: 1 branch
BranchTrueFalseTotal
$override_attr ? : 16 7045 7061
705  
706 # handle basic RootClass subclassing:
707 7061 ▶ my $rebless_class = $apply->{RootClass} || ($class ne 'DBI' ? $class : '');
Branch: 1 branch
BranchTrueFalseTotal
$class ne 'DBI' ? : 8 7029 7037
Condition100%3/3
$apply->{'RootClass'} || ($class ne 'DBI' ? $class : '')
l!l&&r!l&&!r
2487029
MC/DC100%2/2
$apply->{'RootClass'} || ($class ne 'DBI' ? $class : '')
$apply->{'RootClass'} ($class ne 'DBI' ? $class : '')
Truth table100%3/3
A || B
A= $apply->{'RootClass'}B= ($class ne 'DBI' ? $class : '')
ABresult
1X1
011
000
708 7061 ▶ if ($rebless_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rebless_class) 32 7029 7061
709 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
710 32 ▶ if ($apply->{RootClass}) { # explicit attribute (ie not static method call class)
Branch: 1 branch
BranchTrueFalseTotal
if ($apply->{"RootClass"}) 24 8 32
711 24 delete $apply->{RootClass};
712 24 DBI::_load_class($rebless_class, 0);
713 }
714 28 ▶ unless (@{"$rebless_class\::db::ISA"} && @{"$rebless_class\::st::ISA"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{"${rebless_class}::db::ISA";} and @{"${rebless_class}::st::ISA";}) { } 28 0 28
Condition33%1/3
@{"${rebless_class}::db::ISA";} and @{"${rebless_class}::st::ISA";}
!ll&&!rl&&r
0028
MC/DC0%0/2
@{"${rebless_class}::db::ISA";} and @{"${rebless_class}::st::ISA";}
@{"${rebless_class}::db::ISA";} @{"${rebless_class}::st::ISA";}
Truth table33%1/3
A and B
A= @{"${rebless_class}::db::ISA";}B= @{"${rebless_class}::st::ISA";}
ABresult
0X0
100
111
715 0 Carp::carp("DBI subclasses '$rebless_class\::db' and ::st are not setup, RootClass ignored");
716 0 $rebless_class = undef;
717 0 $class = 'DBI';
718 }
719 else {
720 28 $dbh->{RootClass} = $rebless_class; # $dbh->STORE called via plain DBI::db
721 28 DBI::_set_isa([$rebless_class], 'DBI'); # sets up both '::db' and '::st'
722 28 DBI::_rebless($dbh, $rebless_class); # appends '::db'
723 }
724 }
725  
726 7057 ▶ if (%$apply) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$apply) 6375 682 7057
727  
728 6375 ▶ if ($apply->{DbTypeSubclass}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apply->{"DbTypeSubclass"}) 0 6375 6375
729 0 my $DbTypeSubclass = delete $apply->{DbTypeSubclass};
730 0 ▶ DBI::_rebless_dbtype_subclass($dbh, $rebless_class||$class, $DbTypeSubclass);
Condition0%0/3
$rebless_class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$rebless_class || $class
$rebless_class $class
Truth table0%0/3
A || B
A= $rebless_classB= $class
ABresult
1X1
011
000
731 }
732 6375 my $a;
733 6375 foreach $a (qw(Profile RaiseError PrintError AutoCommit)) { # do these first
734 25494 ▶ next unless exists $apply->{$a};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $apply->{$a} 6484 19010 25494
735 19010 $dbh->{$a} = delete $apply->{$a};
736 }
737 6373 ▶ while ( my ($a, $v) = each %$apply) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$apply) 28685 6373 35058
738 28685 eval { $dbh->{$a} = $v }; # assign in void context to avoid re-FETCH
739 28685 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28685 28685
740 }
741 }
742  
743 # confirm to driver (ie if subclassed) that we've connected successfully
744 # and finished the attribute setup. pass in the original arguments
745 7055 $dbh->connected(@orig_args); #if ref $dbh ne 'DBI::db' or $proxy;
746  
747 7055 ▶ DBI->trace_msg(" <- connect= $dbh\n") if $DBI::dbi_debug & 0xF;
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::dbi_debug & 15 10 7045 7055
748  
749 7055 return $dbh;
750 7143 };
751  
752 7143 my $dbh = &$connect_closure(undef, undef);
753  
754 7067 ▶ $dbh->{dbi_connect_closure} = $connect_closure if $dbh;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh 7039 28 7067
755  
756 7067 return $dbh;
757 }
758  
759  
760 158 ▶sub disconnect_all {
Subroutine disconnect_all: called CC=3 SCAR=11.1
Pod documented
761 158 keys %DBI::installed_drh; # reset iterator
762 158 ▶ while ( my ($name, $drh) = each %DBI::installed_drh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %DBI::installed_drh) 263 158 421
763 263 ▶ $drh->disconnect_all() if ref $drh;
Branch: 1 branch
BranchTrueFalseTotal
if ref $drh 263 0 263
764 }
765 }
766  
767  
768 0 ▶sub disconnect { # a regular beginners bug
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod documented
769 0 Carp::croak("DBI->disconnect is not a DBI method (read the DBI manual)");
770 }
771  
772  
773 277 ▶sub install_driver { # croaks on failure
Subroutine install_driver: called CC=22 SCAR=34.1
Pod documented
774 277 my $class = shift;
775 277 my($driver, $attr) = @_;
776 277 my $drh;
777  
778 277 ▶ $driver ||= $ENV{DBI_DRIVER} || '';
Condition20%1/5
$driver ||= $ENV{"DBI_DRIVER"} || ""
l!l&&r!l&&!r
27700
$ENV{'DBI_DRIVER'} || ''
l!l
00
MC/DC0%0/2
$driver ||= $ENV{"DBI_DRIVER"} || ""
$driver $ENV{'DBI_DRIVER'}
Truth table33%1/3
A ||= B
A= $driverB= $ENV{'DBI_DRIVER'}
ABresult
1X1
011
000
779  
780 # allow driver to be specified as a 'dbi:driver:' string
781 277 ▶ $driver = $1 if $driver =~ s/^DBI:(.*?)://i;
Branch: 1 branch
BranchTrueFalseTotal
if $driver =~ s/^DBI:(.*?)://i 8 269 277
782  
783 277 ▶ Carp::croak("usage: $class->install_driver(\$driver [, \%attr])")
Branch: 1 branch
BranchTrueFalseTotal
unless $driver and @_ <= 3 0 277 277
Condition33%1/3
$driver and @_ <= 3
!ll&&!rl&&r
00277
MC/DC0%0/2
$driver and @_ <= 3
$driver @_ <= 3
Truth table33%1/3
A and B
A= $driverB= @_ <= 3
ABresult
0X0
100
111
784 unless ($driver and @_<=3);
785  
786 # already installed
787 277 ▶ return $drh if $drh = $DBI::installed_drh{$driver};
Branch: 1 branch
BranchTrueFalseTotal
if $drh = $DBI::installed_drh{$driver} 8 269 277
788  
789 269 ▶ $class->trace_msg(" -> $class->install_driver($driver"
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::dbi_debug & 15 6 263 269
790 .") for $^O perl=$] pid=$$ ruid=$< euid=$>\n")
791 if $DBI::dbi_debug & 0xF;
792  
793 # --- load the code
794 269 my $driver_class = "DBD::$driver";
795 269 eval qq{package # hide from PAUSE
796 DBI::_firesafe; # just in case
797 require $driver_class; # load the driver
798 };
799 269 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 265 269
800 4 my $err = $@;
801 4 my $advice = "";
802 4 ▶ if ($err =~ /Can't find loadable object/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($err =~ /Can't find loadable object/) { } 0 4 4
elsif ($err =~ m[Can't locate.*?DBD/$driver\.pm in \@INC]) { } 4 0 4
elsif ($err =~ /Can't load .*? for module DBD::/) { } 0 0 0
elsif ($err =~ /Can't locate .*? in \@INC/) { } 0 0 0
803 0 $advice = "Perhaps DBD::$driver was statically linked into a new perl binary."
804 ."\nIn which case you need to use that new perl binary."
805 ."\nOr perhaps only the .pm file was installed but not the shared object file."
806 }
807 elsif ($err =~ /Can't locate.*?DBD\/$driver\.pm in \@INC/) {
808 4 my @drv = $class->available_drivers(1);
809 4 $advice = "Perhaps the DBD::$driver perl module hasn't been fully installed,\n"
810 ."or perhaps the capitalisation of '$driver' isn't right.\n"
811 ."Available drivers: ".join(", ", @drv).".";
812 }
813 elsif ($err =~ /Can't load .*? for module DBD::/) {
814 0 $advice = "Perhaps a required shared library or dll isn't installed where expected";
815 }
816 elsif ($err =~ /Can't locate .*? in \@INC/) {
817 0 $advice = "Perhaps a module that DBD::$driver requires hasn't been fully installed";
818 }
819 4 Carp::croak("install_driver($driver) failed: $err$advice\n");
820 }
821 265 ▶ if ($DBI::dbi_debug & 0xF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::dbi_debug & 15) 6 259 265
822 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
823 6 (my $driver_file = $driver_class) =~ s/::/\//g;
824 6 ▶ my $dbd_ver = ${"$driver_class\::VERSION"} || "undef";
Condition50%1/2
${"${driver_class}::VERSION";} || 'undef'
l!l
60
MC/DC0%0/1
${"${driver_class}::VERSION";} || 'undef'
${"${driver_class}::VERSION";}
Truth table50%1/2
A
A= ${"${driver_class}::VERSION";}
Aresult
11
00
825 6 $class->trace_msg(" install_driver: $driver_class version $dbd_ver"
826 ." loaded from $INC{qq($driver_file.pm)}\n");
827 }
828  
829 # --- do some behind-the-scenes checks and setups on the driver
830 265 $class->setup_driver($driver_class);
831  
832 # --- run the driver function
833 265 ▶ $drh = eval { $driver_class->driver($attr || {}) };
Condition50%1/2
$attr || {}
l!l
0265
MC/DC0%0/1
$attr || {}
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
834 265 ▶ unless ($drh && ref $drh && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($drh and ref $drh and not $@) 2 263 265
Condition66%4/6
$drh and ref $drh and not $@
!ll&&!rl&&r
20263
$drh and ref $drh
!ll&&!rl&&r
20263
MC/DC33%1/3
$drh and ref $drh and not $@
$drh ref $drh not $@
Truth table50%2/4
A and B and not(C)
A= $drhB= ref $drhC= not $@
ABCresult
0XX0
10X0
1100
1111
835 2 my $advice = "";
836 2 ▶ $@ ||= "$driver_class->driver didn't return a handle";
Condition50%1/2
$@ ||= "$driver_class->driver didn't return a handle"
l!l
20
MC/DC0%0/1
$@ ||= "$driver_class->driver didn't return a handle"
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
837 # catch people on case in-sensitive systems using the wrong case
838 2 ▶ $advice = "\nPerhaps the capitalisation of DBD '$driver' isn't right."
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /locate object method/ 2 0 2
839 if $@ =~ /locate object method/;
840 2 Carp::croak("$driver_class initialisation failed: $@$advice");
841 }
842  
843 263 $DBI::installed_drh{$driver} = $drh;
844 263 ▶ $class->trace_msg(" <- install_driver= $drh\n") if $DBI::dbi_debug & 0xF;
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::dbi_debug & 15 6 257 263
845 263 $drh;
846 }
847  
848 214 *driver = \&install_driver; # currently an alias, may change
849  
850  
851 604 ▶sub setup_driver {
Subroutine setup_driver: called CC=5 SCAR=16.1
Pod documented
852 604 my ($class, $driver_class) = @_;
853 604 my $h_type;
854 604 foreach $h_type (qw(dr db st)){
855 1812 my $h_class = $driver_class."::$h_type";
856 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
857 1812 ▶ push @{"${h_class}::ISA"}, "DBD::_::$h_type"
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($h_class, "DBD::_::$h_type") 1455 357 1812
858 unless UNIVERSAL::isa($h_class, "DBD::_::$h_type");
859 # The _mem class stuff is (IIRC) a crufty hack for global destruction
860 # timing issues in early versions of perl5 and possibly no longer needed.
861 1812 my $mem_class = "DBD::_mem::$h_type";
862 1812 ▶ push @{"${h_class}_mem::ISA"}, $mem_class
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa("${h_class}_mem", $mem_class) or $DBI::PurePerl 855 957 1812
Condition100%3/3
UNIVERSAL::isa("${h_class}_mem", $mem_class) or $DBI::PurePerl
l!l&&r!l&&!r
114843855
MC/DC100%2/2
UNIVERSAL::isa("${h_class}_mem", $mem_class) or $DBI::PurePerl
UNIVERSAL::isa("${h_class}_mem", $mem_class) $DBI::PurePerl
Truth table100%3/3
A or B
A= UNIVERSAL::isa("${h_class}_mem", $mem_class)B= $DBI::PurePerl
ABresult
1X1
011
000
863 unless UNIVERSAL::isa("${h_class}_mem", $mem_class)
864 or $DBI::PurePerl;
865 }
866 }
867  
868  
869 28 ▶sub _rebless {
Subroutine _rebless: called CC=1 SCAR=0.0
870 28 my $dbh = shift;
871 28 my ($outer, $inner) = DBI::_handles($dbh);
872 28 my $class = shift(@_).'::db';
873 28 bless $inner => $class;
874 28 bless $outer => $class; # outer last for return
875 }
876  
877  
878 28 ▶sub _set_isa {
Subroutine _set_isa: called CC=8 SCAR=23.7
879 28 my ($classes, $topclass) = @_;
880 28 my $trace = DBI->trace_msg(" _set_isa([@$classes])\n");
881 28 foreach my $suffix ('::db','::st') {
882 56 ▶ my $previous = $topclass || 'DBI'; # trees are rooted here
Condition50%1/2
$topclass || 'DBI'
l!l
560
MC/DC0%0/1
$topclass || 'DBI'
$topclass
Truth table50%1/2
A
A= $topclass
Aresult
11
00
883 56 foreach my $class (@$classes) {
884 56 my $base_class = $previous.$suffix;
885 56 my $sub_class = $class.$suffix;
886 56 my $sub_class_isa = "${sub_class}::ISA";
887 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
888 56 ▶ if (@$sub_class_isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$sub_class_isa) { } 56 0 56
889 56 ▶ DBI->trace_msg(" $sub_class_isa skipped (already set to @$sub_class_isa)\n")
Branch: 1 branch
BranchTrueFalseTotal
if $trace 0 56 56
890 if $trace;
891 }
892 else {
893 0 ▶ @$sub_class_isa = ($base_class) unless @$sub_class_isa;
Branch: 1 branch
BranchTrueFalseTotal
unless @$sub_class_isa 0 0 0
894 0 ▶ DBI->trace_msg(" $sub_class_isa = $base_class\n")
Branch: 1 branch
BranchTrueFalseTotal
if $trace 0 0 0
895 if $trace;
896 }
897 56 $previous = $class;
898 }
899 }
900 }
901  
902  
903 0 ▶sub _rebless_dbtype_subclass {
Subroutine _rebless_dbtype_subclass: not called CC=3 SCAR=24.8
904 0 my ($dbh, $rootclass, $DbTypeSubclass) = @_;
905 # determine the db type names for class hierarchy
906 0 my @hierarchy = DBI::_dbtype_names($dbh, $DbTypeSubclass);
907 # add the rootclass prefix to each ('DBI::' or 'MyDBI::' etc)
908 0 $_ = $rootclass.'::'.$_ foreach (@hierarchy);
909 # load the modules from the 'top down'
910 0 DBI::_load_class($_, 1) foreach (reverse @hierarchy);
911 # setup class hierarchy if needed, does both '::db' and '::st'
912 0 DBI::_set_isa(\@hierarchy, $rootclass);
913 # finally bless the handle into the subclass
914 0 DBI::_rebless($dbh, $hierarchy[0]);
915 }
916  
917  
918 0 ▶sub _dbtype_names { # list dbtypes for hierarchy, ie Informix=>ADO=>ODBC
Subroutine _dbtype_names: not called CC=15 SCAR=54.8
919 0 my ($dbh, $DbTypeSubclass) = @_;
920  
921 0 ▶ if ($DbTypeSubclass && $DbTypeSubclass ne '1' && ref $DbTypeSubclass ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($DbTypeSubclass and $DbTypeSubclass ne 1 and ref $DbTypeSubclass ne "CODE") 0 0 0
Condition0%0/6
$DbTypeSubclass and $DbTypeSubclass ne 1 and ref $DbTypeSubclass ne "CODE"
!ll&&!rl&&r
000
$DbTypeSubclass and $DbTypeSubclass ne 1
!ll&&!rl&&r
000
MC/DC0%0/3
$DbTypeSubclass and $DbTypeSubclass ne 1 and ref $DbTypeSubclass ne "CODE"
$DbTypeSubclass $DbTypeSubclass ne 1 ref $DbTypeSubclass ne "CODE"
Truth table0%0/4
A and B and C
A= $DbTypeSubclassB= $DbTypeSubclass ne 1C= ref $DbTypeSubclass ne "CODE"
ABCresult
0XX0
10X0
1100
1111
922 # treat $DbTypeSubclass as a comma separated list of names
923 0 my @dbtypes = split /\s*,\s*/, $DbTypeSubclass;
924 0 $dbh->trace_msg(" DbTypeSubclass($DbTypeSubclass)=@dbtypes (explicit)\n");
925 0 return @dbtypes;
926 }
927  
928 # XXX will call $dbh->get_info(17) (=SQL_DBMS_NAME) in future?
929  
930 0 my $driver = $dbh->{Driver}->{Name};
931 0 ▶ if ( $driver eq 'Proxy' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver eq "Proxy") 0 0 0
932 # XXX Looking into the internals of DBD::Proxy is questionable!
933 0 ▶ ($driver) = $dbh->{proxy_client}->{application} =~ /^DBI:(.+?):/i
Branch: 1 branch
BranchTrueFalseTotal
($driver) = $dbh->{"proxy_client"}{"application"} =~ /^DBI:(.+?):/i or die "Can't determine driver name from proxy" 0 0 0
934 or die "Can't determine driver name from proxy";
935 }
936  
937 0 my @dbtypes = (ucfirst($driver));
938 0 ▶ if ($driver eq 'ODBC' || $driver eq 'ADO') {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver eq "ODBC" or $driver eq "ADO") 0 0 0
Condition0%0/3
$driver eq "ODBC" or $driver eq "ADO"
l!l&&r!l&&!r
000
MC/DC0%0/2
$driver eq "ODBC" or $driver eq "ADO"
$driver eq "ODBC" $driver eq "ADO"
Truth table0%0/3
A or B
A= $driver eq "ODBC"B= $driver eq "ADO"
ABresult
1X1
011
000
939 # XXX will move these out and make extensible later:
940 0 my $_dbtype_name_regexp = 'Oracle'; # eg 'Oracle|Foo|Bar'
941 0 my %_dbtype_name_map = (
942 'Microsoft SQL Server' => 'MSSQL',
943 'SQL Server' => 'Sybase',
944 'Adaptive Server Anywhere' => 'ASAny',
945 'ADABAS D' => 'AdabasD',
946 );
947  
948 0 my $name;
949 0 ▶ $name = $dbh->func(17, 'GetInfo') # SQL_DBMS_NAME
Branch: 1 branch
BranchTrueFalseTotal
if $driver eq "ODBC" 0 0 0
950 if $driver eq 'ODBC';
951 0 ▶ $name = $dbh->{ado_conn}->Properties->Item('DBMS Name')->Value
Branch: 1 branch
BranchTrueFalseTotal
if $driver eq "ADO" 0 0 0
952 if $driver eq 'ADO';
953 0 ▶ die "Can't determine driver name! ($DBI::errstr)\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
954 unless $name;
955  
956 0 my $dbtype;
957 0 ▶ if ($_dbtype_name_map{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_dbtype_name_map{$name}) { } 0 0 0
958 0 $dbtype = $_dbtype_name_map{$name};
959 }
960 else {
961 0 ▶ if ($name =~ /($_dbtype_name_regexp)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /($_dbtype_name_regexp)/) { } 0 0 0
962 0 $dbtype = lc($1);
963 }
964 else { # generic mangling for other names:
965 0 $dbtype = lc($name);
966 }
967 0 $dbtype =~ s/\b(\w)/\U$1/g;
968 0 $dbtype =~ s/\W+/_/g;
969 }
970 # add ODBC 'behind' ADO
971 0 ▶ push @dbtypes, 'ODBC' if $driver eq 'ADO';
Branch: 1 branch
BranchTrueFalseTotal
if $driver eq "ADO" 0 0 0
972 # add discovered dbtype in front of ADO/ODBC
973 0 unshift @dbtypes, $dbtype;
974 }
975 0 ▶ @dbtypes = &$DbTypeSubclass($dbh, \@dbtypes)
Branch: 1 branch
BranchTrueFalseTotal
if ref $DbTypeSubclass eq "CODE" 0 0 0
976 if (ref $DbTypeSubclass eq 'CODE');
977 0 $dbh->trace_msg(" DbTypeSubclass($DbTypeSubclass)=@dbtypes\n");
978 0 return @dbtypes;
979 }
980  
981 24 ▶sub _load_class {
Subroutine _load_class: called CC=5 SCAR=16.4
982 24 my ($load_class, $missing_ok) = @_;
983 24 DBI->trace_msg(" _load_class($load_class, $missing_ok)\n", 2);
984 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
985 24 ▶ return 1 if @{"$load_class\::ISA"}; # already loaded/exists
Branch: 1 branch
BranchTrueFalseTotal
if @{"${load_class}::ISA";} 20 4 24
986 4 (my $module = $load_class) =~ s!::!/!g;
987 4 DBI->trace_msg(" _load_class require $module\n", 2);
988 4 eval { require "$module.pm"; };
989 4 ▶ return 1 unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 4 4
990 4 ▶ return 0 if $missing_ok && $@ =~ /^Can't locate \Q$module.pm\E/;
Branch: 1 branch
BranchTrueFalseTotal
if $missing_ok and $@ =~ /^Can't locate \Q$module.pm\E/ 0 4 4
Condition33%1/3
$missing_ok and $@ =~ /^Can't locate \Q$module.pm\E/
!ll&&!rl&&r
400
MC/DC0%0/2
$missing_ok and $@ =~ /^Can't locate \Q$module.pm\E/
$missing_ok $@ =~ /^Can't locate \Q$module.pm\E/
Truth table33%1/3
A and B
A= $missing_okB= $@ =~ /^Can't locate \Q$module.pm\E/
ABresult
0X0
100
111
991 4 die $@;
992 }
993  
994  
995 0 ▶sub init_rootclass { # deprecated
Subroutine init_rootclass: not called CC=1 SCAR=6.9
Pod documented
996 0 return 1;
997 }
998  
999  
1000 214 *internal = \&DBD::Switch::dr::driver;
1001  
1002 6088 ▶sub driver_prefix {
Subroutine driver_prefix: called CC=2 SCAR=8.1
Pod documented
1003 6088 my ($class, $driver) = @_;
1004 6088 ▶ return $dbd_class_registry{$driver}->{prefix} if exists $dbd_class_registry{$driver};
Branch: 1 branch
BranchTrueFalseTotal
if exists $dbd_class_registry{$driver} 6088 0 6088
1005 0 return;
1006 }
1007  
1008 12 ▶sub available_drivers {
Subroutine available_drivers: called CC=12 SCAR=24.9
Pod documented
1009 12 my($quiet) = @_;
1010 12 my(@drivers, $d, $f);
1011 12 local(*DBI::DIR, $@);
1012 12 my(%seen_dir, %seen_dbd);
1013 12 my $haveFileSpec = eval { require File::Spec };
1014 12 foreach $d (@INC){
1015 100 chomp($d); # Perl 5 beta 3 bug in #!./perl -Ilib from Test::Harness
1016 100 ▶ my $dbd_dir =
Branch: 1 branch
BranchTrueFalseTotal
$haveFileSpec ? : 100 0 100
1017 ($haveFileSpec ? File::Spec->catdir($d, 'DBD') : "$d/DBD");
1018 100 ▶ next unless -d $dbd_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dbd_dir 64 36 100
1019 36 ▶ next if $seen_dir{$d};
Branch: 1 branch
BranchTrueFalseTotal
if $seen_dir{$d} 8 28 36
1020 28 $seen_dir{$d} = 1;
1021 # XXX we have a problem here with case insensitive file systems
1022 # XXX since we can't tell what case must be used when loading.
1023 28 ▶ opendir(DBI::DIR, $dbd_dir) || Carp::carp "opendir $dbd_dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $dbd_dir or Carp::carp("opendir ${dbd_dir}: $!\n") 28 0 28
1024 28 foreach $f (readdir(DBI::DIR)){
1025 336 ▶ next unless $f =~ s/\.pm$//;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ s/\.pm$// 112 224 336
1026 224 ▶ next if $f eq 'NullP';
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "NullP" 28 196 224
1027 196 ▶ if ($seen_dbd{$f}){
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_dbd{$f}) { } 112 84 196
1028 112 ▶ Carp::carp "DBD::$f in $d is hidden by DBD::$f in $seen_dbd{$f}\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 112 112
1029 unless $quiet;
1030 } else {
1031 84 push(@drivers, $f);
1032 }
1033 196 $seen_dbd{$f} = $d;
1034 }
1035 28 closedir(DBI::DIR);
1036 }
1037  
1038 # "return sort @drivers" will not DWIM in scalar context.
1039 12 ▶ return wantarray ? sort @drivers : @drivers;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 4 12
1040 }
1041  
1042 0 ▶sub installed_versions {
Subroutine installed_versions: not called CC=12 SCAR=48.6
Pod documented
1043 0 my ($class, $quiet) = @_;
1044 0 my %error;
1045 my %version;
1046 0 for my $driver ($class->available_drivers($quiet)) {
1047 0 ▶ next if $DBI::PurePerl && grep { -d "$_/auto/DBD/$driver" } @INC;
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::PurePerl and grep {-d "$_/auto/DBD/$driver";} @INC 0 0 0
Condition0%0/3
$DBI::PurePerl and grep {-d "$_/auto/DBD/$driver";} @INC
!ll&&!rl&&r
000
MC/DC0%0/2
$DBI::PurePerl and grep {-d "$_/auto/DBD/$driver";} @INC
$DBI::PurePerl grep {-d "$_/auto/DBD/$driver";} @INC
Truth table0%0/3
A and B
A= $DBI::PurePerlB= grep {-d "$_/auto/DBD/$driver";} @INC
ABresult
0X0
100
111
1048 0 my $drh = eval {
1049 0 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1050 0 $class->install_driver($driver);
1051 };
1052 0 ▶ ($error{"DBD::$driver"}=$@),next if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1053 214 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1054 0 my $vers = ${"DBD::$driver" . '::VERSION'};
1055 0 ▶ $version{"DBD::$driver"} = $vers || '?';
Condition0%0/2
$vers || '?'
l!l
00
MC/DC0%0/1
$vers || '?'
$vers
Truth table0%0/2
A
A= $vers
Aresult
11
00
1056 }
1057 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 0 0
1058 0 ▶ return map { m/^DBD::(\w+)/ ? ($1) : () } sort keys %version;
Branch: 1 branch
BranchTrueFalseTotal
/^DBD::(\w+)/ ? : 0 0 0
1059 }
1060 0 $version{"DBI"} = $DBI::VERSION;
1061 0 ▶ $version{"DBI::PurePerl"} = $DBI::PurePerl::VERSION if $DBI::PurePerl;
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::PurePerl 0 0 0
1062 0 ▶ if (!defined wantarray) { # void context
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1063 0 require Config; # add more detail
1064 0 $version{OS} = "$^O\t($Config::Config{osvers})";
1065 0 $version{Perl} = "$]\t($Config::Config{archname})";
1066 $version{$_} = (($error{$_} =~ s/ \(\@INC.*//s),$error{$_})
1067 0 for keys %error;
1068 printf " %-16s: %s\n",$_,$version{$_}
1069 0 for reverse sort keys %version;
1070 }
1071 0 return \%version;
1072 }
1073  
1074  
1075 12 ▶sub data_sources {
Subroutine data_sources: called CC=1 SCAR=0.0
Pod documented
1076 12 my ($class, $driver, @other) = @_;
1077 12 my $drh = $class->install_driver($driver);
1078 12 my @ds = $drh->data_sources(@other);
1079 12 return @ds;
1080 }
1081  
1082  
1083 140 ▶sub neat_list {
Subroutine neat_list: called CC=3 SCAR=11.0
Pod documented
1084 140 my ($listref, $maxlen, $sep) = @_;
1085 140 ▶ $maxlen //= 0; # 0 == use internal default
Condition100%2/2
$maxlen //= 0
l!l
1364
MC/DC100%1/1
$maxlen //= 0
$maxlen
Truth table100%2/2
A
A= $maxlen
Aresult
11
00
1086 140 ▶ $sep //= ", ";
Condition100%2/2
$sep //= ", "
l!l
1364
MC/DC100%1/1
$sep //= ", "
$sep
Truth table100%2/2
A
A= $sep
Aresult
11
00
1087 140 join($sep, map { neat($_,$maxlen) } @$listref);
1088 }
1089  
1090  
1091 4 ▶sub dump_results { # also aliased as a method in DBD::_::st
Subroutine dump_results: called CC=9 SCAR=22.7
Pod documented
1092 4 my ($sth, $maxlen, $lsep, $fsep, $fh) = @_;
1093 4 ▶ return 0 unless $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 4 4
1094 4 ▶ $maxlen ||= 35;
Condition50%1/2
$maxlen ||= 35
l!l
40
MC/DC0%0/1
$maxlen ||= 35
$maxlen
Truth table50%1/2
A
A= $maxlen
Aresult
11
00
1095 4 ▶ $lsep ||= "\n";
Condition50%1/2
$lsep ||= "\n"
l!l
40
MC/DC0%0/1
$lsep ||= "\n"
$lsep
Truth table50%1/2
A
A= $lsep
Aresult
11
00
1096 4 ▶ $fh ||= \*STDOUT;
Condition50%1/2
$fh ||= \*STDOUT
l!l
40
MC/DC0%0/1
$fh ||= \*STDOUT
$fh
Truth table50%1/2
A
A= $fh
Aresult
11
00
1097 4 my $rows = 0;
1098 4 my $ref;
1099 4 ▶ while($ref = $sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref = $sth->fetch) 24 4 28
1100 24 ▶ print $fh $lsep if $rows++ and $lsep;
Branch: 1 branch
BranchTrueFalseTotal
if $rows++ and $lsep 20 4 24
Condition66%2/3
$rows++ and $lsep
!ll&&!rl&&r
4020
MC/DC50%1/2
$rows++ and $lsep
$rows++ $lsep
Truth table66%2/3
A and B
A= $rows++B= $lsep
ABresult
0X0
100
111
1101 24 my $str = neat_list($ref,$maxlen,$fsep);
1102 24 print $fh $str; # done on two lines to avoid 5.003 errors
1103 }
1104 4 ▶ print $fh "\n$rows rows".($DBI::err ? " ($DBI::err: $DBI::errstr)" : "")."\n";
Branch: 1 branch
BranchTrueFalseTotal
$DBI::err ? : 0 4 4
1105 4 $rows;
1106 }
1107  
1108  
1109 28 ▶sub data_diff {
Subroutine data_diff: called CC=8 SCAR=20.8
Pod documented
1110 28 my ($a, $b, $logical) = @_;
1111  
1112 28 my $diff = data_string_diff($a, $b);
1113 28 ▶ return "" if $logical and !$diff;
Branch: 1 branch
BranchTrueFalseTotal
if $logical and not $diff 4 24 28
Condition66%2/3
$logical and not $diff
!ll&&!rl&&r
2404
MC/DC50%1/2
$logical and not $diff
$logical not $diff
Truth table66%2/3
A and not(B)
A= $logicalB= not $diff
ABresult
0X0
100
111
1114  
1115 24 my $a_desc = data_string_desc($a);
1116 24 my $b_desc = data_string_desc($b);
1117 24 ▶ return "" if !$diff and $a_desc eq $b_desc;
Branch: 1 branch
BranchTrueFalseTotal
if not $diff and $a_desc eq $b_desc 12 12 24
Condition100%3/3
not $diff and $a_desc eq $b_desc
!ll&&!rl&&r
8412
MC/DC100%2/2
not $diff and $a_desc eq $b_desc
not $diff $a_desc eq $b_desc
Truth table100%3/3
not(A) and B
A= not $diffB= $a_desc eq $b_desc
ABresult
0X0
100
111
1118  
1119 12 ▶ $diff ||= "Strings contain the same sequence of characters"
Branch: 1 branch
BranchTrueFalseTotal
if length $a 8 4 12
Condition100%2/2
$diff ||= "Strings contain the same sequence of characters"
l!l
44
MC/DC100%1/1
$diff ||= "Strings contain the same sequence of characters"
$diff
Truth table100%2/2
A
A= $diff
Aresult
11
00
1120 if length($a);
1121 12 ▶ $diff .= "\n" if $diff;
Branch: 1 branch
BranchTrueFalseTotal
if $diff 12 0 12
1122 12 return "a: $a_desc\nb: $b_desc\n$diff";
1123 }
1124  
1125  
1126 60 ▶sub data_string_diff {
Subroutine data_string_diff: called CC=18 SCAR=29.5
Pod documented
1127 # Compares 'logical' characters, not bytes, so a latin1 string and an
1128 # an equivalent Unicode string will compare as equal even though their
1129 # byte encodings are different.
1130 60 my ($a, $b) = @_;
1131 60 ▶ unless (defined $a and defined $b) { # one undef
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $a and defined $b) 16 44 60
Condition100%3/3
defined $a and defined $b
!ll&&!rl&&r
8844
MC/DC100%2/2
defined $a and defined $b
defined $a defined $b
Truth table100%3/3
A and B
A= defined $aB= defined $b
ABresult
0X0
100
111
1132 16 ▶ return ""
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a or defined $b 8 8 16
Condition66%2/3
defined $a or defined $b
l!l&&r!l&&!r
808
MC/DC50%1/2
defined $a or defined $b
defined $a defined $b
Truth table66%2/3
A or B
A= defined $aB= defined $b
ABresult
1X1
011
000
1133 if !defined $a and !defined $b;
1134 8 ▶ return "String a is undef, string b has ".length($b)." characters"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 8 8
1135 if !defined $a;
1136 8 ▶ return "String b is undef, string a has ".length($a)." characters"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 8 0 8
1137 if !defined $b;
1138 }
1139  
1140 44 ▶ my @a_chars = (utf8::is_utf8($a)) ? unpack("U*", $a) : unpack("C*", $a);
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($a) ? : 0 44 44
1141 44 ▶ my @b_chars = (utf8::is_utf8($b)) ? unpack("U*", $b) : unpack("C*", $b);
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($b) ? : 8 36 44
1142 44 my $i = 0;
1143 44 ▶ while (@a_chars && @b_chars) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a_chars and @b_chars) 72 32 104
Condition100%3/3
@a_chars and @b_chars
!ll&&!rl&&r
28472
MC/DC100%2/2
@a_chars and @b_chars
@a_chars @b_chars
Truth table100%3/3
A and B
A= @a_charsB= @b_chars
ABresult
0X0
100
111
1144 72 ▶ ++$i, shift(@a_chars), shift(@b_chars), next
Branch: 1 branch
BranchTrueFalseTotal
if $a_chars[0] == $b_chars[0] 60 12 72
1145 if $a_chars[0] == $b_chars[0];# compare ordinal values
1146 my @desc = map {
1147 12 ▶ $_ > 255 ? # if wide character...
Branch: 2 branches
BranchTrueFalseTotal
$_ > 255 ? : 0 24 24
chr($_) =~ /[[:cntrl:]]/ ? : 0 24 24
1148 sprintf("\\x{%04X}", $_) : # \x{...}
1149 chr($_) =~ /[[:cntrl:]]/ ? # else if control character ...
1150 sprintf("\\x%02X", $_) : # \x..
1151 chr($_) # else as themselves
1152 } ($a_chars[0], $b_chars[0]);
1153 # highlight probable double-encoding?
1154 12 foreach my $c ( @desc ) {
1155 24 ▶ next unless $c =~ m/\\x\{08(..)}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c =~ /\\x\{08(..)}/ 24 0 24
1156 0 $c .= "='" .chr(hex($1)) ."'"
1157 }
1158 12 return sprintf "Strings differ at index $i: a[$i]=$desc[0], b[$i]=$desc[1]";
1159 }
1160 32 ▶ return "String a truncated after $i characters" if @b_chars;
Branch: 1 branch
BranchTrueFalseTotal
if @b_chars 4 28 32
1161 28 ▶ return "String b truncated after $i characters" if @a_chars;
Branch: 1 branch
BranchTrueFalseTotal
if @a_chars 4 24 28
1162 24 return "";
1163 }
1164  
1165  
1166 72 ▶sub data_string_desc { # describe a data string
Subroutine data_string_desc: called CC=6 SCAR=17.9
Pod documented
1167 72 my ($a) = @_;
1168 72 require bytes;
1169  
1170 # Give sufficient info to help diagnose at least these kinds of situations:
1171 # - valid UTF8 byte sequence but UTF8 flag not set
1172 # (might be ascii so also need to check for hibit to make it worthwhile)
1173 # - UTF8 flag set but invalid UTF8 byte sequence
1174 # could do better here, but this'll do for now
1175 72 ▶ my $utf8 = sprintf "UTF8 %s%s",
Branch: 2 branches
BranchTrueFalseTotal
utf8::is_utf8($a) ? : 8 64 72
utf8::valid($a || '') ? : 72 0 72
Condition100%2/2
$a || ''
l!l
4032
MC/DC100%1/1
$a || ''
$a
Truth table100%2/2
A
A= $a
Aresult
11
00
1176 utf8::is_utf8($a) ? "on" : "off",
1177 utf8::valid($a||'') ? "" : " but INVALID encoding";
1178 72 ▶ return "$utf8, undef" unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 16 56 72
1179 56 my $is_ascii = $a =~ m/^[\000-\177]*$/;
1180 56 ▶ return sprintf "%s, %s, %d characters %d bytes",
Branch: 1 branch
BranchTrueFalseTotal
$is_ascii ? : 40 16 56
1181 $utf8, $is_ascii ? "ASCII" : "non-ASCII",
1182 length($a), bytes::length($a);
1183 }
1184  
1185  
1186 0 ▶sub connect_test_perf {
Subroutine connect_test_perf: not called CC=19 SCAR=59.4
Pod documented
1187 0 my($class, $dsn,$dbuser,$dbpass, $attr) = @_;
1188 0 ▶ Carp::croak("connect_test_perf needs hash ref as fourth arg") unless ref $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attr 0 0 0
1189 # these are non standard attributes just for this special method
1190 0 ▶ my $loops ||= $attr->{dbi_loops} || 5;
Condition0%0/5
my $loops ||= $attr->{"dbi_loops"} || 5
l!l&&r!l&&!r
000
$attr->{'dbi_loops'} || 5
l!l
00
MC/DC0%0/2
my $loops ||= $attr->{"dbi_loops"} || 5
my $loops $attr->{'dbi_loops'}
Truth table0%0/3
A ||= B
A= my $loopsB= $attr->{'dbi_loops'}
ABresult
1X1
011
000
1191 0 ▶ my $par ||= $attr->{dbi_par} || 1; # parallelism
Condition0%0/5
my $par ||= $attr->{"dbi_par"} || 1
l!l&&r!l&&!r
000
$attr->{'dbi_par'} || 1
l!l
00
MC/DC0%0/2
my $par ||= $attr->{"dbi_par"} || 1
my $par $attr->{'dbi_par'}
Truth table0%0/3
A ||= B
A= my $parB= $attr->{'dbi_par'}
ABresult
1X1
011
000
1192 0 ▶ my $verb ||= $attr->{dbi_verb} || 1;
Condition0%0/5
my $verb ||= $attr->{"dbi_verb"} || 1
l!l&&r!l&&!r
000
$attr->{'dbi_verb'} || 1
l!l
00
MC/DC0%0/2
my $verb ||= $attr->{"dbi_verb"} || 1
my $verb $attr->{'dbi_verb'}
Truth table0%0/3
A ||= B
A= my $verbB= $attr->{'dbi_verb'}
ABresult
1X1
011
000
1193 0 ▶ my $meth ||= $attr->{dbi_meth} || 'connect';
Condition0%0/5
my $meth ||= $attr->{"dbi_meth"} || "connect"
l!l&&r!l&&!r
000
$attr->{'dbi_meth'} || 'connect'
l!l
00
MC/DC0%0/2
my $meth ||= $attr->{"dbi_meth"} || "connect"
my $meth $attr->{'dbi_meth'}
Truth table0%0/3
A ||= B
A= my $methB= $attr->{'dbi_meth'}
ABresult
1X1
011
000
1194 0 print "$dsn: testing $loops sets of $par connections:\n";
1195 0 require "FileHandle.pm"; # don't let toke.c create empty FileHandle package
1196 0 local $| = 1;
1197 0 ▶ my $drh = $class->install_driver($dsn) or Carp::croak("Can't install $dsn driver\n");
Branch: 1 branch
BranchTrueFalseTotal
my $drh = $class->install_driver($dsn) or Carp::croak("Can't install $dsn driver\n") 0 0 0
1198 # test the connection and warm up caches etc
1199 0 ▶ $drh->connect($dsn,$dbuser,$dbpass) or Carp::croak("connect failed: $DBI::errstr");
Branch: 1 branch
BranchTrueFalseTotal
$drh->connect($dsn, $dbuser, $dbpass) or Carp::croak("connect failed: $DBI::errstr") 0 0 0
1200 0 my $t1 = dbi_time();
1201 0 my $loop;
1202 0 for $loop (1..$loops) {
1203 0 my @cons;
1204 0 ▶ print "Connecting... " if $verb;
Branch: 1 branch
BranchTrueFalseTotal
if $verb 0 0 0
1205 0 for (1..$par) {
1206 0 print "$_ ";
1207 0 ▶ push @cons, ($drh->connect($dsn,$dbuser,$dbpass)
Condition0%0/2
$drh->connect($dsn, $dbuser, $dbpass) || Carp::croak("connect failed: $DBI::errstr\n")
l!l
00
MC/DC0%0/1
$drh->connect($dsn, $dbuser, $dbpass) || Carp::croak("connect failed: $DBI::errstr\n")
$drh->connect($dsn, $dbuser, $dbpass)
Truth table0%0/2
A
A= $drh->connect($dsn, $dbuser, $dbpass)
Aresult
11
00
1208 or Carp::croak("connect failed: $DBI::errstr\n"));
1209 }
1210 0 ▶ print "\nDisconnecting...\n" if $verb;
Branch: 1 branch
BranchTrueFalseTotal
if $verb 0 0 0
1211 0 for (@cons) {
1212 0 ▶ $_->disconnect or warn "disconnect failed: $DBI::errstr"
Branch: 1 branch
BranchTrueFalseTotal
$_->disconnect or warn "disconnect failed: $DBI::errstr" 0 0 0
1213 }
1214 }
1215 0 my $t2 = dbi_time();
1216 0 my $td = $t2 - $t1;
1217 0 printf "$meth %d and disconnect them, %d times: %.4fs / %d = %.4fs\n",
1218 $par, $loops, $td, $loops*$par, $td/($loops*$par);
1219 0 return $td;
1220 }
1221  
1222  
1223 # Help people doing DBI->errstr, might even document it one day
1224 # XXX probably best moved to cheaper XS code if this gets documented
1225 0 ▶sub err { $DBI::err }
Subroutine err: not called CC=1 SCAR=6.9
Pod documented
1226 0 ▶sub errstr { $DBI::errstr }
Subroutine errstr: not called CC=1 SCAR=6.9
Pod documented
1227  
1228  
1229 # --- Private Internal Function for Creating New DBI Handles
1230  
1231 # XXX move to PurePerl?
1232 214 *DBI::dr::TIEHASH = \&DBI::st::TIEHASH;
1233 214 *DBI::db::TIEHASH = \&DBI::st::TIEHASH;
1234  
1235  
1236 # These three special constructors are called by the drivers
1237 # The way they are called is likely to change.
1238  
1239 214 our $shared_profile;
1240  
1241 271 ▶sub _new_drh { # called by DBD::<drivername>::driver()
Subroutine _new_drh: called CC=6 SCAR=18.0
1242 271 my ($class, $initial_attr, $imp_data) = @_;
1243 # Provide default storage for State,Err and Errstr.
1244 # Note that these are shared by all child handles by default! XXX
1245 # State must be undef to get automatic faking in DBI::var::FETCH
1246 271 my ($h_state_store, $h_err_store, $h_errstr_store) = (undef, undef, '');
1247 271 my $attr = {
1248 # these attributes get copied down to child handles by default
1249 'State' => \$h_state_store, # Holder for DBI::state
1250 'Err' => \$h_err_store, # Holder for DBI::err
1251 'Errstr' => \$h_errstr_store, # Holder for DBI::errstr
1252 'TraceLevel' => 0,
1253 FetchHashKeyName=> 'NAME',
1254 %$initial_attr,
1255 };
1256 271 my ($h, $i) = _new_handle('DBI::dr', '', $attr, $imp_data, $class);
1257  
1258 # XXX DBI_PROFILE unless DBI::PurePerl because for some reason
1259 # it kills the t/zz_*_pp.t tests (they silently exit early)
1260 269 ▶ if (($ENV{DBI_PROFILE} && !$DBI::PurePerl) || $shared_profile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DBI_PROFILE"} and not $DBI::PurePerl or $DBI::shared_profile) 5 264 269
Condition66%4/6
$ENV{"DBI_PROFILE"} and not $DBI::PurePerl or $DBI::shared_profile
l!l&&r!l&&!r
50264
$ENV{"DBI_PROFILE"} and not $DBI::PurePerl
!ll&&!rl&&r
26405
MC/DC33%1/3
$ENV{"DBI_PROFILE"} and not $DBI::PurePerl or $DBI::shared_profile
$ENV{"DBI_PROFILE"} not $DBI::PurePerl $DBI::shared_profile
Truth table40%2/5
A and not(B) or C
A= $ENV{"DBI_PROFILE"}B= not $DBI::PurePerlC= $DBI::shared_profile
ABCresult
11X1
0X11
1011
0X00
1000
1261 # The profile object created here when the first driver is loaded
1262 # is shared by all drivers so we end up with just one set of profile
1263 # data and thus the 'total time in DBI' is really the true total.
1264 5 ▶ if (!$shared_profile) { # first time
Branch: 1 branch
BranchTrueFalseTotal
if (not $DBI::shared_profile) { } 4 1 5
1265 4 $h->{Profile} = $ENV{DBI_PROFILE}; # write string
1266 2 $shared_profile = $h->{Profile}; # read and record object
1267 }
1268 else {
1269 1 $h->{Profile} = $shared_profile;
1270 }
1271 }
1272 267 ▶ return $h unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 54 213 267
1273 213 ($h, $i);
1274 }
1275  
1276 4018 ▶sub _new_dbh { # called by DBD::<drivername>::dr::connect()
Subroutine _new_dbh: called CC=5 SCAR=16.7
1277 4018 my ($drh, $attr, $imp_data) = @_;
1278 my $imp_class = $drh->{ImplementorClass}
1279 4018 ▶ or Carp::croak("DBI _new_dbh: $drh has no ImplementorClass");
Branch: 1 branch
BranchTrueFalseTotal
my $imp_class = $drh->{"ImplementorClass"} or Carp::croak("DBI _new_dbh: $drh has no ImplementorClass") 4018 0 4018
1280 4018 substr($imp_class,-4,4) = '::db';
1281 4018 my $app_class = ref $drh;
1282 4018 substr($app_class,-4,4) = '::db';
1283 4018 ▶ $attr->{Err} ||= \my $err;
Condition50%1/2
$attr->{"Err"} ||= \my $err
l!l
04018
MC/DC0%0/1
$attr->{"Err"} ||= \my $err
$attr->{"Err"}
Truth table50%1/2
A
A= $attr->{"Err"}
Aresult
11
00
1284 4018 ▶ $attr->{Errstr} ||= \my $errstr;
Condition50%1/2
$attr->{"Errstr"} ||= \my $errstr
l!l
04018
MC/DC0%0/1
$attr->{"Errstr"} ||= \my $errstr
$attr->{"Errstr"}
Truth table50%1/2
A
A= $attr->{"Errstr"}
Aresult
11
00
1285 4018 ▶ $attr->{State} ||= \my $state;
Condition50%1/2
$attr->{"State"} ||= \my $state
l!l
04018
MC/DC0%0/1
$attr->{"State"} ||= \my $state
$attr->{"State"}
Truth table50%1/2
A
A= $attr->{"State"}
Aresult
11
00
1286 4018 _new_handle($app_class, $drh, $attr, $imp_data, $imp_class);
1287 }
1288  
1289 7933 ▶sub _new_sth { # called by DBD::<drivername>::db::prepare)
Subroutine _new_sth: called CC=2 SCAR=7.0
1290 7933 my ($dbh, $attr, $imp_data) = @_;
1291 my $imp_class = $dbh->{ImplementorClass}
1292 7933 ▶ or Carp::croak("DBI _new_sth: $dbh has no ImplementorClass");
Branch: 1 branch
BranchTrueFalseTotal
my $imp_class = $dbh->{"ImplementorClass"} or Carp::croak("DBI _new_sth: $dbh has no ImplementorClass") 7933 0 7933
1293 7933 substr($imp_class,-4,4) = '::st';
1294 7933 my $app_class = ref $dbh;
1295 7933 substr($app_class,-4,4) = '::st';
1296 7933 _new_handle($app_class, $dbh, $attr, $imp_data, $imp_class);
1297 }
1298  
1299  
1300 # end of DBI package
1301  
1302  
1303  
1304 # --------------------------------------------------------------------
1305 # === The internal DBI Switch pseudo 'driver' class ===
1306  
1307 { package # hide from PAUSE
1308 DBD::Switch::dr;
1309 214 DBI->setup_driver('DBD::Switch'); # sets up @ISA
1310  
1311 214 $DBD::Switch::dr::imp_data_size = 0;
1312 214 $DBD::Switch::dr::imp_data_size = 0; # avoid typo warning
1313 214 my $drh;
1314  
1315 4 ▶ sub driver {
Subroutine driver: called CC=4 SCAR=15.2
1316 4 ▶ return $drh if $drh; # a package global
Branch: 1 branch
BranchTrueFalseTotal
if $drh 0 4 4
1317  
1318 4 my $inner;
1319 4 ($drh, $inner) = DBI::_new_drh('DBD::Switch::dr', {
1320 'Name' => 'Switch',
1321 'Version' => $DBI::VERSION,
1322 'Attribution' => "DBI $DBI::VERSION by Tim Bunce",
1323 });
1324 4 ▶ Carp::croak("DBD::Switch init failed!") unless ($drh && $inner);
Branch: 1 branch
BranchTrueFalseTotal
unless $drh and $inner 0 4 4
Condition33%1/3
$drh and $inner
!ll&&!rl&&r
004
MC/DC0%0/2
$drh and $inner
$drh $inner
Truth table33%1/3
A and B
A= $drhB= $inner
ABresult
0X0
100
111
1325 4 return $drh;
1326 }
1327 0 ▶ sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
1328 0 undef $drh;
1329 }
1330  
1331 26 ▶ sub FETCH {
Subroutine FETCH: called CC=3 SCAR=12.0
1332 26 my($drh, $key) = @_;
1333 26 ▶ return DBI->trace if $key eq 'DebugDispatch';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "DebugDispatch" 0 26 26
1334 26 ▶ return undef if $key eq 'DebugLog'; # not worth fetching, sorry
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "DebugLog" 0 26 26
1335 26 return $drh->DBD::_::dr::FETCH($key);
1336 0 undef;
1337 }
1338 20 ▶ sub STORE {
Subroutine STORE: called CC=3 SCAR=11.3
1339 20 my($drh, $key, $value) = @_;
1340 20 ▶ if ($key eq 'DebugDispatch') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'DebugDispatch') { } 4 16 20
elsif ($key eq 'DebugLog') { } 0 16 16
1341 4 DBI->trace($value);
1342 } elsif ($key eq 'DebugLog') {
1343 0 DBI->trace(-1, $value);
1344 } else {
1345 16 $drh->DBD::_::dr::STORE($key, $value);
1346 }
1347 }
1348 }
1349  
1350  
1351 # --------------------------------------------------------------------
1352 # === OPTIONAL MINIMAL BASE CLASSES FOR DBI SUBCLASSES ===
1353  
1354 # We only define default methods for harmless functions.
1355 # We don't, for example, define a DBD::_::st::prepare()
1356  
1357 214 { package # hide from PAUSE
1358 DBD::_::common; # ====== Common base class methods ======
1359 214 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1360  
1361 # methods common to all handle types:
1362  
1363 # generic TIEHASH default methods:
1364 48 ▶ sub FIRSTKEY { }
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
1365 0 ▶ sub NEXTKEY { }
Subroutine NEXTKEY: not called CC=1 SCAR=0.0
1366 126 ▶ sub EXISTS { defined($_[0]->FETCH($_[1])) } # XXX undef?
Subroutine EXISTS: called CC=1 SCAR=0.0
1367 0 ▶ sub CLEAR { Carp::carp "Can't CLEAR $_[0] (DBI)" }
Subroutine CLEAR: not called CC=1 SCAR=6.9
1368  
1369 8404 ▶ sub FETCH_many { # XXX should move to C one day
Subroutine FETCH_many: called CC=1 SCAR=0.0
1370 8404 my $h = shift;
1371 # scalar is needed to workaround drivers that return an empty list
1372 # for some attributes
1373 8404 return map { scalar $h->FETCH($_) } @_;
1374 }
1375  
1376 214 *dump_handle = \&DBI::dump_handle;
1377  
1378 725 ▶ sub install_method {
Subroutine install_method: called CC=5 SCAR=16.2
1379 # special class method called directly by apps and/or drivers
1380 # to install new methods into the DBI dispatcher
1381 # DBD::Foo::db->install_method("foo_mumble", { usage => [...], options => '...' });
1382 725 my ($class, $method, $attr) = @_;
1383 725 ▶ Carp::croak("Class '$class' must begin with DBD:: and end with ::db or ::st")
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ /^DBD::(\w+)::(dr|db|st)$/ 0 725 725
1384 unless $class =~ /^DBD::(\w+)::(dr|db|st)$/;
1385 725 my ($driver, $subtype) = ($1, $2);
1386 725 ▶ Carp::croak("invalid method name '$method'")
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /^([a-z][a-z0-9]*_)\w+$/ 0 725 725
1387 unless $method =~ m/^([a-z][a-z0-9]*_)\w+$/;
1388 725 my $prefix = $1;
1389 725 my $reg_info = $dbd_prefix_registry->{$prefix};
1390 725 ▶ Carp::carp("method name prefix '$prefix' is not associated with a registered driver") unless $reg_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $reg_info 0 725 725
1391  
1392 725 my $full_method = "DBI::${subtype}::$method";
1393 725 $DBI::installed_methods{$full_method} = $attr;
1394  
1395 725 my (undef, $filename, $line) = caller;
1396 # XXX reformat $attr as needed for _install_method
1397 725 ▶ my %attr = %{$attr||{}}; # copy so we can edit
Condition100%2/2
$attr || {}
l!l
315410
MC/DC100%1/1
$attr || {}
$attr
Truth table100%2/2
A
A= $attr
Aresult
11
00
1398 725 DBI->_install_method("DBI::${subtype}::$method", "$filename at line $line", \%attr);
1399 }
1400  
1401 80 ▶ sub parse_trace_flags {
Subroutine parse_trace_flags: called CC=10 SCAR=24.2
1402 80 my ($h, $spec) = @_;
1403 80 my $level = 0;
1404 80 my $flags = 0;
1405 80 my @unknown;
1406 80 for my $word (split /\s*[|&,]\s*/, $spec) {
1407 124 ▶ if (DBI::looks_like_number($word) && $word <= 0xF && $word >= 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (DBI::looks_like_number($word) and $word <= 15 and $word >= 0) { } 0 124 124
elsif ($word eq 'ALL') { } 4 120 124
elsif (my $flag = $h->parse_trace_flag($word)) { } 108 12 120
Condition33%2/6
DBI::looks_like_number($word) and $word <= 15 and $word >= 0
!ll&&!rl&&r
12400
DBI::looks_like_number($word) and $word <= 15
!ll&&!rl&&r
12400
MC/DC0%0/3
DBI::looks_like_number($word) and $word <= 15 and $word >= 0
DBI::looks_like_number($word) $word <= 15 $word >= 0
Truth table25%1/4
A and B and C
A= DBI::looks_like_number($word)B= $word <= 15C= $word >= 0
ABCresult
0XX0
10X0
1100
1111
1408 0 $level = $word;
1409 } elsif ($word eq 'ALL') {
1410 4 $flags = 0x7FFFFFFF; # XXX last bit causes negative headaches
1411 4 last;
1412 } elsif (my $flag = $h->parse_trace_flag($word)) {
1413 108 $flags |= $flag;
1414 }
1415 else {
1416 12 push @unknown, $word;
1417 }
1418 }
1419 80 ▶ if (@unknown && (ref $h ? $h->FETCH('Warn') : 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if (@unknown and ref $h ? $h->FETCH("Warn") : 1) 8 72 80
ref $h ? : 8 0 8
Condition66%2/3
@unknown and ref $h ? $h->FETCH("Warn") : 1
!ll&&!rl&&r
7208
MC/DC50%1/2
@unknown and ref $h ? $h->FETCH("Warn") : 1
@unknown ref $h ? $h->FETCH("Warn") : 1
Truth table66%2/3
A and B
A= @unknownB= ref $h ? $h->FETCH("Warn") : 1
ABresult
0X0
100
111
1420 Carp::carp("$h->parse_trace_flags($spec) ignored unknown trace flags: ".
1421 8 join(" ", map { DBI::neat($_) } @unknown));
1422 }
1423 80 $flags |= $level;
1424 80 return $flags;
1425 }
1426  
1427 96 ▶ sub parse_trace_flag {
Subroutine parse_trace_flag: called CC=6 SCAR=17.9
1428 96 my ($h, $name) = @_;
1429 # 0xddDDDDrL (driver, DBI, reserved, Level)
1430 96 ▶ return 0x00000100 if $name eq 'SQL';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "SQL" 24 72 96
1431 72 ▶ return 0x00000200 if $name eq 'CON';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "CON" 14 58 72
1432 58 ▶ return 0x00000400 if $name eq 'ENC';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "ENC" 14 44 58
1433 44 ▶ return 0x00000800 if $name eq 'DBD';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "DBD" 14 30 44
1434 30 ▶ return 0x00001000 if $name eq 'TXN';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "TXN" 14 16 30
1435 16 return;
1436 }
1437  
1438 3788 ▶ sub private_attribute_info {
Subroutine private_attribute_info: called CC=1 SCAR=0.0
1439 3788 return undef;
1440 }
1441  
1442 28 ▶ sub visit_child_handles {
Subroutine visit_child_handles: called CC=6 SCAR=18.0
1443 28 my ($h, $code, $info) = @_;
1444 28 ▶ $info //= {};
Condition50%1/2
$info //= {}
l!l
280
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
Aresult
11
00
1445 28 ▶ for my $ch (@{ $h->{ChildHandles} || []}) {
Condition100%2/2
$h->{'ChildHandles'} || []
l!l
208
MC/DC100%1/1
$h->{'ChildHandles'} || []
$h->{'ChildHandles'}
Truth table100%2/2
A
A= $h->{'ChildHandles'}
Aresult
11
00
1446 384 ▶ next unless $ch;
Branch: 1 branch
BranchTrueFalseTotal
unless $ch 368 16 384
1447 16 ▶ my $child_info = $code->($ch, $info)
Branch: 1 branch
BranchTrueFalseTotal
my $child_info = &$code($ch, $info) or next 16 0 16
1448 or next;
1449 16 $ch->visit_child_handles($code, $child_info);
1450 }
1451 28 return $info;
1452 }
1453 }
1454  
1455  
1456 214 { package # hide from PAUSE
1457 DBD::_::dr; # ====== DRIVER ======
1458 214 our @ISA = qw(DBD::_::common);
1459 214 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1460  
1461 1762 ▶ sub default_user {
Subroutine default_user: called CC=3 SCAR=11.2
1462 1762 my ($drh, $user, $pass, $attr) = @_;
1463 1762 ▶ $user //= $ENV{DBI_USER};
Condition66%2/3
$user //= $ENV{"DBI_USER"}
l!l&&r!l&&!r
401758
MC/DC50%1/2
$user //= $ENV{"DBI_USER"}
$user $ENV{"DBI_USER"}
Truth table66%2/3
A //= B
A= $userB= $ENV{"DBI_USER"}
ABresult
1X1
011
000
1464 1762 ▶ $pass //= $ENV{DBI_PASS};
Condition66%2/3
$pass //= $ENV{"DBI_PASS"}
l!l&&r!l&&!r
401758
MC/DC50%1/2
$pass //= $ENV{"DBI_PASS"}
$pass $ENV{"DBI_PASS"}
Truth table66%2/3
A //= B
A= $passB= $ENV{"DBI_PASS"}
ABresult
1X1
011
000
1465 1762 return ($user, $pass);
1466 }
1467  
1468 131 ▶ sub connect { # normally overridden, but a handy default
Subroutine connect: called CC=1 SCAR=0.0
1469 131 my ($drh, $dsn, $user, $auth) = @_;
1470 131 my ($this) = DBI::_new_dbh($drh, {
1471 'Name' => $dsn,
1472 });
1473 # XXX debatable as there's no "server side" here
1474 # (and now many uses would trigger warnings on DESTROY)
1475 # $this->STORE(Active => 1);
1476 # so drivers should set it in their own connect
1477 131 $this;
1478 }
1479  
1480  
1481 3146 ▶ sub connect_cached {
Subroutine connect_cached: called CC=12 SCAR=25.0
1482 3146 my $drh = shift;
1483 3146 my ($dsn, $user, $auth, $attr) = @_;
1484  
1485 3146 ▶ my $cache = $drh->{CachedKids} ||= {};
Condition100%2/2
$drh->{"CachedKids"} ||= {}
l!l
312620
MC/DC100%1/1
$drh->{"CachedKids"} ||= {}
$drh->{"CachedKids"}
Truth table100%2/2
A
A= $drh->{"CachedKids"}
Aresult
11
00
1486 214 ▶ my $key = do { no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1487 3146 join "!\001", $dsn, $user, $auth, DBI::_concat_hash_sorted($attr, "=\001", ",\001", 0, 0)
1488 };
1489 3146 my $dbh = $cache->{$key};
1490 3146 ▶ $drh->trace_msg(sprintf(" connect_cached: key '%s', cached dbh %s\n", DBI::neat($key), DBI::neat($dbh)))
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::dbi_debug & 15) >= 4 0 3146 3146
1491 if (($DBI::dbi_debug & 0xF) >= 4);
1492  
1493 3146 my $cb = $attr->{Callbacks}; # take care not to autovivify
1494 3146 ▶ if ($dbh && $dbh->FETCH('Active') && eval { $dbh->ping }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh and $dbh->FETCH("Active") and eval { do { $dbh->ping } }) 3114 32 3146
Condition66%4/6
$dbh and $dbh->FETCH("Active") and eval { do { $dbh->ping } }
!ll&&!rl&&r
3203114
$dbh and $dbh->FETCH("Active")
!ll&&!rl&&r
3203114
MC/DC33%1/3
$dbh and $dbh->FETCH("Active") and eval { do { $dbh->ping } }
$dbh $dbh->FETCH("Active") eval { do { $dbh->ping } }
Truth table50%2/4
A and B and C
A= $dbhB= $dbh->FETCH("Active")C= eval { do { $dbh->ping } }
ABCresult
0XX0
10X0
1100
1111
1495 # If the caller has provided a callback then call it
1496 3114 ▶ if ($cb and $cb = $cb->{"connect_cached.reused"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and $cb = $cb->{"connect_cached.reused"}) 2 3112 3114
Condition66%2/3
$cb and $cb = $cb->{"connect_cached.reused"}
!ll&&!rl&&r
311202
MC/DC50%1/2
$cb and $cb = $cb->{"connect_cached.reused"}
$cb $cb = $cb->{"connect_cached.reused"}
Truth table66%2/3
A and B
A= $cbB= $cb = $cb->{"connect_cached.reused"}
ABresult
0X0
100
111
1497 2 local $_ = "connect_cached.reused";
1498 2 $cb->($dbh, $dsn, $user, $auth, $attr);
1499 }
1500 3114 return $dbh;
1501 }
1502  
1503 # If the caller has provided a callback then call it
1504 32 ▶ if ($cb and (my $new_cb = $cb->{"connect_cached.new"})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and my $new_cb = $cb->{"connect_cached.new"}) 2 30 32
Condition66%2/3
$cb and my $new_cb = $cb->{"connect_cached.new"}
!ll&&!rl&&r
3002
MC/DC50%1/2
$cb and my $new_cb = $cb->{"connect_cached.new"}
$cb my $new_cb = $cb->{"connect_cached.new"}
Truth table66%2/3
A and B
A= $cbB= my $new_cb = $cb->{"connect_cached.new"}
ABresult
0X0
100
111
1505 2 local $_ = "connect_cached.new";
1506 2 $new_cb->($dbh, $dsn, $user, $auth, $attr); # $dbh is dead or undef
1507 }
1508  
1509 32 $dbh = $drh->connect(@_);
1510 32 $cache->{$key} = $dbh; # replace prev entry, even if connect failed
1511 32 ▶ if ($cb and (my $conn_cb = $cb->{"connect_cached.connected"})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and my $conn_cb = $cb->{"connect_cached.connected"}) 2 30 32
Condition66%2/3
$cb and my $conn_cb = $cb->{"connect_cached.connected"}
!ll&&!rl&&r
3002
MC/DC50%1/2
$cb and my $conn_cb = $cb->{"connect_cached.connected"}
$cb my $conn_cb = $cb->{"connect_cached.connected"}
Truth table66%2/3
A and B
A= $cbB= my $conn_cb = $cb->{"connect_cached.connected"}
ABresult
0X0
100
111
1512 2 local $_ = "connect_cached.connected";
1513 2 $conn_cb->($dbh, $dsn, $user, $auth, $attr);
1514 }
1515 32 return $dbh;
1516 }
1517  
1518 }
1519  
1520  
1521 214 { package # hide from PAUSE
1522 DBD::_::db; # ====== DATABASE ======
1523 214 our @ISA = qw(DBD::_::common);
1524 214 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1525  
1526 16 ▶ sub clone {
Subroutine clone: called CC=8 SCAR=21.1
1527 16 my ($old_dbh, $attr) = @_;
1528  
1529 my $closure = $old_dbh->{dbi_connect_closure}
1530 16 ▶ or return $old_dbh->set_err($DBI::stderr, "Can't clone handle");
Branch: 1 branch
BranchTrueFalseTotal
my $closure = $old_dbh->{"dbi_connect_closure"} or return $old_dbh->set_err($DBI::stderr, "Can't clone handle") 16 0 16
1531  
1532 16 ▶ unless ($attr) { # XXX deprecated, caller should always pass a hash ref
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr) 8 8 16
1533 # copy attributes visible in the attribute cache
1534 8 keys %$old_dbh; # reset iterator
1535 8 ▶ while ( my ($k, $v) = each %$old_dbh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$old_dbh) 200 8 208
1536 # ignore non-code refs, i.e., caches, handles, Err etc
1537 200 ▶ next if ref $v && ref $v ne 'CODE'; # HandleError etc
Branch: 1 branch
BranchTrueFalseTotal
if ref $v and ref $v ne "CODE" 40 160 200
Condition100%3/3
ref $v and ref $v ne "CODE"
!ll&&!rl&&r
152840
MC/DC100%2/2
ref $v and ref $v ne "CODE"
ref $v ref $v ne "CODE"
Truth table100%3/3
A and B
A= ref $vB= ref $v ne "CODE"
ABresult
0X0
100
111
1538 160 $attr->{$k} = $v;
1539 }
1540 # explicitly set attributes which are unlikely to be in the
1541 # attribute cache, i.e., boolean's and some others
1542 8 $attr->{$_} = $old_dbh->FETCH($_) for (qw(
1543 AutoCommit ChopBlanks InactiveDestroy AutoInactiveDestroy
1544 LongTruncOk PrintError PrintWarn Profile RaiseError RaiseWarn
1545 ShowErrorStatement TaintIn TaintOut
1546 ));
1547 }
1548  
1549 # use Data::Dumper; warn Dumper([$old_dbh, $attr]);
1550 16 my $new_dbh = &$closure($old_dbh, $attr);
1551 16 ▶ unless ($new_dbh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_dbh) 0 16 16
1552 # need to copy err/errstr from driver back into $old_dbh
1553 0 my $drh = $old_dbh->{Driver};
1554 0 return $old_dbh->set_err($drh->err, $drh->errstr, $drh->state);
1555 }
1556 16 $new_dbh->{dbi_connect_closure} = $closure;
1557 16 return $new_dbh;
1558 }
1559  
1560 114 ▶ sub quote_identifier {
Subroutine quote_identifier: called CC=13 SCAR=25.8
1561 114 my ($dbh, @id) = @_;
1562 114 ▶ my $attr = (@id > 3 && ref($id[-1])) ? pop @id : undef;
Branch: 1 branch
BranchTrueFalseTotal
@id > 3 && ref $id[-1] ? : 0 114 114
Condition33%1/3
@id > 3 and ref $id[-1]
!ll&&!rl&&r
11400
MC/DC0%0/2
@id > 3 and ref $id[-1]
@id > 3 ref $id[-1]
Truth table33%1/3
A and B
A= @id > 3B= ref $id[-1]
ABresult
0X0
100
111
1563  
1564 my $info = $dbh->{dbi_quote_identifier_cache} ||= [
1565 114 ▶ $dbh->get_info(29) || '"', # SQL_IDENTIFIER_QUOTE_CHAR
Condition87%7/8
$dbh->{"dbi_quote_identifier_cache"} ||= [$dbh->get_info(29) || "\"", $dbh->get_info(41) || ".", $dbh->get_info(114) || 1]
l!l
9024
$dbh->get_info(29) || '"'
l!l
240
$dbh->get_info(41) || '.'
l!l
204
$dbh->get_info(114) || 1
l!l
204
MC/DC100%1/1
$dbh->{"dbi_quote_identifier_cache"} ||= [$dbh->get_info(29) || "\"", $dbh->get_info(41) || ".", $dbh->get_info(114) || 1]
$dbh->{"dbi_quote_identifier_cache"}
MC/DC0%0/1
$dbh->get_info(29) || '"'
$dbh->get_info(29)
MC/DC100%1/1
$dbh->get_info(41) || '.'
$dbh->get_info(41)
MC/DC100%1/1
$dbh->get_info(114) || 1
$dbh->get_info(114)
Truth table100%2/2
A
A= $dbh->{"dbi_quote_identifier_cache"}
Aresult
11
00
Truth table50%1/2
A
A= $dbh->get_info(29)
Aresult
11
00
Truth table100%2/2
A
A= $dbh->get_info(41)
Aresult
11
00
Truth table100%2/2
A
A= $dbh->get_info(114)
Aresult
11
00
1566 $dbh->get_info(41) || '.', # SQL_CATALOG_NAME_SEPARATOR
1567 $dbh->get_info(114) || 1, # SQL_CATALOG_LOCATION
1568 ];
1569  
1570 114 my $quote = $info->[0];
1571 114 foreach (@id) { # quote the elements
1572 322 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 114 208 322
1573 208 s/$quote/$quote$quote/g; # escape embedded quotes
1574 208 $_ = qq{$quote$_$quote};
1575 }
1576  
1577 # strip out catalog if present for special handling
1578 114 ▶ my $catalog = (@id >= 3) ? shift @id : undef;
Branch: 1 branch
BranchTrueFalseTotal
@id >= 3 ? : 102 12 114
1579  
1580 # join the dots, ignoring any null/undef elements (ie schema)
1581 114 my $quoted_id = join '.', grep { defined } @id;
1582  
1583 114 ▶ if ($catalog) { # add catalog correctly
Branch: 1 branch
BranchTrueFalseTotal
if ($catalog) 78 36 114
1584 78 ▶ if ($quoted_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted_id) { } 70 8 78
1585 70 ▶ $quoted_id = ($info->[2] == 2) # SQL_CL_END
Branch: 1 branch
BranchTrueFalseTotal
$info->[2] == 2 ? : 2 68 70
1586 ? $quoted_id . $info->[1] . $catalog
1587 : $catalog . $info->[1] . $quoted_id;
1588 } else {
1589 8 $quoted_id = $catalog;
1590 }
1591 }
1592 114 return $quoted_id;
1593 }
1594  
1595 16 ▶ sub quote {
Subroutine quote: called CC=16 SCAR=30.1
1596 16 my ($dbh, $str, $data_type) = @_;
1597  
1598 16 ▶ return "NULL" unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 4 12 16
1599 12 ▶ unless ($data_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_type) 4 8 12
1600 4 $str =~ s/'/''/g; # ISO SQL2
1601 4 return "'$str'";
1602 }
1603  
1604 8 ▶ my $dbi_literal_quote_cache = $dbh->{'dbi_literal_quote_cache'} ||= [ {} , {} ];
Condition100%2/2
$dbh->{"dbi_literal_quote_cache"} ||= [{}, {}]
l!l
26
MC/DC100%1/1
$dbh->{"dbi_literal_quote_cache"} ||= [{}, {}]
$dbh->{"dbi_literal_quote_cache"}
Truth table100%2/2
A
A= $dbh->{"dbi_literal_quote_cache"}
Aresult
11
00
1605 8 my ($prefixes, $suffixes) = @$dbi_literal_quote_cache;
1606  
1607 8 my $lp = $prefixes->{$data_type};
1608 8 my $ls = $suffixes->{$data_type};
1609  
1610 8 ▶ if ( ! defined $lp || ! defined $ls ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lp and defined $ls) 8 0 8
Condition33%1/3
defined $lp and defined $ls
!ll&&!rl&&r
800
MC/DC0%0/2
defined $lp and defined $ls
defined $lp defined $ls
Truth table33%1/3
A and B
A= defined $lpB= defined $ls
ABresult
0X0
100
111
1611 8 my $ti = $dbh->type_info($data_type);
1612 8 ▶ $lp = $prefixes->{$data_type} = $ti ? $ti->{LITERAL_PREFIX} || "" : "'";
Branch: 1 branch
BranchTrueFalseTotal
$ti ? : 8 0 8
Condition100%2/2
$ti->{"LITERAL_PREFIX"} or ""
l!l
44
MC/DC100%1/1
$ti->{"LITERAL_PREFIX"} or ""
$ti->{"LITERAL_PREFIX"}
Truth table100%2/2
A
A= $ti->{"LITERAL_PREFIX"}
Aresult
11
00
1613 8 ▶ $ls = $suffixes->{$data_type} = $ti ? $ti->{LITERAL_SUFFIX} || "" : "'";
Branch: 1 branch
BranchTrueFalseTotal
$ti ? : 8 0 8
Condition100%2/2
$ti->{"LITERAL_SUFFIX"} or ""
l!l
44
MC/DC100%1/1
$ti->{"LITERAL_SUFFIX"} or ""
$ti->{"LITERAL_SUFFIX"}
Truth table100%2/2
A
A= $ti->{"LITERAL_SUFFIX"}
Aresult
11
00
1614 }
1615 8 ▶ return $str unless $lp || $ls; # no quoting required
Branch: 1 branch
BranchTrueFalseTotal
unless $lp or $ls 4 4 8
Condition66%2/3
$lp or $ls
l!l&&r!l&&!r
404
MC/DC50%1/2
$lp or $ls
$lp $ls
Truth table66%2/3
A or B
A= $lpB= $ls
ABresult
1X1
011
000
1616  
1617 # XXX don't know what the standard says about escaping
1618 # in the 'general case' (where $lp != "'").
1619 # So we just do this and hope:
1620 4 ▶ $str =~ s/$lp/$lp$lp/g
Branch: 1 branch
BranchTrueFalseTotal
if $lp and $lp eq $ls and $lp eq "'" || $lp eq "\"" 4 0 4
Condition33%3/9
$lp and $lp eq $ls and $lp eq "'" || $lp eq "\""
!ll&&!rl&&r
004
$lp and $lp eq $ls
!ll&&!rl&&r
004
$lp eq "'" or $lp eq "\""
l!l&&r!l&&!r
400
MC/DC0%0/4
$lp and $lp eq $ls and $lp eq "'" || $lp eq "\""
$lp $lp eq $ls $lp eq "'" $lp eq "\""
Truth table20%1/5
A and B and C or D
A= $lpB= $lp eq $lsC= $lp eq "'"D= $lp eq "\""
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1621 if $lp && $lp eq $ls && ($lp eq "'" || $lp eq '"');
1622 4 return "$lp$str$ls";
1623 }
1624  
1625 0 ▶ sub rows { -1 } # here so $DBI::rows 'works' after using $dbh
Subroutine rows: not called CC=1 SCAR=6.9
1626  
1627 1755 ▶ sub do {
Subroutine do: called CC=4 SCAR=13.9
1628 1755 my($dbh, $statement, $attr, @params) = @_;
1629 1755 ▶ my $sth = $dbh->prepare($statement, $attr) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($statement, $attr) or return undef 1751 4 1755
1630 1751 ▶ $sth->execute(@params) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@params) or return undef 244 1507 1751
1631 244 my $rows = $sth->rows;
1632 244 ▶ ($rows == 0) ? "0E0" : $rows;
Branch: 1 branch
BranchTrueFalseTotal
$rows == 0 ? : 68 176 244
1633 }
1634  
1635 24 ▶ sub _do_selectrow {
Subroutine _do_selectrow: called CC=5 SCAR=16.7
1636 24 my ($method, $dbh, $stmt, $attr, @bind) = @_;
1637 24 ▶ my $sth = ((ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr))
Branch: 2 branches
BranchTrueFalseTotal
my $sth = ref $stmt ? $stmt : $dbh->prepare($stmt, $attr) or return undef 24 0 24
ref $stmt ? : 0 24 24
1638 or return undef;
1639 24 ▶ $sth->execute(@bind)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or return undef 16 8 24
1640 or return undef;
1641 16 ▶ my $row = $sth->$method()
Branch: 1 branch
BranchTrueFalseTotal
my $row = $sth->$method and $sth->finish 16 0 16
1642 and $sth->finish;
1643 16 return $row;
1644 }
1645  
1646 4 ▶ sub selectrow_hashref { return _do_selectrow('fetchrow_hashref', @_); }
Subroutine selectrow_hashref: called CC=1 SCAR=0.0
1647  
1648 # XXX selectrow_array/ref also have C implementations in Driver.xst
1649 8 ▶ sub selectrow_arrayref { return _do_selectrow('fetchrow_arrayref', @_); }
Subroutine selectrow_arrayref: called CC=1 SCAR=0.0
1650 12 ▶ sub selectrow_array {
Subroutine selectrow_array: called CC=3 SCAR=11.7
1651 12 ▶ my $row = _do_selectrow('fetchrow_arrayref', @_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $row = _do_selectrow("fetchrow_arrayref", @_) or return 12 0 12
1652 12 ▶ return $row->[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 12 12
1653 12 return @$row;
1654 }
1655  
1656 4 ▶ sub selectall_array {
Subroutine selectall_array: called CC=2 SCAR=7.2
1657 4 ▶ return @{ shift->selectall_arrayref(@_) || [] };
Condition50%1/2
(shift())->selectall_arrayref(@_) || []
l!l
40
MC/DC0%0/1
(shift())->selectall_arrayref(@_) || []
(shift())->selectall_arrayref(@_)
Truth table50%1/2
A
A= (shift())->selectall_arrayref(@_)
Aresult
11
00
1658 }
1659  
1660 # XXX selectall_arrayref also has C implementation in Driver.xst
1661 # which fallsback to this if a slice is given
1662 126 ▶ sub selectall_arrayref {
Subroutine selectall_arrayref: called CC=9 SCAR=22.0
1663 126 my ($dbh, $stmt, $attr, @bind) = @_;
1664 126 ▶ my $sth = (ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr)
Branch: 2 branches
BranchTrueFalseTotal
my $sth = ref $stmt ? $stmt : $dbh->prepare($stmt, $attr) or return 122 4 126
ref $stmt ? : 4 122 126
1665 or return;
1666 122 ▶ $sth->execute(@bind) || return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or return 122 0 122
1667 122 my $slice = $attr->{Slice}; # typically undef, else hash or array ref
1668 122 ▶ if (!$slice and $slice=$attr->{Columns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $slice and $slice = $attr->{"Columns"}) 8 114 122
Condition100%3/3
not $slice and $slice = $attr->{"Columns"}
!ll&&!rl&&r
41108
MC/DC100%2/2
not $slice and $slice = $attr->{"Columns"}
not $slice $slice = $attr->{"Columns"}
Truth table100%3/3
not(A) and B
A= not $sliceB= $slice = $attr->{"Columns"}
ABresult
0X0
100
111
1669 8 ▶ if (ref $slice eq 'ARRAY') { # map col idx to perl array idx
Branch: 1 branch
BranchTrueFalseTotal
if (ref $slice eq "ARRAY") 4 4 8
1670 4 $slice = [ @{$attr->{Columns}} ]; # take a copy
1671 4 for (@$slice) { $_-- }
1672 }
1673 }
1674 122 my $rows = $sth->fetchall_arrayref($slice, my $MaxRows = $attr->{MaxRows});
1675 122 ▶ $sth->finish if defined $MaxRows;
Branch: 1 branch
BranchTrueFalseTotal
if defined $MaxRows 0 122 122
1676 122 return $rows;
1677 }
1678  
1679 8 ▶ sub selectall_hashref {
Subroutine selectall_hashref: called CC=4 SCAR=14.6
1680 8 my ($dbh, $stmt, $key_field, $attr, @bind) = @_;
1681 8 ▶ my $sth = (ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr);
Branch: 1 branch
BranchTrueFalseTotal
ref $stmt ? : 0 8 8
1682 8 ▶ return unless $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 8 8
1683 8 ▶ $sth->execute(@bind) || return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or return 8 0 8
1684 8 return $sth->fetchall_hashref($key_field);
1685 }
1686  
1687 8 ▶ sub selectcol_arrayref {
Subroutine selectcol_arrayref: called CC=11 SCAR=27.1
1688 8 my ($dbh, $stmt, $attr, @bind) = @_;
1689 8 ▶ my $sth = (ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr);
Branch: 1 branch
BranchTrueFalseTotal
ref $stmt ? : 0 8 8
1690 8 ▶ return unless $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 8 8
1691 8 ▶ $sth->execute(@bind) || return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or return 8 0 8
1692 8 ▶ my @columns = ($attr->{Columns}) ? @{$attr->{Columns}} : (1);
Branch: 1 branch
BranchTrueFalseTotal
$attr->{'Columns'} ? : 4 4 8
1693 8 my @values = (undef) x @columns;
1694 8 my $idx = 0;
1695 8 for (@columns) {
1696 12 ▶ $sth->bind_col($_, \$values[$idx++]) || return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->bind_col($_, \$values[$idx++]) or return 12 0 12
1697 }
1698 8 my @col;
1699 8 ▶ if (my $max = $attr->{MaxRows}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max = $attr->{'MaxRows'}) { } 0 8 8
1700 0 ▶ push @col, @values while 0 < $max-- && $sth->fetch;
Branch: 1 branch
BranchTrueFalseTotal
0 < $max-- and $sth->fetch and do { push @col, @values } 0 0 0
Condition0%0/3
0 < $max-- and $sth->fetch
!ll&&!rl&&r
000
MC/DC0%0/2
0 < $max-- and $sth->fetch
0 < $max-- $sth->fetch
Truth table0%0/3
A and B
A= 0 < $max--B= $sth->fetch
ABresult
0X0
100
111
1701 }
1702 else {
1703 8 ▶ push @col, @values while $sth->fetch;
Branch: 1 branch
BranchTrueFalseTotal
$sth->fetch and do { push @col, @values } 24 8 32
1704 }
1705 8 return \@col;
1706 }
1707  
1708 48 ▶ sub prepare_cached {
Subroutine prepare_cached: called CC=9 SCAR=22.0
1709 48 my ($dbh, $statement, $attr, $if_active) = @_;
1710  
1711 # Needs support at dbh level to clear cache before complaining about
1712 # active children. The XS template code does this. Drivers not using
1713 # the template must handle clearing the cache themselves.
1714 48 ▶ my $cache = $dbh->{CachedKids} ||= {};
Condition100%2/2
$dbh->{"CachedKids"} ||= {}
l!l
1632
MC/DC100%1/1
$dbh->{"CachedKids"} ||= {}
$dbh->{"CachedKids"}
Truth table100%2/2
A
A= $dbh->{"CachedKids"}
Aresult
11
00
1715 214 ▶ my $key = do { no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1716 48 join "!\001", $statement, DBI::_concat_hash_sorted($attr, "=\001", ",\001", 0, 0)
1717 };
1718 48 my $sth = $cache->{$key};
1719  
1720 48 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 12 36 48
1721 12 ▶ return $sth unless $sth->FETCH('Active');
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->FETCH("Active") 0 12 12
1722 12 ▶ Carp::carp("prepare_cached($statement) statement handle $sth still Active")
Branch: 1 branch
BranchTrueFalseTotal
unless $if_active ||= 0 4 8 12
Condition100%2/2
$if_active ||= 0
l!l
84
MC/DC100%1/1
$if_active ||= 0
$if_active
Truth table100%2/2
A
A= $if_active
Aresult
11
00
1723 unless ($if_active ||= 0);
1724 12 ▶ $sth->finish if $if_active <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $if_active <= 1 8 4 12
1725 12 ▶ return $sth if $if_active <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $if_active <= 2 8 4 12
1726 }
1727  
1728 40 $sth = $dbh->prepare($statement, $attr);
1729 40 ▶ $cache->{$key} = $sth if $sth;
Branch: 1 branch
BranchTrueFalseTotal
if $sth 40 0 40
1730  
1731 40 return $sth;
1732 }
1733  
1734 12 ▶ sub ping {
Subroutine ping: called CC=2 SCAR=6.9
1735 12 my $dbh = shift;
1736 # "0 but true" is a special kind of true 0 that is used here so
1737 # applications can check if the ping was a real ping or not
1738 12 ▶ ($dbh->FETCH('Active')) ? "0 but true" : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->FETCH('Active') ? : 8 4 12
1739 }
1740  
1741 4 ▶ sub begin_work {
Subroutine begin_work: called CC=2 SCAR=7.0
1742 4 my $dbh = shift;
1743 4 ▶ return $dbh->set_err($DBI::stderr, "Already in a transaction")
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->FETCH("AutoCommit") 0 4 4
1744 unless $dbh->FETCH('AutoCommit');
1745 4 $dbh->STORE('AutoCommit', 0); # will croak if driver doesn't support it
1746 4 $dbh->STORE('BegunWork', 1); # trigger post commit/rollback action
1747 4 return 1;
1748 }
1749  
1750 0 ▶ sub primary_key {
Subroutine primary_key: not called CC=4 SCAR=30.0
1751 0 my ($dbh, @args) = @_;
1752 0 ▶ my $sth = $dbh->primary_key_info(@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->primary_key_info(@args) or return 0 0 0
1753 0 my ($row, @col);
1754 0 ▶ push @col, $row->[3] while ($row = $sth->fetch);
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @col, $row->[3] } 0 0 0
1755 0 ▶ Carp::croak("primary_key method not called in list context")
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
1756 unless wantarray; # leave us some elbow room
1757 0 return @col;
1758 }
1759  
1760 32 ▶ sub tables {
Subroutine tables: called CC=10 SCAR=23.5
1761 32 my ($dbh, @args) = @_;
1762 32 ▶ my $sth = $dbh->table_info(@args[0,1,2,3,4]) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->table_info(@args[0, 1, 2, 3, 4]) or return 32 0 32
1763 32 ▶ my $tables = $sth->fetchall_arrayref or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tables = $sth->fetchall_arrayref or return 32 0 32
1764 32 my @tables;
1765 32 ▶ if (defined($args[3]) && $args[3] eq '%' # special case for tables('','','','%')
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args[3] and $args[3] eq '%' and grep {defined $_ and $_ eq '';} @args[0, 1, 2]) { } 4 28 32
elsif ($dbh->get_info(29)) { } 16 12 28
Condition83%5/6
defined $args[3] and $args[3] eq "%" and grep {defined $_ and $_ eq "";} @args[0, 1, 2]
!ll&&!rl&&r
2804
defined $args[3] and $args[3] eq "%"
!ll&&!rl&&r
2444
MC/DC66%2/3
defined $args[3] and $args[3] eq "%" and grep {defined $_ and $_ eq "";} @args[0, 1, 2]
defined $args[3] $args[3] eq "%" grep {defined $_ and $_ eq "";} @args[0, 1, 2]
Truth table75%3/4
A and B and C
A= defined $args[3]B= $args[3] eq "%"C= grep {defined $_ and $_ eq "";} @args[0, 1, 2]
ABCresult
0XX0
10X0
1100
1111
1766 12 ▶ && grep {defined($_) && $_ eq ''} @args[0,1,2]
Condition33%1/3
defined $_ && $_ eq ''
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $_ && $_ eq ''
defined $_ $_ eq ''
Truth table33%1/3
A && B
A= defined $_B= $_ eq ''
ABresult
0X0
100
111
1767 ) {
1768 4 @tables = map { $_->[3] } @$tables;
1769 } elsif ($dbh->get_info(29)) { # SQL_IDENTIFIER_QUOTE_CHAR
1770 16 @tables = map { $dbh->quote_identifier( @{$_}[0,1,2] ) } @$tables;
1771 }
1772 else { # temporary old style hack (yeach)
1773 @tables = map {
1774 12 my $name = $_->[2];
1775 16 ▶ if ($_->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[1]) 16 0 16
1776 16 my $schema = $_->[1];
1777 # a sad hack (mostly for Informix I recall)
1778 16 ▶ my $quote = ($schema eq uc($schema)) ? '' : '"';
Branch: 1 branch
BranchTrueFalseTotal
$schema eq uc $schema ? : 0 16 16
1779 16 $name = "$quote$schema$quote.$name"
1780 }
1781 16 $name;
1782 } @$tables;
1783 }
1784 32 return @tables;
1785 }
1786  
1787 28 ▶ sub type_info { # this should be sufficient for all drivers
Subroutine type_info: called CC=15 SCAR=28.8
1788 28 my ($dbh, $data_type) = @_;
1789 28 my $idx_hash;
1790 28 my $tia = $dbh->{dbi_type_info_row_cache};
1791 28 ▶ if ($tia) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tia) { } 18 10 28
1792 18 $idx_hash = $dbh->{dbi_type_info_idx_cache};
1793 }
1794 else {
1795 10 my $temp = $dbh->type_info_all;
1796 10 ▶ return unless $temp && @$temp;
Branch: 1 branch
BranchTrueFalseTotal
unless $temp and @$temp 0 10 10
Condition33%1/3
$temp and @$temp
!ll&&!rl&&r
0010
MC/DC0%0/2
$temp and @$temp
$temp @$temp
Truth table33%1/3
A and B
A= $tempB= @$temp
ABresult
0X0
100
111
1797 # we cache here because type_info_all may be expensive to call
1798 # (and we take a copy so the following shift can't corrupt
1799 # the data that may be returned by future calls to type_info_all)
1800 10 $tia = $dbh->{dbi_type_info_row_cache} = [ @$temp ];
1801 10 $idx_hash = $dbh->{dbi_type_info_idx_cache} = shift @$tia;
1802 }
1803  
1804 28 ▶ my $dt_idx = $idx_hash->{DATA_TYPE} || $idx_hash->{data_type};
Condition33%1/3
$idx_hash->{'DATA_TYPE'} || $idx_hash->{'data_type'}
l!l&&r!l&&!r
2800
MC/DC0%0/2
$idx_hash->{'DATA_TYPE'} || $idx_hash->{'data_type'}
$idx_hash->{'DATA_TYPE'} $idx_hash->{'data_type'}
Truth table33%1/3
A || B
A= $idx_hash->{'DATA_TYPE'}B= $idx_hash->{'data_type'}
ABresult
1X1
011
000
1805 28 ▶ Carp::croak("type_info_all returned non-standard DATA_TYPE index value ($dt_idx != 1)")
Branch: 1 branch
BranchTrueFalseTotal
if $dt_idx and $dt_idx != 1 0 28 28
Condition33%1/3
$dt_idx and $dt_idx != 1
!ll&&!rl&&r
0280
MC/DC0%0/2
$dt_idx and $dt_idx != 1
$dt_idx $dt_idx != 1
Truth table33%1/3
A and B
A= $dt_idxB= $dt_idx != 1
ABresult
0X0
100
111
1806 if $dt_idx && $dt_idx != 1;
1807  
1808 # --- simple DATA_TYPE match filter
1809 28 my @ti;
1810 28 ▶ my @data_type_list = (ref $data_type) ? @$data_type : ($data_type);
Branch: 1 branch
BranchTrueFalseTotal
ref $data_type ? : 0 28 28
1811 28 foreach $data_type (@data_type_list) {
1812 28 ▶ if (defined($data_type) && $data_type != DBI::SQL_ALL_TYPES()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data_type and $data_type != &DBI::SQL_ALL_TYPES()) { } 24 4 28
Condition66%2/3
defined $data_type and $data_type != &DBI::SQL_ALL_TYPES()
!ll&&!rl&&r
4024
MC/DC50%1/2
defined $data_type and $data_type != &DBI::SQL_ALL_TYPES()
defined $data_type $data_type != &DBI::SQL_ALL_TYPES()
Truth table66%2/3
A and B
A= defined $data_typeB= $data_type != &DBI::SQL_ALL_TYPES()
ABresult
0X0
100
111
1813 24 push @ti, grep { $_->[$dt_idx] == $data_type } @$tia;
1814 }
1815 else { # SQL_ALL_TYPES
1816 4 push @ti, @$tia;
1817 }
1818 28 ▶ last if @ti; # found at least one match
Branch: 1 branch
BranchTrueFalseTotal
if @ti 28 0 28
1819 }
1820  
1821 # --- format results into list of hash refs
1822 28 my $idx_fields = keys %$idx_hash;
1823 28 my @idx_names = map { uc($_) } keys %$idx_hash;
1824 28 my @idx_values = values %$idx_hash;
1825 0 Carp::croak "type_info_all result has $idx_fields keys but ".(@{$ti[0]})." fields"
1826 28 ▶ if @ti && @{$ti[0]} != $idx_fields;
Branch: 1 branch
BranchTrueFalseTotal
if @ti and @{$ti[0];} != $idx_fields 0 28 28
Condition33%1/3
@ti and @{$ti[0];} != $idx_fields
!ll&&!rl&&r
0280
MC/DC0%0/2
@ti and @{$ti[0];} != $idx_fields
@ti @{$ti[0];} != $idx_fields
Truth table33%1/3
A and B
A= @tiB= @{$ti[0];} != $idx_fields
ABresult
0X0
100
111
1827 my @out = map {
1828 28 my %h; @h{@idx_names} = @{$_}[ @idx_values ]; \%h;
1829 } @ti;
1830 28 ▶ return $out[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 24 4 28
1831 4 return @out;
1832 }
1833  
1834 4 ▶ sub data_sources {
Subroutine data_sources: called CC=1 SCAR=0.0
1835 4 my ($dbh, @other) = @_;
1836 4 my $drh = $dbh->{Driver}; # XXX proxy issues?
1837 4 return $drh->data_sources(@other);
1838 }
1839  
1840 }
1841  
1842  
1843 214 { package # hide from PAUSE
1844 DBD::_::st; # ====== STATEMENT ======
1845 214 our @ISA = qw(DBD::_::common);
1846 214 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1847  
1848 0 ▶ sub bind_param { Carp::croak("Can't bind_param, not implement by driver") }
Subroutine bind_param: not called CC=1 SCAR=6.9
1849  
1850 #
1851 # ********************************************************
1852 #
1853 # BEGIN ARRAY BINDING
1854 #
1855 # Array binding support for drivers which don't support
1856 # array binding, but have sufficient interfaces to fake it.
1857 # NOTE: mixing scalars and arrayrefs requires using bind_param_array
1858 # for *all* params...unless we modify bind_param for the default
1859 # case...
1860 #
1861 # 2002-Apr-10 D. Arnold
1862  
1863 84 ▶ sub bind_param_array {
Subroutine bind_param_array: called CC=8 SCAR=20.9
1864 84 my $sth = shift;
1865 84 my ($p_id, $value_array, $attr) = @_;
1866  
1867 84 ▶ return $sth->set_err($DBI::stderr, "Value for parameter $p_id must be a scalar or an arrayref, not a ".ref($value_array))
Branch: 1 branch
BranchTrueFalseTotal
if defined $value_array and ref $value_array and ref $value_array ne "ARRAY" 4 80 84
Condition100%6/6
defined $value_array and ref $value_array and ref $value_array ne "ARRAY"
!ll&&!rl&&r
40404
defined $value_array and ref $value_array
!ll&&!rl&&r
43644
MC/DC100%3/3
defined $value_array and ref $value_array and ref $value_array ne "ARRAY"
defined $value_array ref $value_array ref $value_array ne "ARRAY"
Truth table100%4/4
A and B and C
A= defined $value_arrayB= ref $value_arrayC= ref $value_array ne "ARRAY"
ABCresult
0XX0
10X0
1100
1111
1868 if defined $value_array and ref $value_array and ref $value_array ne 'ARRAY';
1869  
1870 80 ▶ return $sth->set_err($DBI::stderr, "Can't use named placeholder '$p_id' for non-driver supported bind_param_array")
Branch: 1 branch
BranchTrueFalseTotal
unless DBI::looks_like_number($p_id) 4 76 80
1871 unless DBI::looks_like_number($p_id); # because we rely on execute(@ary) here
1872  
1873 76 ▶ return $sth->set_err($DBI::stderr, "Placeholder '$p_id' is out of range")
Branch: 1 branch
BranchTrueFalseTotal
if $p_id <= 0 0 76 76
1874 if $p_id <= 0; # can't easily/reliably test for too big
1875  
1876 # get/create arrayref to hold params
1877 76 ▶ my $hash_of_arrays = $sth->{ParamArrays} ||= { };
Condition50%1/2
$sth->{"ParamArrays"} ||= {}
l!l
760
MC/DC0%0/1
$sth->{"ParamArrays"} ||= {}
$sth->{"ParamArrays"}
Truth table50%1/2
A
A= $sth->{"ParamArrays"}
Aresult
11
00
1878  
1879 # If the bind has attribs then we rely on the driver conforming to
1880 # the DBI spec in that a single bind_param() call with those attribs
1881 # makes them 'sticky' and apply to all later execute(@values) calls.
1882 # Since we only call bind_param() if we're given attribs then
1883 # applications using drivers that don't support bind_param can still
1884 # use bind_param_array() so long as they don't pass any attribs.
1885  
1886 76 $$hash_of_arrays{$p_id} = $value_array;
1887 76 ▶ return $sth->bind_param($p_id, undef, $attr)
Branch: 1 branch
BranchTrueFalseTotal
if $attr 0 76 76
1888 if $attr;
1889 76 1;
1890 }
1891  
1892 0 ▶ sub bind_param_inout_array {
Subroutine bind_param_inout_array: not called CC=1 SCAR=6.9
1893 0 my $sth = shift;
1894 # XXX not supported so we just call bind_param_array instead
1895 # and then return an error
1896 0 my ($p_num, $value_array, $attr) = @_;
1897 0 $sth->bind_param_array($p_num, $value_array, $attr);
1898 0 return $sth->set_err($DBI::stderr, "bind_param_inout_array not supported");
1899 }
1900  
1901 116 ▶ sub bind_columns {
Subroutine bind_columns: called CC=11 SCAR=24.9
1902 116 my $sth = shift;
1903 116 ▶ my $fields = $sth->FETCH('NUM_OF_FIELDS') || 0;
Condition50%1/2
$sth->FETCH('NUM_OF_FIELDS') || 0
l!l
1160
MC/DC0%0/1
$sth->FETCH('NUM_OF_FIELDS') || 0
$sth->FETCH('NUM_OF_FIELDS')
Truth table50%1/2
A
A= $sth->FETCH('NUM_OF_FIELDS')
Aresult
11
00
1904 116 ▶ if ($fields <= 0 && !$sth->{Active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields <= 0 and not $sth->{"Active"}) 0 116 116
Condition33%1/3
$fields <= 0 and not $sth->{"Active"}
!ll&&!rl&&r
11600
MC/DC0%0/2
$fields <= 0 and not $sth->{"Active"}
$fields <= 0 not $sth->{"Active"}
Truth table33%1/3
A and not(B)
A= $fields <= 0B= not $sth->{"Active"}
ABresult
0X0
100
111
1905 0 return $sth->set_err($DBI::stderr, "Statement has no result columns to bind"
1906 ." (perhaps you need to successfully call execute first, or again)");
1907 }
1908 # Backwards compatibility for old-style call with attribute hash
1909 # ref as first arg. Skip arg if undef or a hash ref.
1910 116 my $attr;
1911 116 ▶ $attr = shift if !defined $_[0] or ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] or ref $_[0] eq "HASH" 12 104 116
Condition66%2/3
not defined $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
120104
MC/DC50%1/2
not defined $_[0] or ref $_[0] eq "HASH"
not defined $_[0] ref $_[0] eq "HASH"
Truth table66%2/3
not(A) or B
A= not defined $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
1912  
1913 116 my $idx = 0;
1914 116 ▶ $sth->bind_col(++$idx, shift, $attr) or return
Branch: 2 branches
BranchTrueFalseTotal
@_ and $idx < $fields and do { $sth->bind_col(++$idx, shift(), $attr) or return } 272 116 388
$sth->bind_col(++$idx, shift(), $attr) or return 272 0 272
Condition100%3/3
@_ and $idx < $fields
!ll&&!rl&&r
1124272
MC/DC100%2/2
@_ and $idx < $fields
@_ $idx < $fields
Truth table100%3/3
A and B
A= @_B= $idx < $fields
ABresult
0X0
100
111
1915 while (@_ and $idx < $fields);
1916  
1917 116 ▶ return $sth->set_err($DBI::stderr, "bind_columns called with ".($idx+@_)." values but $fields are needed")
Branch: 1 branch
BranchTrueFalseTotal
if @_ or $idx != $fields 8 108 116
Condition100%3/3
@_ or $idx != $fields
l!l&&r!l&&!r
44108
MC/DC100%2/2
@_ or $idx != $fields
@_ $idx != $fields
Truth table100%3/3
A or B
A= @_B= $idx != $fields
ABresult
1X1
011
000
1918 if @_ or $idx != $fields;
1919  
1920 108 return 1;
1921 }
1922  
1923 48 ▶ sub execute_array {
Subroutine execute_array: called CC=24 SCAR=32.7
1924 48 my $sth = shift;
1925 48 my ($attr, @array_of_arrays) = @_;
1926 48 my $NUM_OF_PARAMS = $sth->FETCH('NUM_OF_PARAMS'); # may be undef at this point
1927  
1928 # get tuple status array or hash attribute
1929 48 my $tuple_sts = $attr->{ArrayTupleStatus};
1930 48 ▶ return $sth->set_err($DBI::stderr, "ArrayTupleStatus attribute must be an arrayref")
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_sts and ref $tuple_sts ne "ARRAY" 4 44 48
Condition100%3/3
$tuple_sts and ref $tuple_sts ne "ARRAY"
!ll&&!rl&&r
4404
MC/DC100%2/2
$tuple_sts and ref $tuple_sts ne "ARRAY"
$tuple_sts ref $tuple_sts ne "ARRAY"
Truth table100%3/3
A and B
A= $tuple_stsB= ref $tuple_sts ne "ARRAY"
ABresult
0X0
100
111
1931 if $tuple_sts and ref $tuple_sts ne 'ARRAY';
1932  
1933 # bind all supplied arrays
1934 44 ▶ if (@array_of_arrays) {
Branch: 1 branch
BranchTrueFalseTotal
if (@array_of_arrays) 28 16 44
1935 28 $sth->{ParamArrays} = { }; # clear out old params
1936 28 ▶ return $sth->set_err($DBI::stderr,
Branch: 1 branch
BranchTrueFalseTotal
if defined $NUM_OF_PARAMS and @array_of_arrays != $NUM_OF_PARAMS 4 24 28
Condition66%2/3
defined $NUM_OF_PARAMS and @array_of_arrays != $NUM_OF_PARAMS
!ll&&!rl&&r
0244
MC/DC50%1/2
defined $NUM_OF_PARAMS and @array_of_arrays != $NUM_OF_PARAMS
defined $NUM_OF_PARAMS @array_of_arrays != $NUM_OF_PARAMS
Truth table66%2/3
A and B
A= defined $NUM_OF_PARAMSB= @array_of_arrays != $NUM_OF_PARAMS
ABresult
0X0
100
111
1937 @array_of_arrays." bind values supplied but $NUM_OF_PARAMS expected")
1938 if defined ($NUM_OF_PARAMS) && @array_of_arrays != $NUM_OF_PARAMS;
1939 $sth->bind_param_array($_, $array_of_arrays[$_-1]) or return
1940 24 ▶ foreach (1..@array_of_arrays);
Branch: 1 branch
BranchTrueFalseTotal
$sth->bind_param_array($_, $array_of_arrays[$_ - 1]) or return 72 4 76
1941 }
1942  
1943 36 my $fetch_tuple_sub;
1944  
1945 36 ▶ if ($fetch_tuple_sub = $attr->{ArrayTupleFetch}) { # fetch on demand
Branch: 1 branch
BranchTrueFalseTotal
if ($fetch_tuple_sub = $attr->{'ArrayTupleFetch'}) { } 8 28 36
1946  
1947 8 ▶ return $sth->set_err($DBI::stderr,
Branch: 1 branch
BranchTrueFalseTotal
if @array_of_arrays 0 8 8
1948 "Can't use both ArrayTupleFetch and explicit bind values")
1949 if @array_of_arrays; # previous bind_param_array calls will simply be ignored
1950  
1951 8 ▶ if (UNIVERSAL::isa($fetch_tuple_sub,'DBI::st')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($fetch_tuple_sub, 'DBI::st')) { } 4 4 8
elsif (not UNIVERSAL::isa($fetch_tuple_sub, 'CODE')) { } 0 4 4
1952 4 my $fetch_sth = $fetch_tuple_sub;
1953 return $sth->set_err($DBI::stderr,
1954 "ArrayTupleFetch sth is not Active, need to execute() it first")
1955 4 ▶ unless $fetch_sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
unless $fetch_sth->{"Active"} 0 4 4
1956 # check column count match to give more friendly message
1957 4 my $NUM_OF_FIELDS = $fetch_sth->{NUM_OF_FIELDS};
1958 4 ▶ return $sth->set_err($DBI::stderr,
Branch: 1 branch
BranchTrueFalseTotal
if defined $NUM_OF_FIELDS and defined $NUM_OF_PARAMS and $NUM_OF_FIELDS != $NUM_OF_PARAMS 0 4 4
Condition33%2/6
defined $NUM_OF_FIELDS and defined $NUM_OF_PARAMS and $NUM_OF_FIELDS != $NUM_OF_PARAMS
!ll&&!rl&&r
040
defined $NUM_OF_FIELDS and defined $NUM_OF_PARAMS
!ll&&!rl&&r
004
MC/DC0%0/3
defined $NUM_OF_FIELDS and defined $NUM_OF_PARAMS and $NUM_OF_FIELDS != $NUM_OF_PARAMS
defined $NUM_OF_FIELDS defined $NUM_OF_PARAMS $NUM_OF_FIELDS != $NUM_OF_PARAMS
Truth table25%1/4
A and B and C
A= defined $NUM_OF_FIELDSB= defined $NUM_OF_PARAMSC= $NUM_OF_FIELDS != $NUM_OF_PARAMS
ABCresult
0XX0
10X0
1100
1111
1959 "$NUM_OF_FIELDS columns from ArrayTupleFetch sth but $NUM_OF_PARAMS expected")
1960 if defined($NUM_OF_FIELDS) && defined($NUM_OF_PARAMS)
1961 && $NUM_OF_FIELDS != $NUM_OF_PARAMS;
1962 4 ▶ $fetch_tuple_sub = sub { $fetch_sth->fetchrow_arrayref };
Subroutine __ANON__: called CC=1 SCAR=0.0
1963 }
1964 elsif (!UNIVERSAL::isa($fetch_tuple_sub,'CODE')) {
1965 0 return $sth->set_err($DBI::stderr, "ArrayTupleFetch '$fetch_tuple_sub' is not a code ref or statement handle");
1966 }
1967  
1968 }
1969 else {
1970 28 ▶ my $NUM_OF_PARAMS_given = keys %{ $sth->{ParamArrays} || {} };
Condition50%1/2
$sth->{'ParamArrays'} || {}
l!l
280
MC/DC0%0/1
$sth->{'ParamArrays'} || {}
$sth->{'ParamArrays'}
Truth table50%1/2
A
A= $sth->{'ParamArrays'}
Aresult
11
00
1971 28 ▶ return $sth->set_err($DBI::stderr,
Branch: 1 branch
BranchTrueFalseTotal
if defined $NUM_OF_PARAMS and $NUM_OF_PARAMS != $NUM_OF_PARAMS_given 0 28 28
Condition33%1/3
defined $NUM_OF_PARAMS and $NUM_OF_PARAMS != $NUM_OF_PARAMS_given
!ll&&!rl&&r
0280
MC/DC0%0/2
defined $NUM_OF_PARAMS and $NUM_OF_PARAMS != $NUM_OF_PARAMS_given
defined $NUM_OF_PARAMS $NUM_OF_PARAMS != $NUM_OF_PARAMS_given
Truth table33%1/3
A and B
A= defined $NUM_OF_PARAMSB= $NUM_OF_PARAMS != $NUM_OF_PARAMS_given
ABresult
0X0
100
111
1972 "$NUM_OF_PARAMS_given bind values supplied but $NUM_OF_PARAMS expected")
1973 if defined($NUM_OF_PARAMS) && $NUM_OF_PARAMS != $NUM_OF_PARAMS_given;
1974  
1975 # get the length of a bound array
1976 28 my $maxlen;
1977 28 my %hash_of_arrays = %{$sth->{ParamArrays}};
1978 28 foreach (keys(%hash_of_arrays)) {
1979 100 my $ary = $hash_of_arrays{$_};
1980 100 ▶ next unless ref $ary eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ary eq "ARRAY" 52 48 100
1981 48 ▶ $maxlen = @$ary if !$maxlen || @$ary > $maxlen;
Branch: 1 branch
BranchTrueFalseTotal
if not $maxlen or @$ary > $maxlen 36 12 48
Condition66%2/3
not $maxlen or @$ary > $maxlen
l!l&&r!l&&!r
36012
MC/DC50%1/2
not $maxlen or @$ary > $maxlen
not $maxlen @$ary > $maxlen
Truth table66%2/3
not(A) or B
A= not $maxlenB= @$ary > $maxlen
ABresult
1X1
011
000
1982 }
1983 # if there are no arrays then execute scalars once
1984 28 ▶ $maxlen //= 1;
Condition100%2/2
$maxlen //= 1
l!l
244
MC/DC100%1/1
$maxlen //= 1
$maxlen
Truth table100%2/2
A
A= $maxlen
Aresult
11
00
1985 28 my @bind_ids = 1..keys(%hash_of_arrays);
1986  
1987 28 my $tuple_idx = 0;
1988 68 ▶ $fetch_tuple_sub = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1989 68 ▶ return if $tuple_idx >= $maxlen;
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_idx >= $maxlen 28 40 68
1990 my @tuple = map {
1991 40 my $a = $hash_of_arrays{$_};
1992 160 ▶ ref($a) ? $a->[$tuple_idx] : $a
Branch: 1 branch
BranchTrueFalseTotal
ref $a ? : 72 88 160
1993 } @bind_ids;
1994 40 ++$tuple_idx;
1995 40 return \@tuple;
1996 28 };
1997 }
1998 # pass thru the callers scalar or list context
1999 36 return $sth->execute_for_fetch($fetch_tuple_sub, $tuple_sts);
2000 }
2001  
2002 36 ▶ sub execute_for_fetch {
Subroutine execute_for_fetch: called CC=9 SCAR=22.0
2003 36 my ($sth, $fetch_tuple_sub, $tuple_status) = @_;
2004 # start with empty status array
2005 36 ▶ ($tuple_status) ? @$tuple_status = () : $tuple_status = [];
Branch: 1 branch
BranchTrueFalseTotal
$tuple_status ? : 32 4 36
2006  
2007 36 my $rc_total = 0;
2008 36 my $err_count;
2009 36 ▶ while ( my $tuple = &$fetch_tuple_sub() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tuple = &$fetch_tuple_sub()) 60 36 96
2010 60 ▶ if ( my $rc = $sth->execute(@$tuple) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = $sth->execute(@$tuple)) { } 56 4 60
2011 56 push @$tuple_status, $rc;
2012 56 ▶ $rc_total = ($rc >= 0 && $rc_total >= 0) ? $rc_total + $rc : -1;
Branch: 1 branch
BranchTrueFalseTotal
$rc >= 0 && $rc_total >= 0 ? : 56 0 56
Condition33%1/3
$rc >= 0 and $rc_total >= 0
!ll&&!rl&&r
0056
MC/DC0%0/2
$rc >= 0 and $rc_total >= 0
$rc >= 0 $rc_total >= 0
Truth table33%1/3
A and B
A= $rc >= 0B= $rc_total >= 0
ABresult
0X0
100
111
2013 }
2014 else {
2015 4 $err_count++;
2016 4 push @$tuple_status, [ $sth->err, $sth->errstr, $sth->state ];
2017 # XXX drivers implementing execute_for_fetch could opt to "last;" here
2018 # if they know the error code means no further executes will work.
2019 }
2020 }
2021 36 my $tuples = @$tuple_status;
2022 36 ▶ return $sth->set_err($DBI::stderr, "executing $tuples generated $err_count errors")
Branch: 1 branch
BranchTrueFalseTotal
if $err_count 4 32 36
2023 if $err_count;
2024 32 ▶ $tuples ||= "0E0";
Condition100%2/2
$tuples ||= "0E0"
l!l
2012
MC/DC100%1/1
$tuples ||= "0E0"
$tuples
Truth table100%2/2
A
A= $tuples
Aresult
11
00
2025 32 ▶ return $tuples unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 28 4 32
2026 4 return ($tuples, $rc_total);
2027 }
2028  
2029 0 ▶ sub last_insert_id {
Subroutine last_insert_id: not called CC=1 SCAR=6.9
2030 0 return shift->{Database}->last_insert_id(@_);
2031 }
2032  
2033 2394 ▶ sub fetchall_arrayref { # ALSO IN Driver.xst
Subroutine fetchall_arrayref: called CC=27 SCAR=33.2
2034 2394 my ($sth, $slice, $max_rows) = @_;
2035  
2036 # when batch fetching with $max_rows were very likely to try to
2037 # fetch the 'next batch' after the previous batch returned
2038 # <=$max_rows. So don't treat that as an error.
2039 2394 ▶ return undef if $max_rows and not $sth->FETCH('Active');
Branch: 1 branch
BranchTrueFalseTotal
if $max_rows and not $sth->FETCH("Active") 4 2390 2394
Condition100%3/3
$max_rows and not $sth->FETCH("Active")
!ll&&!rl&&r
2378124
MC/DC100%2/2
$max_rows and not $sth->FETCH("Active")
$max_rows not $sth->FETCH("Active")
Truth table100%3/3
A and not(B)
A= $max_rowsB= not $sth->FETCH("Active")
ABresult
0X0
100
111
2040  
2041 2390 ▶ my $mode = ref($slice) || 'ARRAY';
Condition100%2/2
ref $slice || 'ARRAY'
l!l
562334
MC/DC100%1/1
ref $slice || 'ARRAY'
ref $slice
Truth table100%2/2
A
A= ref $slice
Aresult
11
00
2042 2390 my @rows;
2043  
2044 2390 ▶ if ($mode eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "ARRAY") 2358 32 2390
2045 2358 my $row;
2046 # we copy the array here because fetch (currently) always
2047 # returns the same array ref. XXX
2048 2358 ▶ if ($slice && @$slice) {
Branch: 2 branches
BranchTrueFalseTotal
if ($slice and @$slice) { } 16 2342 2358
elsif (defined $max_rows) { } 8 2334 2342
Condition100%3/3
$slice and @$slice
!ll&&!rl&&r
2334816
MC/DC100%2/2
$slice and @$slice
$slice @$slice
Truth table100%3/3
A and B
A= $sliceB= @$slice
ABresult
0X0
100
111
2049 16 ▶ $max_rows //= -1;
Condition100%2/2
$max_rows //= -1
l!l
412
MC/DC100%1/1
$max_rows //= -1
$max_rows
Truth table100%2/2
A
A= $max_rows
Aresult
11
00
2050 16 ▶ push @rows, [ @{$row}[ @$slice] ]
Branch: 1 branch
BranchTrueFalseTotal
$max_rows-- and $row = $sth->fetch and do { push @rows, [@{$row;}[@$slice]] } 40 16 56
Condition100%3/3
$max_rows-- and $row = $sth->fetch
!ll&&!rl&&r
41240
MC/DC100%2/2
$max_rows-- and $row = $sth->fetch
$max_rows-- $row = $sth->fetch
Truth table100%3/3
A and B
A= $max_rows--B= $row = $sth->fetch
ABresult
0X0
100
111
2051 while($max_rows-- and $row = $sth->fetch);
2052 }
2053 elsif (defined $max_rows) {
2054 8 ▶ push @rows, [ @$row ]
Branch: 1 branch
BranchTrueFalseTotal
$max_rows-- and $row = $sth->fetch and do { push @rows, [@$row] } 8 8 16
Condition100%3/3
$max_rows-- and $row = $sth->fetch
!ll&&!rl&&r
448
MC/DC100%2/2
$max_rows-- and $row = $sth->fetch
$max_rows-- $row = $sth->fetch
Truth table100%3/3
A and B
A= $max_rows--B= $row = $sth->fetch
ABresult
0X0
100
111
2055 while($max_rows-- and $row = $sth->fetch);
2056 }
2057 else {
2058 2334 ▶ push @rows, [ @$row ] while($row = $sth->fetch);
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @rows, [@$row] } 98085 2333 100418
2059 }
2060 return \@rows
2061 2357 }
2062  
2063 32 my %row;
2064 32 ▶ if ($mode eq 'REF' && ref($$slice) eq 'HASH') { # \{ $idx => $name }
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'REF' and ref $$slice eq 'HASH') { } 12 20 32
elsif ($mode eq 'HASH') { } 16 4 20
Condition100%3/3
$mode eq "REF" and ref $$slice eq "HASH"
!ll&&!rl&&r
16412
MC/DC100%2/2
$mode eq "REF" and ref $$slice eq "HASH"
$mode eq "REF" ref $$slice eq "HASH"
Truth table100%3/3
A and B
A= $mode eq "REF"B= ref $$slice eq "HASH"
ABresult
0X0
100
111
2065 12 keys %$$slice; # reset the iterator
2066 12 ▶ while ( my ($idx, $name) = each %$$slice ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$$slice) 12 8 20
2067 12 $sth->bind_col($idx+1, \$row{$name});
2068 }
2069 }
2070 elsif ($mode eq 'HASH') {
2071 16 ▶ if (keys %$slice) { # resets the iterator
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$slice) { } 12 4 16
2072 12 my $name2idx = $sth->FETCH('NAME_lc_hash');
2073 12 ▶ while ( my ($name, $unused) = each %$slice ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$slice) 20 8 28
2074 20 my $idx = $name2idx->{lc $name};
2075 20 ▶ return $sth->set_err($DBI::stderr, "Invalid column name '$name' for slice")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $idx 4 16 20
2076 if not defined $idx;
2077 16 $sth->bind_col($idx+1, \$row{$name});
2078 }
2079 }
2080 else {
2081 4 ▶ my @column_names = @{ $sth->FETCH($sth->FETCH('FetchHashKeyName')) || [] };
Condition50%1/2
$sth->FETCH($sth->FETCH('FetchHashKeyName')) || []
l!l
40
MC/DC0%0/1
$sth->FETCH($sth->FETCH('FetchHashKeyName')) || []
$sth->FETCH($sth->FETCH('FetchHashKeyName'))
Truth table50%1/2
A
A= $sth->FETCH($sth->FETCH('FetchHashKeyName'))
Aresult
11
00
2082 4 ▶ return [] if !@column_names;
Branch: 1 branch
BranchTrueFalseTotal
unless @column_names 0 4 4
2083  
2084 4 $sth->bind_columns( \( @row{@column_names} ) );
2085 }
2086 }
2087 else {
2088 4 return $sth->set_err($DBI::stderr, "fetchall_arrayref($mode) invalid");
2089 }
2090  
2091 20 ▶ if (not defined $max_rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $max_rows) { } 20 0 20
2092 20 ▶ push @rows, { %row } while ($sth->fetch); # full speed ahead!
Branch: 1 branch
BranchTrueFalseTotal
$sth->fetch and do { push @rows, {%row} } 60 20 80
2093 }
2094 else {
2095 0 ▶ push @rows, { %row } while ($max_rows-- and $sth->fetch);
Branch: 1 branch
BranchTrueFalseTotal
$max_rows-- and $sth->fetch and do { push @rows, {%row} } 0 0 0
Condition0%0/3
$max_rows-- and $sth->fetch
!ll&&!rl&&r
000
MC/DC0%0/2
$max_rows-- and $sth->fetch
$max_rows-- $sth->fetch
Truth table0%0/3
A and B
A= $max_rows--B= $sth->fetch
ABresult
0X0
100
111
2096 }
2097  
2098 20 return \@rows;
2099 }
2100  
2101 96 ▶ sub fetchall_hashref {
Subroutine fetchall_hashref: called CC=12 SCAR=25.2
2102 96 my ($sth, $key_field) = @_;
2103  
2104 96 ▶ my $hash_key_name = $sth->{FetchHashKeyName} || 'NAME';
Condition50%1/2
$sth->{'FetchHashKeyName'} || 'NAME'
l!l
960
MC/DC0%0/1
$sth->{'FetchHashKeyName'} || 'NAME'
$sth->{'FetchHashKeyName'}
Truth table50%1/2
A
A= $sth->{'FetchHashKeyName'}
Aresult
11
00
2105 96 my $names_hash = $sth->FETCH("${hash_key_name}_hash");
2106 96 ▶ my @key_fields = (ref $key_field) ? @$key_field : ($key_field);
Branch: 1 branch
BranchTrueFalseTotal
ref $key_field ? : 8 88 96
2107 96 my @key_indexes;
2108 96 my $num_of_fields = $sth->FETCH('NUM_OF_FIELDS');
2109 96 foreach (@key_fields) {
2110 100 my $index = $names_hash->{$_}; # perl index not column
2111 100 ▶ $index = $_ - 1 if !defined $index && DBI::looks_like_number($_) && $_>=1 && $_ <= $num_of_fields;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $index and DBI::looks_like_number($_) and $_ >= 1 and $_ <= $num_of_fields 4 96 100
Condition66%6/9
not defined $index and DBI::looks_like_number($_) and $_ >= 1 and $_ <= $num_of_fields
!ll&&!rl&&r
9604
not defined $index and DBI::looks_like_number($_) and $_ >= 1
!ll&&!rl&&r
9604
not defined $index and DBI::looks_like_number($_)
!ll&&!rl&&r
9604
MC/DC25%1/4
not defined $index and DBI::looks_like_number($_) and $_ >= 1 and $_ <= $num_of_fields
not defined $index DBI::looks_like_number($_) $_ >= 1 $_ <= $num_of_fields
Truth table40%2/5
not(A) and B and C and D
A= not defined $indexB= DBI::looks_like_number($_)C= $_ >= 1D= $_ <= $num_of_fields
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2112 0 ▶ return $sth->set_err($DBI::stderr, "Field '$_' does not exist (not one of @{[keys %$names_hash]})")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 100 100
2113 unless defined $index;
2114 100 push @key_indexes, $index;
2115 }
2116 96 my $rows = {};
2117 96 my $NAME = $sth->FETCH($hash_key_name);
2118 96 my @row = (undef) x $num_of_fields;
2119 96 $sth->bind_columns(\(@row));
2120 96 ▶ while ($sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 248 96 344
2121 248 my $ref = $rows;
2122 248 ▶ $ref = $ref->{$row[$_]} ||= {} for @key_indexes;
Condition100%2/2
$$ref{$row[$_]} ||= {}
l!l
16252
MC/DC100%1/1
$$ref{$row[$_]} ||= {}
$$ref{$row[$_]}
Truth table100%2/2
A
A= $$ref{$row[$_]}
Aresult
11
00
2123 248 @{$ref}{@$NAME} = @row;
2124 }
2125 96 return $rows;
2126 }
2127  
2128 214 *dump_results = \&DBI::dump_results;
2129  
2130 0 ▶ sub blob_copy_to_file { # returns length or undef on error
Subroutine blob_copy_to_file: not called CC=5 SCAR=34.0
2131 0 my($self, $field, $filename_or_handleref, $blocksize) = @_;
2132 0 my $fh = $filename_or_handleref;
2133 0 my($len, $buf) = (0, "");
2134 0 ▶ $blocksize ||= 512; # not too ambitious
Condition0%0/2
$blocksize ||= 512
l!l
00
MC/DC0%0/1
$blocksize ||= 512
$blocksize
Truth table0%0/2
A
A= $blocksize
Aresult
11
00
2135 0 local(*FH);
2136 0 ▶ unless(ref $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fh) 0 0 0
2137 0 ▶ open(FH, ">$fh") || return undef;
Branch: 1 branch
BranchTrueFalseTotal
open FH, ">$fh" or return undef 0 0 0
2138 0 $fh = \*FH;
2139 }
2140 0 ▶ while(defined($self->blob_read($field, $len, $blocksize, \$buf))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->blob_read($field, $len, $blocksize, \$buf)) 0 0 0
2141 0 print $fh $buf;
2142 0 $len += length $buf;
2143 }
2144 0 close(FH);
2145 0 $len;
2146 }
2147  
2148 2483 ▶ sub more_results {
Subroutine more_results: called CC=1 SCAR=0.0
2149 2483 shift->{syb_more_results}; # handy grandfathering
2150 }
2151  
2152 }
2153  
2154 214 ▶unless ($DBI::PurePerl) { # See install_driver
Branch: 1 branch
BranchTrueFalseTotal
unless ($DBI::PurePerl) 107 107 214
2155 107 { @DBD::_mem::dr::ISA = qw(DBD::_mem::common); }
2156 107 { @DBD::_mem::db::ISA = qw(DBD::_mem::common); }
2157 107 { @DBD::_mem::st::ISA = qw(DBD::_mem::common); }
2158 # DBD::_mem::common::DESTROY is implemented in DBI.xs
2159 }
2160  
2161 214 1;
2162 __END__
« blib/lib/DBI/Const/GetInfoReturn.pm ↑ Summary blib/lib/DBI/DBD.pm »