DBIx/Class/Storage/DBI.pm

filter: Statementstmt 75.2% 567 / 754 Branchbran 64.0% 242 / 378 Conditioncond 55.3% 176 / 318 MC/DCmcdc 31.8% 56 / 176 Subroutinesub 78.6% 107 / 136 Podpod 81.4% 22 / 27 totaltotal 65.4% 1170 / 1789 CC 401 SCAR 44.3
CC
401
Cov
68%
create_ddl_dir
1056.0
_insert_bulk
243.0
_max_column_bytesize
110.0
CRAP 83.7
« DBIx/Class/Storage/DBI/Oracle/Generic.pm ↑ Summary DBIx/Class/Storage/DBI/Sybase/ASE.pm »
1 package DBIx::Class::Storage::DBI;
2 # -*- mode: cperl; cperl-indent-level: 2 -*-
3  
4 266 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 266 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 266 ▶use base qw/DBIx::Class::Storage::DBIHacks DBIx::Class::Storage/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 266 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 266 ▶use DBIx::Class::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 266 ▶use Scalar::Util qw/refaddr weaken reftype blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 266 ▶use Context::Preserve 'preserve_context';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 266 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 266 ▶use SQL::Abstract::Util qw(is_plain_value is_literal_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 266 ▶use DBIx::Class::_Util qw(quote_sub perlstring serialize detected_reinvoked_destructor sigwarn_silencer);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 266 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # default cursor class, overridable in connect_info attributes
19 266 __PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor');
20  
21 266 __PACKAGE__->mk_group_accessors('inherited' => qw/
22 sql_limit_dialect sql_quote_char sql_name_sep
23 /);
24  
25 266 __PACKAGE__->mk_group_accessors('component_class' => qw/sql_maker_class datetime_parser_type/);
26  
27 266 __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker');
28 266 __PACKAGE__->datetime_parser_type('DateTime::Format::MySQL'); # historic default
29  
30 266 __PACKAGE__->sql_name_sep('.');
31  
32 266 __PACKAGE__->mk_group_accessors('simple' => qw/
33 _connect_info _dbic_connect_attributes _driver_determined
34 _dbh _dbh_details _conn_pid _sql_maker _sql_maker_opts _dbh_autocommit
35 _perform_autoinc_retrieval _autoinc_supplied_for_op
36 /);
37  
38 # the values for these accessors are picked out (and deleted) from
39 # the attribute hashref passed to connect_info
40 266 my @storage_options = qw/
41 on_connect_call on_disconnect_call on_connect_do on_disconnect_do
42 disable_sth_caching unsafe auto_savepoint
43 /;
44 266 __PACKAGE__->mk_group_accessors('simple' => @storage_options);
45  
46  
47 # capability definitions, using a 2-tiered accessor system
48 # The rationale is:
49 #
50 # A driver/user may define _use_X, which blindly without any checks says:
51 # "(do not) use this capability", (use_dbms_capability is an "inherited"
52 # type accessor)
53 #
54 # If _use_X is undef, _supports_X is then queried. This is a "simple" style
55 # accessor, which in turn calls _determine_supports_X, and stores the return
56 # in a special slot on the storage object, which is wiped every time a $dbh
57 # reconnection takes place (it is not guaranteed that upon reconnection we
58 # will get the same rdbms version). _determine_supports_X does not need to
59 # exist on a driver, as we ->can for it before calling.
60  
61 266 my @capabilities = (qw/
62 insert_returning
63 insert_returning_bound
64  
65 multicolumn_in
66  
67 placeholders
68 typeless_placeholders
69  
70 join_optimizer
71 /);
72 266 __PACKAGE__->mk_group_accessors( dbms_capability => map { "_supports_$_" } @capabilities );
73 266 __PACKAGE__->mk_group_accessors( use_dbms_capability => map { "_use_$_" } (@capabilities ) );
74  
75 # on by default, not strictly a capability (pending rewrite)
76 266 __PACKAGE__->_use_join_optimizer (1);
77 0 ▶sub _determine_supports_join_optimizer { 1 };
Subroutine _determine_supports_join_optimizer: not called CC=1 SCAR=6.9
78  
79 # Each of these methods need _determine_driver called before itself
80 # in order to function reliably. We also need to separate accessors
81 # from plain old method calls, since an accessor called as a setter
82 # does *not* need the driver determination loop fired (and in fact
83 # can produce hard to find bugs, like e.g. losing on_connect_*
84 # semantics on fresh connections)
85 #
86 # The construct below is simply a parameterized around()
87 266 my $storage_accessor_idx = { map { $_ => 1 } qw(
88 sqlt_type
89 datetime_parser_type
90  
91 sql_maker
92 cursor_class
93 )};
94 266 for my $meth (keys %$storage_accessor_idx, qw(
95 deployment_statements
96  
97 build_datetime_parser
98  
99 txn_begin
100  
101 insert
102 update
103 delete
104 select
105 select_single
106  
107 _insert_bulk
108  
109 with_deferred_fk_checks
110  
111 get_use_dbms_capability
112 get_dbms_capability
113  
114 _server_info
115 _get_server_version
116 )) {
117  
118 4788 ▶ my $orig = __PACKAGE__->can ($meth)
Branch: 1 branch
BranchTrueFalseTotal
my $orig = __PACKAGE__->can($meth) or die "$meth is not a ::Storage::DBI method!" 4788 0 4788
119 or die "$meth is not a ::Storage::DBI method!";
120  
121 4788 ▶ my $is_getter = $storage_accessor_idx->{$meth} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$storage_accessor_idx->{$meth} ? : 1064 3724 4788
122  
123 4788 quote_sub
124 __PACKAGE__ ."::$meth", sprintf( <<'EOC', $is_getter, perlstring $meth ), { '$orig' => \$orig };
125  
126 if (
127 # only fire when invoked on an instance, a valid class-based invocation
128 # would e.g. be setting a default for an inherited accessor
129 ref $_[0]
130 and
131 ! $_[0]->{_driver_determined}
132 and
133 ! $_[0]->{_in_determine_driver}
134 and
135 # if this is a known *setter* - just set it, no need to connect
136 # and determine the driver
137 ( %1$s or @_ <= 1 )
138 and
139 # Only try to determine stuff if we have *something* that either is or can
140 # provide a DSN. Allows for bare $schema's generated with a plain ->connect()
141 # to still be marginally useful
142 $_[0]->_dbi_connect_info->[0]
143 ) {
144 $_[0]->_determine_driver;
145  
146 # work around http://rt.perl.org/rt3/Public/Bug/Display.html?id=35878
147 goto $_[0]->can(%2$s) unless DBIx::Class::_ENV_::BROKEN_GOTO;
148  
149 my $cref = $_[0]->can(%2$s);
150 goto $cref;
151 }
152  
153 goto $orig;
154 EOC
155 }
156  
157 =head1 NAME
158  
159 DBIx::Class::Storage::DBI - DBI storage handler
160  
161 =head1 SYNOPSIS
162  
163 my $schema = MySchema->connect('dbi:SQLite:my.db');
164  
165 $schema->storage->debug(1);
166  
167 my @stuff = $schema->storage->dbh_do(
168 sub {
169 my ($storage, $dbh, @args) = @_;
170 $dbh->do("DROP TABLE authors");
171 },
172 @column_list
173 );
174  
175 $schema->resultset('Book')->search({
176 written_on => $schema->storage->datetime_parser->format_datetime(DateTime->now)
177 });
178  
179 =head1 DESCRIPTION
180  
181 This class represents the connection to an RDBMS via L<DBI>. See
182 L<DBIx::Class::Storage> for general information. This pod only
183 documents DBI-specific methods and behaviors.
184  
185 =head1 METHODS
186  
187 =cut
188  
189 456 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
190 456 my $new = shift->next::method(@_);
191  
192 456 $new->_sql_maker_opts({});
193 456 $new->_dbh_details({});
194 456 $new->{_in_do_block} = 0;
195  
196 # read below to see what this does
197 456 $new->_arm_global_destructor;
198  
199 456 $new;
200 }
201  
202 # This is hack to work around perl shooting stuff in random
203 # order on exit(). If we do not walk the remaining storage
204 # objects in an END block, there is a *small but real* chance
205 # of a fork()ed child to kill the parent's shared DBI handle,
206 # *before perl reaches the DESTROY in this package*
207 # Yes, it is ugly and effective.
208 # Additionally this registry is used by the CLONE method to
209 # make sure no handles are shared between threads
210 {
211 266 my %seek_and_destroy;
212  
213 456 ▶ sub _arm_global_destructor {
Subroutine _arm_global_destructor: called CC=3 SCAR=11.0
214  
215 # quick "garbage collection" pass - prevents the registry
216 # from slowly growing with a bunch of undef-valued keys
217 defined $seek_and_destroy{$_} or delete $seek_and_destroy{$_}
218 456 ▶ for keys %seek_and_destroy;
Branch: 1 branch
BranchTrueFalseTotal
defined $seek_and_destroy{$_} or delete $seek_and_destroy{$_} 33 221 254
219  
220 weaken (
221 456 $seek_and_destroy{ refaddr($_[0]) } = $_[0]
222 );
223 }
224  
225 266 ▶ END {
Subroutine END: called CC=2 SCAR=6.9
226 266 local $?; # just in case the DBI destructor changes it somehow
227  
228 # destroy just the object if not native to this process
229 266 $_->_verify_pid for (grep
230 235 { defined $_ }
231 values %seek_and_destroy
232 );
233 }
234  
235 0 ▶ sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
236 # As per DBI's recommendation, DBIC disconnects all handles as
237 # soon as possible (DBIC will reconnect only on demand from within
238 # the thread)
239 0 my @instances = grep { defined $_ } values %seek_and_destroy;
240 0 %seek_and_destroy = ();
241  
242 0 for (@instances) {
243 0 $_->_dbh(undef);
244  
245 0 $_->transaction_depth(0);
246 0 $_->savepoints([]);
247  
248 # properly renumber existing refs
249 0 $_->_arm_global_destructor
250 }
251 }
252 }
253  
254 266 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
255 454 ▶ return if &detected_reinvoked_destructor;
Branch: 1 branch
BranchTrueFalseTotal
if &detected_reinvoked_destructor 0 454 454
256  
257 454 $_[0]->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
258 # some databases spew warnings on implicit disconnect
259 454 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
260 454 $_[0]->_dbh(undef);
261  
262 # this op is necessary, since the very last perl runtime statement
263 # triggers a global destruction shootout, and the $SIG localization
264 # may very well be destroyed before perl actually gets to do the
265 # $dbh undef
266 454 1;
267 }
268  
269 # handle pid changes correctly - do not destroy parent's connection
270 68173 ▶sub _verify_pid {
Subroutine _verify_pid: called CC=4 SCAR=13.9
271  
272 68173 my $pid = $_[0]->_conn_pid;
273  
274 68173 ▶ if( defined $pid and $pid != $$ and my $dbh = $_[0]->_dbh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pid and $pid != $$ and my $dbh = $_[0]->_dbh) 24 68149 68173
Condition83%5/6
defined $pid and $pid != $$ and my $dbh = $_[0]->_dbh
!ll&&!rl&&r
68149024
defined $pid and $pid != $$
!ll&&!rl&&r
6376751224
MC/DC66%2/3
defined $pid and $pid != $$ and my $dbh = $_[0]->_dbh
defined $pid $pid != $$ my $dbh = $_[0]->_dbh
Truth table75%3/4
A and B and C
A= defined $pidB= $pid != $$C= my $dbh = $_[0]->_dbh
ABCresult
0XX0
10X0
1100
1111
275 24 $dbh->{InactiveDestroy} = 1;
276 24 $_[0]->_dbh(undef);
277 24 $_[0]->transaction_depth(0);
278 24 $_[0]->savepoints([]);
279 }
280  
281 68173 return;
282 }
283  
284 =head2 connect_info
285  
286 This method is normally called by L<DBIx::Class::Schema/connection>, which
287 encapsulates its argument list in an arrayref before passing them here.
288  
289 The argument list may contain:
290  
291 =over
292  
293 =item *
294  
295 The same 4-element argument set one would normally pass to
296 L<DBI/connect>, optionally followed by
297 L<extra attributes|/DBIx::Class specific connection attributes>
298 recognized by DBIx::Class:
299  
300 $connect_info_args = [ $dsn, $user, $password, \%dbi_attributes?, \%extra_attributes? ];
301  
302 =item *
303  
304 A single code reference which returns a connected
305 L<DBI database handle|DBI/connect> optionally followed by
306 L<extra attributes|/DBIx::Class specific connection attributes> recognized
307 by DBIx::Class:
308  
309 $connect_info_args = [ sub { DBI->connect (...) }, \%extra_attributes? ];
310  
311 =item *
312  
313 A single hashref with all the attributes and the dsn/user/password
314 mixed together:
315  
316 $connect_info_args = [{
317 dsn => $dsn,
318 user => $user,
319 password => $pass,
320 %dbi_attributes,
321 %extra_attributes,
322 }];
323  
324 $connect_info_args = [{
325 dbh_maker => sub { DBI->connect (...) },
326 %dbi_attributes,
327 %extra_attributes,
328 }];
329  
330 This is particularly useful for L<Catalyst> based applications, allowing the
331 following config (L<Config::General> style):
332  
333 <Model::DB>
334 schema_class App::DB
335 <connect_info>
336 dsn dbi:mysql:database=test
337 user testuser
338 password TestPass
339 AutoCommit 1
340 </connect_info>
341 </Model::DB>
342  
343 The C<dsn>/C<user>/C<password> combination can be substituted by the
344 C<dbh_maker> key whose value is a coderef that returns a connected
345 L<DBI database handle|DBI/connect>
346  
347 =back
348  
349 Please note that the L<DBI> docs recommend that you always explicitly
350 set C<AutoCommit> to either I<0> or I<1>. L<DBIx::Class> further
351 recommends that it be set to I<1>, and that you perform transactions
352 via our L<DBIx::Class::Schema/txn_do> method. L<DBIx::Class> will set it
353 to I<1> if you do not do explicitly set it to zero. This is the default
354 for most DBDs. See L</DBIx::Class and AutoCommit> for details.
355  
356 =head3 DBIx::Class specific connection attributes
357  
358 In addition to the standard L<DBI|DBI/ATTRIBUTES COMMON TO ALL HANDLES>
359 L<connection|DBI/Database Handle Attributes> attributes, DBIx::Class recognizes
360 the following connection options. These options can be mixed in with your other
361 L<DBI> connection attributes, or placed in a separate hashref
362 (C<\%extra_attributes>) as shown above.
363  
364 Every time C<connect_info> is invoked, any previous settings for
365 these options will be cleared before setting the new ones, regardless of
366 whether any options are specified in the new C<connect_info>.
367  
368  
369 =over
370  
371 =item on_connect_do
372  
373 Specifies things to do immediately after connecting or re-connecting to
374 the database. Its value may contain:
375  
376 =over
377  
378 =item a scalar
379  
380 This contains one SQL statement to execute.
381  
382 =item an array reference
383  
384 This contains SQL statements to execute in order. Each element contains
385 a string or a code reference that returns a string.
386  
387 =item a code reference
388  
389 This contains some code to execute. Unlike code references within an
390 array reference, its return value is ignored.
391  
392 =back
393  
394 =item on_disconnect_do
395  
396 Takes arguments in the same form as L</on_connect_do> and executes them
397 immediately before disconnecting from the database.
398  
399 Note, this only runs if you explicitly call L</disconnect> on the
400 storage object.
401  
402 =item on_connect_call
403  
404 A more generalized form of L</on_connect_do> that calls the specified
405 C<connect_call_METHOD> methods in your storage driver.
406  
407 on_connect_do => 'select 1'
408  
409 is equivalent to:
410  
411 on_connect_call => [ [ do_sql => 'select 1' ] ]
412  
413 Its values may contain:
414  
415 =over
416  
417 =item a scalar
418  
419 Will call the C<connect_call_METHOD> method.
420  
421 =item a code reference
422  
423 Will execute C<< $code->($storage) >>
424  
425 =item an array reference
426  
427 Each value can be a method name or code reference.
428  
429 =item an array of arrays
430  
431 For each array, the first item is taken to be the C<connect_call_> method name
432 or code reference, and the rest are parameters to it.
433  
434 =back
435  
436 Some predefined storage methods you may use:
437  
438 =over
439  
440 =item do_sql
441  
442 Executes a SQL string or a code reference that returns a SQL string. This is
443 what L</on_connect_do> and L</on_disconnect_do> use.
444  
445 It can take:
446  
447 =over
448  
449 =item a scalar
450  
451 Will execute the scalar as SQL.
452  
453 =item an arrayref
454  
455 Taken to be arguments to L<DBI/do>, the SQL string optionally followed by the
456 attributes hashref and bind values.
457  
458 =item a code reference
459  
460 Will execute C<< $code->($storage) >> and execute the return array refs as
461 above.
462  
463 =back
464  
465 =item datetime_setup
466  
467 Execute any statements necessary to initialize the database session to return
468 and accept datetime/timestamp values used with
469 L<DBIx::Class::InflateColumn::DateTime>.
470  
471 Only necessary for some databases, see your specific storage driver for
472 implementation details.
473  
474 =back
475  
476 =item on_disconnect_call
477  
478 Takes arguments in the same form as L</on_connect_call> and executes them
479 immediately before disconnecting from the database.
480  
481 Calls the C<disconnect_call_METHOD> methods as opposed to the
482 C<connect_call_METHOD> methods called by L</on_connect_call>.
483  
484 Note, this only runs if you explicitly call L</disconnect> on the
485 storage object.
486  
487 =item disable_sth_caching
488  
489 If set to a true value, this option will disable the caching of
490 statement handles via L<DBI/prepare_cached>.
491  
492 =item limit_dialect
493  
494 Sets a specific SQL::Abstract::Limit-style limit dialect, overriding the
495 default L</sql_limit_dialect> setting of the storage (if any). For a list
496 of available limit dialects see L<DBIx::Class::SQLMaker::LimitDialects>.
497  
498 =item quote_names
499  
500 When true automatically sets L</quote_char> and L</name_sep> to the characters
501 appropriate for your particular RDBMS. This option is preferred over specifying
502 L</quote_char> directly.
503  
504 =item quote_char
505  
506 Specifies what characters to use to quote table and column names.
507  
508 C<quote_char> expects either a single character, in which case is it
509 is placed on either side of the table/column name, or an arrayref of length
510 2 in which case the table/column name is placed between the elements.
511  
512 For example under MySQL you should use C<< quote_char => '`' >>, and for
513 SQL Server you should use C<< quote_char => [qw/[ ]/] >>.
514  
515 =item name_sep
516  
517 This parameter is only useful in conjunction with C<quote_char>, and is used to
518 specify the character that separates elements (schemas, tables, columns) from
519 each other. If unspecified it defaults to the most commonly used C<.>.
520  
521 =item unsafe
522  
523 This Storage driver normally installs its own C<HandleError>, sets
524 C<RaiseError> and C<ShowErrorStatement> on, and sets C<PrintError> off on
525 all database handles, including those supplied by a coderef. It does this
526 so that it can have consistent and useful error behavior.
527  
528 If you set this option to a true value, Storage will not do its usual
529 modifications to the database handle's attributes, and instead relies on
530 the settings in your connect_info DBI options (or the values you set in
531 your connection coderef, in the case that you are connecting via coderef).
532  
533 Note that your custom settings can cause Storage to malfunction,
534 especially if you set a C<HandleError> handler that suppresses exceptions
535 and/or disable C<RaiseError>.
536  
537 =item auto_savepoint
538  
539 If this option is true, L<DBIx::Class> will use savepoints when nesting
540 transactions, making it possible to recover from failure in the inner
541 transaction without having to abort all outer transactions.
542  
543 =item cursor_class
544  
545 Use this argument to supply a cursor class other than the default
546 L<DBIx::Class::Storage::DBI::Cursor>.
547  
548 =back
549  
550 Some real-life examples of arguments to L</connect_info> and
551 L<DBIx::Class::Schema/connect>
552  
553 # Simple SQLite connection
554 ->connect_info([ 'dbi:SQLite:./foo.db' ]);
555  
556 # Connect via subref
557 ->connect_info([ sub { DBI->connect(...) } ]);
558  
559 # Connect via subref in hashref
560 ->connect_info([{
561 dbh_maker => sub { DBI->connect(...) },
562 on_connect_do => 'alter session ...',
563 }]);
564  
565 # A bit more complicated
566 ->connect_info(
567 [
568 'dbi:Pg:dbname=foo',
569 'postgres',
570 'my_pg_password',
571 { AutoCommit => 1 },
572 { quote_char => q{"} },
573 ]
574 );
575  
576 # Equivalent to the previous example
577 ->connect_info(
578 [
579 'dbi:Pg:dbname=foo',
580 'postgres',
581 'my_pg_password',
582 { AutoCommit => 1, quote_char => q{"}, name_sep => q{.} },
583 ]
584 );
585  
586 # Same, but with hashref as argument
587 # See parse_connect_info for explanation
588 ->connect_info(
589 [{
590 dsn => 'dbi:Pg:dbname=foo',
591 user => 'postgres',
592 password => 'my_pg_password',
593 AutoCommit => 1,
594 quote_char => q{"},
595 name_sep => q{.},
596 }]
597 );
598  
599 # Subref + DBIx::Class-specific connection options
600 ->connect_info(
601 [
602 sub { DBI->connect(...) },
603 {
604 quote_char => q{`},
605 name_sep => q{@},
606 on_connect_do => ['SET search_path TO myschema,otherschema,public'],
607 disable_sth_caching => 1,
608 },
609 ]
610 );
611  
612  
613  
614 =cut
615  
616 452 ▶sub connect_info {
Subroutine connect_info: called CC=12 SCAR=25.0
Pod documented
617 452 my ($self, $info) = @_;
618  
619 452 ▶ return $self->_connect_info if !$info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 4 448 452
620  
621 448 $self->_connect_info($info); # copy for _connect_info
622  
623 448 ▶ $info = $self->_normalize_connect_info($info)
Branch: 1 branch
BranchTrueFalseTotal
if ref $info eq "ARRAY" 448 0 448
624 if ref $info eq 'ARRAY';
625  
626 my %attrs = (
627 448 ▶ %{ $self->_default_dbi_connect_attributes || {} },
Condition50%1/2
$self->_default_dbi_connect_attributes || {}
l!l
4480
MC/DC0%0/1
$self->_default_dbi_connect_attributes || {}
$self->_default_dbi_connect_attributes
Truth table50%1/2
A
A= $self->_default_dbi_connect_attributes
Aresult
11
00
628 448 ▶ %{ $info->{attributes} || {} },
Condition100%2/2
$info->{'attributes'} || {}
l!l
41632
MC/DC100%1/1
$info->{'attributes'} || {}
$info->{'attributes'}
Truth table100%2/2
A
A= $info->{'attributes'}
Aresult
11
00
629 );
630  
631 448 my @args = @{ $info->{arguments} };
632  
633 448 ▶ if (keys %attrs and ref $args[0] ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %attrs and ref $args[0] ne "CODE") 440 8 448
Condition66%2/3
keys %attrs and ref $args[0] ne "CODE"
!ll&&!rl&&r
08440
MC/DC50%1/2
keys %attrs and ref $args[0] ne "CODE"
keys %attrs ref $args[0] ne "CODE"
Truth table66%2/3
A and B
A= keys %attrsB= ref $args[0] ne "CODE"
ABresult
0X0
100
111
634 carp_unique (
635 'You provided explicit AutoCommit => 0 in your connection_info. '
636 . 'This is almost universally a bad idea (see the footnotes of '
637 . 'DBIx::Class::Storage::DBI for more info). If you still want to '
638 . 'do this you can set $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK} to disable '
639 . 'this warning.'
640 440 ▶ ) if ! $attrs{AutoCommit} and ! $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK};
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs{"AutoCommit"} or $ENV{"DBIC_UNSAFE_AUTOCOMMIT_OK"} 1 439 440
Condition66%2/3
$attrs{"AutoCommit"} or $ENV{"DBIC_UNSAFE_AUTOCOMMIT_OK"}
l!l&&r!l&&!r
43901
MC/DC50%1/2
$attrs{"AutoCommit"} or $ENV{"DBIC_UNSAFE_AUTOCOMMIT_OK"}
$attrs{"AutoCommit"} $ENV{"DBIC_UNSAFE_AUTOCOMMIT_OK"}
Truth table66%2/3
A or B
A= $attrs{"AutoCommit"}B= $ENV{"DBIC_UNSAFE_AUTOCOMMIT_OK"}
ABresult
1X1
011
000
641  
642 440 ▶ push @args, \%attrs if keys %attrs;
Branch: 1 branch
BranchTrueFalseTotal
if keys %attrs 440 0 440
643 }
644  
645 # this is the authoritative "always an arrayref" thing fed to DBI->connect
646 # OR a single-element coderef-based $dbh factory
647 448 $self->_dbi_connect_info(\@args);
648  
649 # extract the individual storage options
650 448 for my $storage_opt (keys %{ $info->{storage_options} }) {
651 455 my $value = $info->{storage_options}{$storage_opt};
652  
653 455 $self->$storage_opt($value);
654 }
655  
656 # Extract the individual sqlmaker options
657 #
658 # Kill sql_maker/_sql_maker_opts, so we get a fresh one with only
659 # the new set of options
660 448 $self->_sql_maker(undef);
661 448 $self->_sql_maker_opts({});
662  
663 448 for my $sql_maker_opt (keys %{ $info->{sql_maker_options} }) {
664 11 my $value = $info->{sql_maker_options}{$sql_maker_opt};
665  
666 11 $self->_sql_maker_opts->{$sql_maker_opt} = $value;
667 }
668  
669 # FIXME - dirty:
670 # save attributes in a separate accessor so they are always
671 # introspectable, even in case of a CODE $dbhmaker
672 448 $self->_dbic_connect_attributes (\%attrs);
673  
674 448 return $self->_connect_info;
675 }
676  
677 1234 ▶sub _dbi_connect_info {
Subroutine _dbi_connect_info: called CC=5 SCAR=16.1
678 1234 my $self = shift;
679  
680 1234 ▶ return $self->{_dbi_connect_info} = $_[0]
Branch: 1 branch
BranchTrueFalseTotal
if @_ 448 786 1234
681 if @_;
682  
683 786 ▶ my $conninfo = $self->{_dbi_connect_info} || [];
Condition50%1/2
$self->{'_dbi_connect_info'} || []
l!l
7860
MC/DC0%0/1
$self->{'_dbi_connect_info'} || []
$self->{'_dbi_connect_info'}
Truth table50%1/2
A
A= $self->{'_dbi_connect_info'}
Aresult
11
00
684  
685 # last ditch effort to grab a DSN
686 786 ▶ if ( ! defined $conninfo->[0] and $ENV{DBI_DSN} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $conninfo->[0] and $ENV{"DBI_DSN"}) 168 618 786
Condition100%3/3
not defined $conninfo->[0] and $ENV{"DBI_DSN"}
!ll&&!rl&&r
6126168
MC/DC100%2/2
not defined $conninfo->[0] and $ENV{"DBI_DSN"}
not defined $conninfo->[0] $ENV{"DBI_DSN"}
Truth table100%3/3
not(A) and B
A= not defined $conninfo->[0]B= $ENV{"DBI_DSN"}
ABresult
0X0
100
111
687 168 my @new_conninfo = @$conninfo;
688 168 $new_conninfo[0] = $ENV{DBI_DSN};
689 168 $conninfo = \@new_conninfo;
690 }
691  
692 786 return $conninfo;
693 }
694  
695  
696 448 ▶sub _normalize_connect_info {
Subroutine _normalize_connect_info: called CC=11 SCAR=24.0
697 448 my ($self, $info_arg) = @_;
698 448 my %info;
699  
700 448 my @args = @$info_arg; # take a shallow copy for further mutilation
701  
702 # combine/pre-parse arguments depending on invocation style
703  
704 448 my %attrs;
705 448 ▶ if (ref $args[0] eq 'CODE') { # coderef with optional \%extra_attributes
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args[0] eq 'CODE') { } 7 441 448
elsif (ref $args[0] eq 'HASH') { } 2 439 441
706 7 ▶ %attrs = %{ $args[1] || {} };
Condition100%2/2
$args[1] || {}
l!l
43
MC/DC100%1/1
$args[1] || {}
$args[1]
Truth table100%2/2
A
A= $args[1]
Aresult
11
00
707 7 @args = $args[0];
708 }
709 elsif (ref $args[0] eq 'HASH') { # single hashref (i.e. Catalyst config)
710 2 %attrs = %{$args[0]};
711 2 @args = ();
712 2 ▶ if (my $code = delete $attrs{dbh_maker}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = delete $attrs{'dbh_maker'}) { } 1 1 2
713 1 @args = $code;
714  
715 1 my @ignored = grep { delete $attrs{$_} } (qw/dsn user password/);
716 1 ▶ if (@ignored) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ignored) 1 0 1
717 carp sprintf (
718 'Attribute(s) %s in connect_info were ignored, as they can not be applied '
719 . "to the result of 'dbh_maker'",
720  
721 1 join (', ', map { "'$_'" } (@ignored) ),
722 );
723 }
724 }
725 else {
726 1 @args = delete @attrs{qw/dsn user password/};
727 }
728 }
729 else { # otherwise assume dsn/user/password + \%attrs + \%extra_attrs
730 %attrs = (
731 439 ▶ % { $args[3] || {} },
Condition100%2/2
$args[3] || {}
l!l
41524
MC/DC100%1/1
$args[3] || {}
$args[3]
Truth table100%2/2
A
A= $args[3]
Aresult
11
00
732 439 ▶ % { $args[4] || {} },
Condition100%2/2
$args[4] || {}
l!l
9430
MC/DC100%1/1
$args[4] || {}
$args[4]
Truth table100%2/2
A
A= $args[4]
Aresult
11
00
733 );
734 439 @args = @args[0,1,2];
735 }
736  
737 448 $info{arguments} = \@args;
738  
739 448 my @storage_opts = grep exists $attrs{$_},
740 @storage_options, 'cursor_class';
741  
742 419 @{ $info{storage_options} }{@storage_opts} =
743 448 ▶ delete @attrs{@storage_opts} if @storage_opts;
Branch: 1 branch
BranchTrueFalseTotal
if @storage_opts 419 29 448
744  
745 448 my @sql_maker_opts = grep exists $attrs{$_},
746 qw/limit_dialect quote_char name_sep quote_names/;
747  
748 11 @{ $info{sql_maker_options} }{@sql_maker_opts} =
749 448 ▶ delete @attrs{@sql_maker_opts} if @sql_maker_opts;
Branch: 1 branch
BranchTrueFalseTotal
if @sql_maker_opts 11 437 448
750  
751 448 ▶ $info{attributes} = \%attrs if %attrs;
Branch: 1 branch
BranchTrueFalseTotal
if %attrs 416 32 448
752  
753 448 return \%info;
754 }
755  
756 450 ▶sub _default_dbi_connect_attributes () {
Subroutine _default_dbi_connect_attributes: called CC=1 SCAR=0.0
757 +{
758 450 AutoCommit => 1,
759 PrintError => 0,
760 RaiseError => 1,
761 ShowErrorStatement => 1,
762 };
763 }
764  
765 =head2 on_connect_do
766  
767 This method is deprecated in favour of setting via L</connect_info>.
768  
769 =cut
770  
771 =head2 on_disconnect_do
772  
773 This method is deprecated in favour of setting via L</connect_info>.
774  
775 =cut
776  
777 488 ▶sub _parse_connect_do {
Subroutine _parse_connect_do: called CC=5 SCAR=16.2
778 488 my ($self, $type) = @_;
779  
780 488 my $val = $self->$type;
781 488 ▶ return () if not defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 37 451 488
782  
783 451 my @res;
784  
785 451 ▶ if (not ref($val)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $val) { } 7 444 451
elsif (ref $val eq 'CODE') { } 442 2 444
elsif (ref $val eq 'ARRAY') { } 2 0 2
786 7 push @res, [ 'do_sql', $val ];
787 } elsif (ref($val) eq 'CODE') {
788 442 push @res, $val;
789 } elsif (ref($val) eq 'ARRAY') {
790 2 push @res, map { [ 'do_sql', $_ ] } @$val;
791 } else {
792 0 $self->throw_exception("Invalid type for $type: ".ref($val));
793 }
794  
795 451 return \@res;
796 }
797  
798 =head2 dbh_do
799  
800 Arguments: ($subref | $method_name), @extra_coderef_args?
801  
802 Execute the given $subref or $method_name using the new exception-based
803 connection management.
804  
805 The first two arguments will be the storage object that C<dbh_do> was called
806 on and a database handle to use. Any additional arguments will be passed
807 verbatim to the called subref as arguments 2 and onwards.
808  
809 Using this (instead of $self->_dbh or $self->dbh) ensures correct
810 exception handling and reconnection (or failover in future subclasses).
811  
812 Your subref should have no side-effects outside of the database, as
813 there is the potential for your subref to be partially double-executed
814 if the database connection was stale/dysfunctional.
815  
816 Example:
817  
818 my @stuff = $schema->storage->dbh_do(
819 sub {
820 my ($storage, $dbh, @cols) = @_;
821 my $cols = join(q{, }, @cols);
822 $dbh->selectrow_array("SELECT $cols FROM foo");
823 },
824 @column_list
825 );
826  
827 =cut
828  
829 47195 ▶sub dbh_do {
Subroutine dbh_do: called CC=4 SCAR=13.9
Pod documented
830 47195 my $self = shift;
831 47195 my $run_target = shift; # either a coderef or a method name
832  
833 # short circuit when we know there is no need for a runner
834 #
835 # FIXME - assumption may be wrong
836 # the rationale for the txn_depth check is that if this block is a part
837 # of a larger transaction, everything up to that point is screwed anyway
838 return $self->$run_target($self->_get_dbh, @_)
839 47195 ▶ if $self->{_in_do_block} or $self->transaction_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_in_do_block"} or $self->transaction_depth 2993 44202 47195
Condition100%3/3
$self->{"_in_do_block"} or $self->transaction_depth
l!l&&r!l&&!r
819217444202
MC/DC100%2/2
$self->{"_in_do_block"} or $self->transaction_depth
$self->{"_in_do_block"} $self->transaction_depth
Truth table100%3/3
A or B
A= $self->{"_in_do_block"}B= $self->transaction_depth
ABresult
1X1
011
000
840  
841 # take a ref instead of a copy, to preserve @_ aliasing
842 # semantics within the coderef, but only if needed
843 # (pseudoforking doesn't like this trick much)
844 44202 ▶ my $args = @_ ? \@_ : [];
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 7087 37115 44202
845  
846 DBIx::Class::Storage::BlockRunner->new(
847 storage => $self,
848 wrap_txn => 0,
849 22 ▶ retry_handler => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
850 22 ▶ $_[0]->failed_attempt_count == 1
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->failed_attempt_count == 1 and not $_[0]->storage->connected 22 0 22
851 and
852 ! $_[0]->storage->connected
853 },
854 44205 ▶ )->run(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
855 44205 $self->$run_target ($self->_get_dbh, @$args )
856 44202 });
857 }
858  
859 472 ▶sub txn_do {
Subroutine txn_do: called CC=1 SCAR=0.0
Pod documented
860 472 $_[0]->_get_dbh; # connects or reconnects on pid change, necessary to grab correct txn_depth
861 472 shift->next::method(@_);
862 }
863  
864 =head2 disconnect
865  
866 Our C<disconnect> method also performs a rollback first if the
867 database is not in C<AutoCommit> mode.
868  
869 =cut
870  
871 37 ▶sub disconnect {
Subroutine disconnect: called CC=5 SCAR=16.1
Pod documented
872  
873 37 ▶ if( my $dbh = $_[0]->_dbh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = $_[0]->_dbh) 20 17 37
874  
875 20 ▶ $_[0]->_do_connection_actions(disconnect_call_ => $_) for (
Condition100%3/3
$_[0]->on_disconnect_call || ()
l!l&&r!l&&!r
4106
MC/DC100%2/2
$_[0]->on_disconnect_call || ()
$_[0]->on_disconnect_call ()
Truth table100%3/3
A || B
A= $_[0]->on_disconnect_callB= ()
ABresult
1X1
011
000
876 ( $_[0]->on_disconnect_call || () ),
877 $_[0]->_parse_connect_do ('on_disconnect_do')
878 );
879  
880 # stops the "implicit rollback on disconnect" warning
881 20 ▶ $_[0]->_exec_txn_rollback unless $_[0]->_dbh_autocommit;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->_dbh_autocommit 0 20 20
882  
883 20 %{ $dbh->{CachedKids} } = ();
884 20 $dbh->disconnect;
885 20 $_[0]->_dbh(undef);
886 }
887 }
888  
889 =head2 with_deferred_fk_checks
890  
891 =over 4
892  
893 =item Arguments: C<$coderef>
894  
895 =item Return Value: The return value of $coderef
896  
897 =back
898  
899 Storage specific method to run the code ref with FK checks deferred or
900 in MySQL's case disabled entirely.
901  
902 =cut
903  
904 # Storage subclasses should override this
905 sub with_deferred_fk_checks {
906 #my ($self, $sub) = @_;
907 $_[1]->();
908 }
909  
910 =head2 connected
911  
912 =over
913  
914 =item Arguments: none
915  
916 =item Return Value: 1|0
917  
918 =back
919  
920 Verifies that the current database handle is active and ready to execute
921 an SQL statement (e.g. the connection did not get stale, server is still
922 answering, etc.) This method is used internally by L</dbh>.
923  
924 =cut
925  
926 267 ▶sub connected {
Subroutine connected: called CC=2 SCAR=6.9
Pod documented
927 267 ▶ return 0 unless $_[0]->_seems_connected;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->_seems_connected 116 151 267
928  
929 #be on the safe side
930 151 local $_[0]->_dbh->{RaiseError} = 1;
931  
932 151 return $_[0]->_ping;
933 }
934  
935 9907 ▶sub _seems_connected {
Subroutine _seems_connected: called CC=2 SCAR=6.9
936 9907 $_[0]->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
937  
938 9907 ▶ ($_[0]->_dbh || return 0)->FETCH('Active');
Condition100%2/2
$_[0]->_dbh || (return 0)
l!l
981394
MC/DC100%1/1
$_[0]->_dbh || (return 0)
$_[0]->_dbh
Truth table100%2/2
A
A= $_[0]->_dbh
Aresult
11
00
939 }
940  
941 6 ▶sub _ping {
Subroutine _ping: called CC=2 SCAR=7.6
942 6 ▶ ($_[0]->_dbh || return 0)->ping;
Condition50%1/2
$_[0]->_dbh || (return 0)
l!l
60
MC/DC0%0/1
$_[0]->_dbh || (return 0)
$_[0]->_dbh
Truth table50%1/2
A
A= $_[0]->_dbh
Aresult
11
00
943 }
944  
945 177 ▶sub ensure_connected {
Subroutine ensure_connected: called CC=3 SCAR=11.4
Pod documented
946 177 ▶ $_[0]->connected || ( $_[0]->_populate_dbh && 1 );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->connected or $_[0]->_populate_dbh and 1 109 68 177
Condition60%3/5
$_[0]->connected || $_[0]->_populate_dbh && 1
l!l&&r!l&&!r
109680
$_[0]->_populate_dbh and 1
!ll
050
MC/DC0%0/2
$_[0]->connected || $_[0]->_populate_dbh && 1
$_[0]->connected $_[0]->_populate_dbh
Truth table33%1/3
A || B
A= $_[0]->connectedB= $_[0]->_populate_dbh
ABresult
1X1
011
000
947 }
948  
949 =head2 dbh
950  
951 Returns a C<$dbh> - a data base handle of class L<DBI>. The returned handle
952 is guaranteed to be healthy by implicitly calling L</connected>, and if
953 necessary performing a reconnection before returning. Keep in mind that this
954 is very B<expensive> on some database engines. Consider using L</dbh_do>
955 instead.
956  
957 =cut
958  
959 110 ▶sub dbh {
Subroutine dbh: called CC=3 SCAR=12.0
Pod documented
960 # maybe save a ping call
961 110 ▶ $_[0]->_dbh
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_dbh ? : 99 11 110
Condition33%1/3
$_[0]->ensure_connected and $_[0]->_dbh
!ll&&!rl&&r
0099
MC/DC0%0/2
$_[0]->ensure_connected and $_[0]->_dbh
$_[0]->ensure_connected $_[0]->_dbh
Truth table33%1/3
A and B
A= $_[0]->ensure_connectedB= $_[0]->_dbh
ABresult
0X0
100
111
962 ? ( $_[0]->ensure_connected and $_[0]->_dbh )
963 : $_[0]->_populate_dbh
964 ;
965 }
966  
967 # this is the internal "get dbh or connect (don't check)" method
968 57676 ▶sub _get_dbh {
Subroutine _get_dbh: called CC=2 SCAR=6.9
969 57676 $_[0]->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
970 57676 ▶ $_[0]->_dbh || $_[0]->_populate_dbh;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_dbh or $_[0]->_populate_dbh 57122 554 57676
971 }
972  
973 # *DELIBERATELY* not a setter (for the time being)
974 # Too intertwined with everything else for any kind of sanity
975 32649 ▶sub sql_maker {
Subroutine sql_maker: called CC=15 SCAR=28.2
976 32649 my $self = shift;
977  
978 31374 ▶ $self->throw_exception('sql_maker() is not a setter method') if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 977 30396 31373
979  
980 31373 ▶ unless ($self->_sql_maker) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_sql_maker) 390 28747 29137
981 1628 my $sql_maker_class = $self->sql_maker_class;
982  
983 1628 ▶ my %opts = %{$self->_sql_maker_opts||{}};
Condition100%3/3
$self->_sql_maker_opts || {}
l!l
38218
MC/DC0%0/1
$self->_sql_maker_opts || {}
$self->_sql_maker_opts
Truth table50%1/2
A
A= $self->_sql_maker_opts
Aresult
11
00
984 my $dialect =
985 $opts{limit_dialect}
986 ||
987 $self->sql_limit_dialect
988 ||
989 390 ▶ do {
Condition83%5/6
$opts{'limit_dialect'} || $self->sql_limit_dialect || do { my $s_class = ref $self || $self; carp_unique("Your storage class ($s_class) does not set sql_limit_dialect and you " . 'have not supplied an explicit limit_dialect in your connection_info. ' . 'DBIC will attempt to use the GenericSubQ dialect, which works on most ' . 'databases but can be (and often is) painfully slow. ' . "Please file an RT ticket against '${s_class}'") if $self->_dbi_connect_info->[0]; 'GenericSubQ' }
l!l&&r!l&&!r
383818
$opts{"limit_dialect"} or $self->sql_limit_dialect
l!l&&r!l&&!r
03767
MC/DC0%0/3
$opts{'limit_dialect'} || $self->sql_limit_dialect || do { my $s_class = ref $self || $self; carp_unique("Your storage class ($s_class) does not set sql_limit_dialect and you " . 'have not supplied an explicit limit_dialect in your connection_info. ' . 'DBIC will attempt to use the GenericSubQ dialect, which works on most ' . 'databases but can be (and often is) painfully slow. ' . "Please file an RT ticket against '${s_class}'") if $self->_dbi_connect_info->[0]; 'GenericSubQ' }
$opts{"limit_dialect"} $self->sql_limit_dialect do { my $s_class = ref $self || $self; carp_unique("Your storage class ($s_class) does not set sql_limit_dialect and you " . 'have not supplied an explicit limit_dialect in your connection_info. ' . 'DBIC will attempt to use the GenericSubQ dialect, which works on most ' . 'databases but can be (and often is) painfully slow. ' . "Please file an RT ticket against '${s_class}'") if $self->_dbi_connect_info->[0]; 'GenericSubQ' }
Truth table50%2/4
A or B || C
A= $opts{"limit_dialect"}B= $self->sql_limit_dialectC= do { my $s_class = ref $self || $self; carp_unique("Your storage class ($s_class) does not set sql_limit_dialect and you " . 'have not supplied an explicit limit_dialect in your connection_info. ' . 'DBIC will attempt to use the GenericSubQ dialect, which works on most ' . 'databases but can be (and often is) painfully slow. ' . "Please file an RT ticket against '${s_class}'") if $self->_dbi_connect_info->[0]; 'GenericSubQ' }
ABCresult
1XX1
01X1
0011
0000
990 15 ▶ my $s_class = (ref $self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
710
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
991 15 ▶ carp_unique (
Branch: 1 branch
BranchTrueFalseTotal
if $self->_dbi_connect_info->[0] 15 1 16
992 "Your storage class ($s_class) does not set sql_limit_dialect and you "
993 . 'have not supplied an explicit limit_dialect in your connection_info. '
994 . 'DBIC will attempt to use the GenericSubQ dialect, which works on most '
995 . 'databases but can be (and often is) painfully slow. '
996 . "Please file an RT ticket against '$s_class'"
997 ) if $self->_dbi_connect_info->[0];
998  
999 15 'GenericSubQ';
1000 }
1001 ;
1002  
1003 390 my ($quote_char, $name_sep);
1004  
1005 391 ▶ if ($opts{quote_names}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"quote_names"}) 26 382 408
1006 17 ▶ $quote_char = (delete $opts{quote_char}) || $self->sql_quote_char || do {
Condition33%2/6
delete $opts{'quote_char'} || $self->sql_quote_char || do { my $s_class = ref $self || $self; carp_unique("You requested 'quote_names' but your storage class ($s_class) does " . 'not explicitly define a default sql_quote_char and you have not ' . 'supplied a quote_char as part of your connection_info. DBIC will ' . q[default to the ANSI SQL standard quote '"', which works most of ] . "the time. Please file an RT ticket against '${s_class}'."); '"' }
l!l&&r!l&&!r
800
delete $opts{"quote_char"} or $self->sql_quote_char
l!l&&r!l&&!r
080
MC/DC0%0/3
delete $opts{'quote_char'} || $self->sql_quote_char || do { my $s_class = ref $self || $self; carp_unique("You requested 'quote_names' but your storage class ($s_class) does " . 'not explicitly define a default sql_quote_char and you have not ' . 'supplied a quote_char as part of your connection_info. DBIC will ' . q[default to the ANSI SQL standard quote '"', which works most of ] . "the time. Please file an RT ticket against '${s_class}'."); '"' }
delete $opts{"quote_char"} $self->sql_quote_char do { my $s_class = ref $self || $self; carp_unique("You requested 'quote_names' but your storage class ($s_class) does " . 'not explicitly define a default sql_quote_char and you have not ' . 'supplied a quote_char as part of your connection_info. DBIC will ' . q[default to the ANSI SQL standard quote '"', which works most of ] . "the time. Please file an RT ticket against '${s_class}'."); '"' }
Truth table25%1/4
A or B || C
A= delete $opts{"quote_char"}B= $self->sql_quote_charC= do { my $s_class = ref $self || $self; carp_unique("You requested 'quote_names' but your storage class ($s_class) does " . 'not explicitly define a default sql_quote_char and you have not ' . 'supplied a quote_char as part of your connection_info. DBIC will ' . q[default to the ANSI SQL standard quote '"', which works most of ] . "the time. Please file an RT ticket against '${s_class}'."); '"' }
ABCresult
1XX1
01X1
0011
0000
1007 18 ▶ my $s_class = (ref $self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1008 18 carp_unique (
1009 "You requested 'quote_names' but your storage class ($s_class) does "
1010 . 'not explicitly define a default sql_quote_char and you have not '
1011 . 'supplied a quote_char as part of your connection_info. DBIC will '
1012 .q{default to the ANSI SQL standard quote '"', which works most of }
1013 . "the time. Please file an RT ticket against '$s_class'."
1014 );
1015  
1016 18 '"'; # RV
1017 };
1018  
1019 16 ▶ $name_sep = (delete $opts{name_sep}) || $self->sql_name_sep;
Condition33%1/3
delete $opts{'name_sep'} || $self->sql_name_sep
l!l&&r!l&&!r
080
MC/DC0%0/2
delete $opts{'name_sep'} || $self->sql_name_sep
delete $opts{'name_sep'} $self->sql_name_sep
Truth table33%1/3
A || B
A= delete $opts{'name_sep'}B= $self->sql_name_sep
ABresult
1X1
011
000
1020 }
1021  
1022 390 ▶ $self->_sql_maker($sql_maker_class->new(
Branch: 1 branch
BranchTrueFalseTotal
$quote_char ? : 8 392 400
Condition100%2/2
$name_sep || '.'
l!l
8374
MC/DC100%1/1
$name_sep || '.'
$name_sep
Truth table100%2/2
A
A= $name_sep
Aresult
11
00
1023 bindtype=>'columns',
1024 array_datatypes => 1,
1025 limit_dialect => $dialect,
1026 ($quote_char ? (quote_char => $quote_char) : ()),
1027 name_sep => ($name_sep || '.'),
1028 %opts,
1029 ));
1030 }
1031 29137 return $self->_sql_maker;
1032 }
1033  
1034 # nothing to do by default
1035 423 ▶sub _rebless {}
Subroutine _rebless: called CC=1 SCAR=0.0
1036 437 ▶sub _init {}
Subroutine _init: called CC=1 SCAR=0.0
1037  
1038 649 ▶sub _populate_dbh {
Subroutine _populate_dbh: called CC=3 SCAR=11.0
1039  
1040 649 $_[0]->_dbh(undef); # in case ->connected failed we might get sent here
1041  
1042 649 $_[0]->_dbh_details({}); # reset everything we know
1043  
1044 # FIXME - this needs reenabling with the proper "no reset on same DSN" check
1045 #$_[0]->_sql_maker(undef); # this may also end up being different
1046  
1047 649 $_[0]->_dbh($_[0]->_connect);
1048  
1049 466 $_[0]->_conn_pid($$) unless DBIx::Class::_ENV_::BROKEN_FORK; # on win32 these are in fact threads
1050  
1051 466 $_[0]->_determine_driver;
1052  
1053 # Always set the transaction depth on connect, since
1054 # there is no transaction in progress by definition
1055 465 ▶ $_[0]->{transaction_depth} = $_[0]->_dbh_autocommit ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_dbh_autocommit ? : 463 2 465
1056  
1057 465 ▶ $_[0]->_run_connection_actions unless $_[0]->{_in_determine_driver};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"_in_determine_driver"} 461 4 465
1058  
1059 452 $_[0]->_dbh;
1060 }
1061  
1062 468 ▶sub _run_connection_actions {
Subroutine _run_connection_actions: called CC=4 SCAR=14.2
1063 # there are pathological cases in the CI where this can loop
1064 # did not investigae in depth, but in either case this makes
1065 # sense to guard like this
1066 468 ▶ return if $_[0]->{_running_connections_actions};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_running_connections_actions"} 0 468 468
1067  
1068 468 local $_[0]->{_running_connections_actions} = 1;
1069  
1070 468 ▶ $_[0]->_do_connection_actions(connect_call_ => $_) for (
Condition66%2/3
$_[0]->on_connect_call || ()
l!l&&r!l&&!r
46503
MC/DC50%1/2
$_[0]->on_connect_call || ()
$_[0]->on_connect_call ()
Truth table66%2/3
A || B
A= $_[0]->on_connect_callB= ()
ABresult
1X1
011
000
1071 ( $_[0]->on_connect_call || () ),
1072 $_[0]->_parse_connect_do ('on_connect_do'),
1073 );
1074  
1075 455 my $sqlac_like;
1076 455 if(
1077 DBIx::Class::_ENV_::DEVREL
1078 and
1079 $ENV{DBICDEVREL_SWAPOUT_SQLAC_WITH}
1080 and
1081 ( $sqlac_like ) = $ENV{DBICDEVREL_SWAPOUT_SQLAC_WITH} =~ /(.+)/
1082 and
1083 # delay calling ->sql_maker as long as we can
1084 # ensure_class_loaded returns undef or throws
1085 ( Class::C3::Componentised->ensure_class_loaded( $sqlac_like ), 1 )
1086 and
1087 ( ref $_[0]->sql_maker ) !~ /__REBASED__/
1088 ) {
1089  
1090 require DBIx::Class::SQLMaker::ClassicExtensions;
1091 require SQL::Abstract::Classic;
1092  
1093 Class::C3::Componentised->inject_base(
1094 'DBICDevRel::SQLAC::SwapOut',
1095 'DBIx::Class::SQLMaker::ClassicExtensions',
1096 $sqlac_like,
1097 'SQL::Abstract::Classic',
1098 );
1099  
1100 $_[0]->_do_connection_actions(connect_call_ => [[ rebase_sqlmaker => 'DBICDevRel::SQLAC::SwapOut' ]]);
1101 }
1102 }
1103  
1104  
1105  
1106 286 ▶sub set_use_dbms_capability {
Subroutine set_use_dbms_capability: called CC=1 SCAR=0.0
Pod undocumented
1107 286 $_[0]->set_inherited ($_[1], $_[2]);
1108 }
1109  
1110 sub get_use_dbms_capability {
1111 my ($self, $capname) = @_;
1112  
1113 my $use = $self->get_inherited ($capname);
1114 return defined $use
1115 ? $use
1116 : do { $capname =~ s/^_use_/_supports_/; $self->get_dbms_capability ($capname) }
1117 ;
1118 }
1119  
1120 169 ▶sub set_dbms_capability {
Subroutine set_dbms_capability: called CC=1 SCAR=0.0
Pod undocumented
1121 169 $_[0]->_dbh_details->{capability}{$_[1]} = $_[2];
1122 }
1123  
1124 sub get_dbms_capability {
1125 my ($self, $capname) = @_;
1126  
1127 my $cap = $self->_dbh_details->{capability}{$capname};
1128  
1129 unless (defined $cap) {
1130 if (my $meth = $self->can ("_determine$capname")) {
1131 $cap = $self->$meth ? 1 : 0;
1132 }
1133 else {
1134 $cap = 0;
1135 }
1136  
1137 $self->set_dbms_capability ($capname, $cap);
1138 }
1139  
1140 return $cap;
1141 }
1142  
1143 sub _server_info {
1144 my $self = shift;
1145  
1146 my $info;
1147 unless ($info = $self->_dbh_details->{info}) {
1148  
1149 $info = {};
1150 # this guarantees that problematic conninfo won't be hidden
1151 # by the try{} below
1152 $self->ensure_connected;
1153  
1154 my $server_version = try {
1155 $self->_get_server_version
1156 } catch {
1157 # driver determination *may* use this codepath
1158 # in which case we must rethrow
1159 $self->throw_exception($_) if $self->{_in_determine_driver};
1160  
1161 # $server_version on failure
1162 undef;
1163 };
1164  
1165 if (defined $server_version) {
1166 $info->{dbms_version} = $server_version;
1167  
1168 my ($numeric_version) = $server_version =~ /^([\d\.]+)/;
1169 my @verparts = split (/\./, $numeric_version);
1170 if (
1171 @verparts
1172 &&
1173 $verparts[0] <= 999
1174 ) {
1175 # consider only up to 3 version parts, iff not more than 3 digits
1176 my @use_parts;
1177 while (@verparts && @use_parts < 3) {
1178 my $p = shift @verparts;
1179 last if $p > 999;
1180 push @use_parts, $p;
1181 }
1182 push @use_parts, 0 while @use_parts < 3;
1183  
1184 $info->{normalized_dbms_version} = sprintf "%d.%03d%03d", @use_parts;
1185 }
1186 }
1187  
1188 $self->_dbh_details->{info} = $info;
1189 }
1190  
1191 return $info;
1192 }
1193  
1194 sub _get_server_version {
1195 shift->_dbh_get_info('SQL_DBMS_VER');
1196 }
1197  
1198 1410 ▶sub _dbh_get_info {
Subroutine _dbh_get_info: called CC=3 SCAR=11.0
1199 1410 my ($self, $info) = @_;
1200  
1201 1410 ▶ if ($info =~ /[^0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ /[^0-9]/) 345 1065 1410
1202 1410 require DBI::Const::GetInfoType;
1203 345 $info = $DBI::Const::GetInfoType::GetInfoType{$info};
1204 179 ▶ $self->throw_exception("Info type '$_[1]' not provided by DBI::Const::GetInfoType")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info 3 342 345
1205 unless defined $info;
1206 }
1207  
1208 342 $self->_get_dbh->get_info($info);
1209 }
1210  
1211 6 ▶sub _describe_connection {
Subroutine _describe_connection: called CC=6 SCAR=18.3
1212 175 require DBI::Const::GetInfoReturn;
1213  
1214 1240 my $self = shift;
1215  
1216 6 my $drv;
1217 6 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
1218 6 $drv = $self->_extract_driver_from_connect_info;
1219 6 $self->ensure_connected;
1220 6 };
1221  
1222 6 ▶ $drv = "DBD::$drv" if $drv;
Branch: 1 branch
BranchTrueFalseTotal
if $drv 7 2 9
1223  
1224 6 my $res = do {
1225 6 local $SIG{__WARN__} = sigwarn_silencer(qr/Argument .+? isn't numeric in subroutine entry/);
1226 {
1227 DBIC_DSN => $self->_dbi_connect_info->[0],
1228 DBI_VER => DBI->VERSION,
1229 DBIC_VER => DBIx::Class->VERSION,
1230 DBIC_DRIVER => ref $self,
1231 $drv ? (
1232 DBD => $drv,
1233 4 ▶ DBD_VER => try { $drv->VERSION },
Subroutine __ANON__: called CC=1 SCAR=0.0
1234 6 ▶ ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$drv ? : 4 2 6
1235 }
1236 };
1237  
1238 # try to grab data even if we never managed to connect
1239 # will cover us in cases of an oddly broken half-connect
1240 6 for my $inf (
1241 #keys %DBI::Const::GetInfoType::GetInfoType,
1242 qw/
1243 SQL_CURSOR_COMMIT_BEHAVIOR
1244 SQL_CURSOR_ROLLBACK_BEHAVIOR
1245 SQL_CURSOR_SENSITIVITY
1246 SQL_DATA_SOURCE_NAME
1247 SQL_DBMS_NAME
1248 SQL_DBMS_VER
1249 SQL_DEFAULT_TXN_ISOLATION
1250 SQL_DM_VER
1251 SQL_DRIVER_NAME
1252 SQL_DRIVER_ODBC_VER
1253 SQL_DRIVER_VER
1254 SQL_EXPRESSIONS_IN_ORDERBY
1255 SQL_GROUP_BY
1256 SQL_IDENTIFIER_CASE
1257 SQL_IDENTIFIER_QUOTE_CHAR
1258 SQL_MAX_CATALOG_NAME_LEN
1259 SQL_MAX_COLUMN_NAME_LEN
1260 SQL_MAX_IDENTIFIER_LEN
1261 SQL_MAX_TABLE_NAME_LEN
1262 SQL_MULTIPLE_ACTIVE_TXN
1263 SQL_MULT_RESULT_SETS
1264 SQL_NEED_LONG_DATA_LEN
1265 SQL_NON_NULLABLE_COLUMNS
1266 SQL_ODBC_VER
1267 SQL_QUALIFIER_NAME_SEPARATOR
1268 SQL_QUOTED_IDENTIFIER_CASE
1269 SQL_TXN_CAPABLE
1270 SQL_TXN_ISOLATION_OPTION
1271 /
1272 ) {
1273 # some drivers barf on things they do not know about instead
1274 # of returning undef
1275 168 ▶ my $v = try { $self->_dbh_get_info($inf) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1276 168 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 168 0 168
1277  
1278 #my $key = sprintf( '%s(%s)', $inf, $DBI::Const::GetInfoType::GetInfoType{$inf} );
1279 0 my $expl = DBI::Const::GetInfoReturn::Explain($inf, $v);
1280 0 ▶ $res->{$inf} = DBI::Const::GetInfoReturn::Format($inf, $v) . ( $expl ? " ($expl)" : '' );
Branch: 1 branch
BranchTrueFalseTotal
$expl ? : 0 0 0
1281 }
1282  
1283 6 $res;
1284 }
1285  
1286 504 ▶sub _determine_driver {
Subroutine _determine_driver: called CC=10 SCAR=23.0
1287 504 my ($self) = @_;
1288  
1289 504 ▶ if ((not $self->_driver_determined) && (not $self->{_in_determine_driver})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_driver_determined || $self->{"_in_determine_driver"}) 438 66 504
Condition100%3/3
$self->_driver_determined || $self->{'_in_determine_driver'}
l!l&&r!l&&!r
633438
MC/DC100%2/2
$self->_driver_determined || $self->{'_in_determine_driver'}
$self->_driver_determined $self->{'_in_determine_driver'}
Truth table100%3/3
A || B
A= $self->_driver_determinedB= $self->{'_in_determine_driver'}
ABresult
1X1
011
000
1290 438 my $started_connected = 0;
1291 438 local $self->{_in_determine_driver} = 1;
1292  
1293 438 ▶ if (ref($self) eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq __PACKAGE__) 429 9 438
1294 429 my $driver;
1295 429 ▶ if ($self->_dbh) { # we are connected
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dbh) { } 396 33 429
1296 396 $driver = $self->_dbh->{Driver}{Name};
1297 396 $started_connected = 1;
1298 }
1299 else {
1300 33 $driver = $self->_extract_driver_from_connect_info;
1301 }
1302  
1303 429 ▶ if ($driver) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver) { } 427 2 429
1304 427 my $storage_class = "DBIx::Class::Storage::DBI::${driver}";
1305 427 ▶ if ($self->load_optional_class($storage_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->load_optional_class($storage_class)) { } 423 4 427
1306 423 mro::set_mro($storage_class, 'c3');
1307 423 bless $self, $storage_class;
1308 423 $self->_rebless();
1309 }
1310 else {
1311 4 $self->_warn_undetermined_driver(
1312 'This version of DBIC does not yet seem to supply a driver for '
1313 . "your particular RDBMS and/or connection method ('$driver')."
1314 );
1315 }
1316 }
1317 else {
1318 2 $self->_warn_undetermined_driver(
1319 'Unable to extract a driver name from connect info - this '
1320 . 'should not have happened.'
1321 );
1322 }
1323 }
1324  
1325 438 $self->_driver_determined(1);
1326  
1327 438 Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
1328  
1329 438 ▶ if ($self->can('source_bind_attributes')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("source_bind_attributes")) 1 437 438
1330 1 $self->throw_exception(
1331 1 "Your storage subclass @{[ ref $self ]} provides (or inherits) the method "
1332 . 'source_bind_attributes() for which support has been removed as of Jan 2013. '
1333 . 'If you are not sure how to proceed please contact the development team via '
1334 . DBIx::Class::_ENV_::HELP_URL
1335 );
1336 }
1337  
1338 437 $self->_init; # run driver-specific initializations
1339  
1340 437 ▶ $self->_run_connection_actions
Branch: 1 branch
BranchTrueFalseTotal
if not $started_connected and defined $self->_dbh 7 430 437
Condition100%3/3
not $started_connected and defined $self->_dbh
!ll&&!rl&&r
396347
MC/DC100%2/2
not $started_connected and defined $self->_dbh
not $started_connected defined $self->_dbh
Truth table100%3/3
not(A) and B
A= not $started_connectedB= defined $self->_dbh
ABresult
0X0
100
111
1341 if !$started_connected && defined $self->_dbh;
1342 }
1343 }
1344  
1345 39 ▶sub _extract_driver_from_connect_info {
Subroutine _extract_driver_from_connect_info: called CC=5 SCAR=16.2
1346 39 my $self = shift;
1347  
1348 39 my $drv;
1349  
1350 # if connect_info is a CODEREF, we have no choice but to connect
1351 39 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->_dbi_connect_info->[0] and builtin::reftype($self->_dbi_connect_info->[0]) eq 'CODE') { } 3 36 39
Condition66%2/3
ref $self->_dbi_connect_info->[0] and builtin::reftype($self->_dbi_connect_info->[0]) eq "CODE"
!ll&&!rl&&r
3603
MC/DC50%1/2
ref $self->_dbi_connect_info->[0] and builtin::reftype($self->_dbi_connect_info->[0]) eq "CODE"
ref $self->_dbi_connect_info->[0] builtin::reftype($self->_dbi_connect_info->[0]) eq "CODE"
Truth table66%2/3
A and B
A= ref $self->_dbi_connect_info->[0]B= builtin::reftype($self->_dbi_connect_info->[0]) eq "CODE"
ABresult
0X0
100
111
1352 ref $self->_dbi_connect_info->[0]
1353 and
1354 reftype $self->_dbi_connect_info->[0] eq 'CODE'
1355 ) {
1356 3 $self->_populate_dbh;
1357 3 $drv = $self->_dbh->{Driver}{Name};
1358 }
1359 else {
1360 # try to use dsn to not require being connected, the driver may still
1361 # force a connection later in _rebless to determine version
1362 # (dsn may not be supplied at all if all we do is make a mock-schema)
1363 #
1364 # Use the same regex as the one used by DBI itself (even if the use of
1365 # \w is odd given unicode):
1366 # https://metacpan.org/source/TIMB/DBI-1.634/DBI.pm#L621
1367 #
1368 # DO NOT use https://metacpan.org/source/TIMB/DBI-1.634/DBI.pm#L559-566
1369 # as there is a long-standing precedent of not loading DBI.pm until the
1370 # very moment we are actually connecting
1371 #
1372 36 ▶ ($drv) = ($self->_dbi_connect_info->[0] || '') =~ /^dbi:(\w*)/i;
Condition50%1/2
$self->_dbi_connect_info->[0] || ''
l!l
360
MC/DC0%0/1
$self->_dbi_connect_info->[0] || ''
$self->_dbi_connect_info->[0]
Truth table50%1/2
A
A= $self->_dbi_connect_info->[0]
Aresult
11
00
1373 36 ▶ $drv ||= $ENV{DBI_DRIVER};
Condition100%3/3
$drv ||= $ENV{"DBI_DRIVER"}
l!l&&r!l&&!r
2844
MC/DC100%2/2
$drv ||= $ENV{"DBI_DRIVER"}
$drv $ENV{"DBI_DRIVER"}
Truth table100%3/3
A ||= B
A= $drvB= $ENV{"DBI_DRIVER"}
ABresult
1X1
011
000
1374 }
1375  
1376 39 return $drv;
1377 }
1378  
1379 0 ▶sub _determine_connector_driver {
Subroutine _determine_connector_driver: not called CC=4 SCAR=30.0
1380 0 my ($self, $conn) = @_;
1381  
1382 0 my $dbtype = $self->_dbh_get_info('SQL_DBMS_NAME');
1383  
1384 0 ▶ if (not $dbtype) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbtype) 0 0 0
1385 0 $self->_warn_undetermined_driver(
1386 'Unable to retrieve RDBMS type (SQL_DBMS_NAME) of the engine behind your '
1387 . "$conn connector - this should not have happened."
1388 );
1389 0 return;
1390 }
1391  
1392 0 $dbtype =~ s/\W/_/gi;
1393  
1394 0 my $subclass = "DBIx::Class::Storage::DBI::${conn}::${dbtype}";
1395 0 ▶ return if $self->isa($subclass);
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa($subclass) 0 0 0
1396  
1397 0 ▶ if ($self->load_optional_class($subclass)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->load_optional_class($subclass)) { } 0 0 0
1398 0 bless $self, $subclass;
1399 0 $self->_rebless;
1400 }
1401 else {
1402 0 $self->_warn_undetermined_driver(
1403 'This version of DBIC does not yet seem to supply a driver for '
1404 . "your particular RDBMS and/or connection method ('$conn/$dbtype')."
1405 );
1406 }
1407 }
1408  
1409 6 ▶sub _warn_undetermined_driver {
Subroutine _warn_undetermined_driver: called CC=1 SCAR=0.0
1410 6 my ($self, $msg) = @_;
1411  
1412 6 require Data::Dumper::Concise;
1413  
1414 6 carp_once ($msg . ' While we will attempt to continue anyway, the results '
1415 . 'are likely to be underwhelming. Please upgrade DBIC, and if this message '
1416 . "does not go away, file a bugreport including the following info:\n"
1417 . Data::Dumper::Concise::Dumper($self->_describe_connection)
1418 );
1419 }
1420  
1421 1837 ▶sub _do_connection_actions {
Subroutine _do_connection_actions: called CC=1 SCAR=0.0
1422 1837 my ($self, $method_prefix, $call, @args) = @_;
1423  
1424 1837 ▶ try {
Subroutine __ANON__: called CC=7 SCAR=19.6
1425 1837 ▶ if (not ref($call)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $call) { } 26 1811 1837
elsif (ref $call eq 'CODE') { } 900 911 1811
elsif (ref $call eq 'ARRAY') { } 911 0 911
1426 26 my $method = $method_prefix . $call;
1427 26 $self->$method(@args);
1428 }
1429 elsif (ref($call) eq 'CODE') {
1430 900 $self->$call(@args);
1431 }
1432 elsif (ref($call) eq 'ARRAY') {
1433 911 ▶ if (ref($call->[0]) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $call->[0] ne 'ARRAY') { } 447 464 911
1434 447 $self->_do_connection_actions($method_prefix, $_) for @$call;
1435 }
1436 else {
1437 464 $self->_do_connection_actions($method_prefix, @$_) for @$call;
1438 }
1439 }
1440 else {
1441 0 $self->throw_exception (sprintf ("Don't know how to process conection actions of type '%s'", ref($call)) );
1442 }
1443 }
1444 29 ▶ catch {
Subroutine __ANON__: called CC=2 SCAR=6.9
1445 29 ▶ if ( $method_prefix =~ /^connect/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method_prefix =~ /^connect/) { } 26 3 29
1446 # this is an on_connect cycle - we can't just throw while leaving
1447 # a handle in an undefined state in our storage object
1448 # kill it with fire and rethrow
1449 26 $self->_dbh(undef);
1450 26 $self->throw_exception( $_[0] );
1451 }
1452 else {
1453 3 carp "Disconnect action failed: $_[0]";
1454 }
1455 1837 };
1456  
1457 1811 return $self;
1458 }
1459  
1460 12 ▶sub connect_call_do_sql {
Subroutine connect_call_do_sql: called CC=1 SCAR=0.0
Pod undocumented
1461 12 my $self = shift;
1462 12 $self->_do_query(@_);
1463 }
1464  
1465 4 ▶sub disconnect_call_do_sql {
Subroutine disconnect_call_do_sql: called CC=1 SCAR=0.0
Pod undocumented
1466 4 my $self = shift;
1467 4 $self->_do_query(@_);
1468 }
1469  
1470 =head2 connect_call_datetime_setup
1471  
1472 A no-op stub method, provided so that one can always safely supply the
1473 L<connection option|/DBIx::Class specific connection attributes>
1474  
1475 on_connect_call => 'datetime_setup'
1476  
1477 This way one does not need to know in advance whether the underlying
1478 storage requires any sort of hand-holding when dealing with calendar
1479 data.
1480  
1481 =cut
1482  
1483 0 ▶sub connect_call_datetime_setup { 1 }
Subroutine connect_call_datetime_setup: not called CC=1 SCAR=6.9
Pod documented
1484  
1485 20 ▶sub _do_query {
Subroutine _do_query: called CC=4 SCAR=13.9
1486 20 my ($self, $action) = @_;
1487  
1488 20 ▶ if (ref $action eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $action eq 'CODE') { } 4 16 20
1489 4 $action = $action->($self);
1490 4 $self->_do_query($_) foreach @$action;
1491 }
1492 else {
1493 # Most debuggers expect ($sql, @bind), so we need to exclude
1494 # the attribute hash which is the second argument to $dbh->do
1495 # furthermore the bind values are usually to be presented
1496 # as named arrayref pairs, so wrap those here too
1497 16 ▶ my @do_args = (ref $action eq 'ARRAY') ? (@$action) : ($action);
Branch: 1 branch
BranchTrueFalseTotal
ref $action eq 'ARRAY' ? : 3 13 16
1498 16 my $sql = shift @do_args;
1499 16 my $attrs = shift @do_args;
1500 16 my @bind = map { [ undef, $_ ] } @do_args;
1501  
1502 16 ▶ $self->dbh_do(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1503 16 $_[0]->_query_start($sql, \@bind);
1504 16 $_[1]->do($sql, $attrs, @do_args);
1505 11 $_[0]->_query_end($sql, \@bind);
1506 16 });
1507 }
1508  
1509 15 return $self;
1510 }
1511  
1512 =head2 connect_call_rebase_sqlmaker
1513  
1514 This on-connect call takes as a single argument the name of a class to "rebase"
1515 the SQLMaker inheritance hierarchy upon. For this to work properly the target
1516 class B<MUST> inherit from L<DBIx::Class::SQLMaker::ClassicExtensions> and
1517 L<SQL::Abstract::Classic> as shown below.
1518  
1519 This infrastructure is provided to aid recent activity around experimental new
1520 aproaches to SQL generation within DBIx::Class. You can (and are encouraged to)
1521 mix and match old and new within the same codebase as follows:
1522  
1523 package DBIx::Class::Awesomer::SQLMaker;
1524 # you MUST inherit in this order to get the composition right
1525 # you are free to override-without-next::method any part you need
1526 use base qw(
1527 DBIx::Class::SQLMaker::ClassicExtensions
1528 << OPTIONAL::AWESOME::Class::Implementing::ExtraRainbowSauce >>
1529 SQL::Abstract::Classic
1530 );
1531 << your new code goes here >>
1532  
1533  
1534 ... and then ...
1535  
1536  
1537 my $experimental_schema = $original_schema->connect(
1538 sub {
1539 $original_schema->storage->dbh
1540 },
1541 {
1542 # the nested arrayref is important, as per
1543 # https://metacpan.org/pod/DBIx::Class::Storage::DBI#on_connect_call
1544 on_connect_call => [ [ rebase_sqlmaker => 'DBIx::Class::Awesomer::SQLMaker' ] ],
1545 },
1546 );
1547  
1548 =cut
1549  
1550 1 ▶sub connect_call_rebase_sqlmaker {
Subroutine connect_call_rebase_sqlmaker: called CC=7 SCAR=20.1
Pod documented
1551 1 my( $self, $requested_base_class ) = @_;
1552  
1553 1 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 or not length $requested_base_class 0 1 1
Condition33%1/3
@_ != 2 or not length $requested_base_class
l!l&&r!l&&!r
001
MC/DC0%0/2
@_ != 2 or not length $requested_base_class
@_ != 2 not length $requested_base_class
Truth table33%1/3
A or not(B)
A= @_ != 2B= not length $requested_base_class
ABresult
1X1
011
000
1554 "The on_connect callee 'rebase_sqlmaker' expects a single plain string argument: the name of the target base class"
1555 ) if (
1556 @_ != 2
1557 or
1558 ! length( $requested_base_class )
1559 );
1560  
1561 1 my $old_class = ref( $self->sql_maker );
1562  
1563 # nothing to do!
1564 1 ▶ return if $old_class->isa( $requested_base_class );
Branch: 1 branch
BranchTrueFalseTotal
if $old_class->isa($requested_base_class) 0 1 1
1565  
1566 1 my $synthetic_class = "${old_class}__REBASED_ON__${requested_base_class}";
1567  
1568 {
1569 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1570  
1571 # skip if we already made that class
1572 1 ▶ unless( @{"${synthetic_class}::ISA"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{"${synthetic_class}::ISA";}) 1 0 1
1573  
1574 1 $self->ensure_class_loaded( $requested_base_class );
1575  
1576 1 for my $base (qw(
1577 DBIx::Class::SQLMaker::ClassicExtensions
1578 SQL::Abstract::Classic
1579 )) {
1580  
1581 2 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $requested_base_class->isa($base) 0 2 2
1582 "The 'rebase_sqlmaker' target class '$requested_base_class' is not inheriting from '$base', this can not work"
1583 ) unless $requested_base_class->isa( $base );
1584 }
1585  
1586 1 $self->inject_base( $synthetic_class, $old_class, $requested_base_class );
1587  
1588 1 Class::C3->reinitialize
1589 if DBIx::Class::_ENV_::OLD_MRO;
1590 }
1591 }
1592  
1593 # force re-build on next access for this particular $storage instance
1594 1 $self->sql_maker_class( $synthetic_class );
1595 1 $self->_sql_maker( undef );
1596 }
1597  
1598 649 ▶sub _connect {
Subroutine _connect: called CC=4 SCAR=14.2
1599 649 my $self = shift;
1600  
1601 649 my $info = $self->_dbi_connect_info;
1602  
1603 649 ▶ $self->throw_exception("You did not provide any connection_info")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->[0] 3 646 649
1604 unless defined $info->[0];
1605  
1606 646 my ($old_connect_via, $dbh);
1607  
1608 646 ▶ local $DBI::connect_via = 'connect' if $INC{'Apache/DBI.pm'} && $ENV{MOD_PERL};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"} 0 646 646
Condition33%1/3
$INC{"Apache/DBI.pm"} and $ENV{"MOD_PERL"}
!ll&&!rl&&r
64600
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
1609  
1610 # this odd anonymous coderef dereference is in fact really
1611 # necessary to avoid the unwanted effect described in perl5
1612 # RT#75792
1613 #
1614 # in addition the coderef itself can't reside inside the try{} block below
1615 # as it somehow triggers a leak under perl -d
1616 466 ▶ my $dbh_error_handler_installer = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1617 466 weaken (my $weak_self = $_[0]);
1618  
1619 # the coderef is blessed so we can distinguish it from externally
1620 # supplied handles (which must be preserved)
1621 43 ▶ $_[1]->{HandleError} = bless sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1622 43 ▶ if ($weak_self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak_self) { } 42 1 43
1623 42 $weak_self->throw_exception("DBI Exception: $_[0]");
1624 }
1625 else {
1626 # the handler may be invoked by something totally out of
1627 # the scope of DBIC
1628 1 DBIx::Class::Exception->throw("DBI Exception (unhandled by DBIC, ::Schema GCed): $_[0]");
1629 }
1630 466 }, '__DBIC__DBH__ERROR__HANDLER__';
1631 646 };
1632  
1633 646 ▶ try {
Subroutine __ANON__: called CC=10 SCAR=24.6
1634 646 ▶ if(ref $info->[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->[0] eq 'CODE') { } 6 640 646
1635 6 $dbh = $info->[0]->();
1636 }
1637 else {
1638 640 require DBI;
1639 640 $dbh = DBI->connect(@$info);
1640 }
1641  
1642 466 ▶ die $DBI::errstr unless $dbh;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh 0 466 466
1643  
1644 466 ▶ die sprintf ("%s fresh DBI handle with a *false* 'Active' attribute. "
Branch: 2 branches
BranchTrueFalseTotal
unless $dbh->FETCH("Active") 0 466 466
ref $info->[0] eq 'CODE' ? : 0 0 0
1645 . 'This handle is disconnected as far as DBIC is concerned, and we can '
1646 . 'not continue',
1647 ref $info->[0] eq 'CODE'
1648 ? "Connection coderef $info->[0] returned a"
1649 : 'DBI->connect($schema->storage->connect_info) resulted in a'
1650 ) unless $dbh->FETCH('Active');
1651  
1652 # sanity checks unless asked otherwise
1653 466 ▶ unless ($self->unsafe) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->unsafe) 466 0 466
1654  
1655 $self->throw_exception(
1656 'Refusing clobbering of {HandleError} installed on externally supplied '
1657 ."DBI handle $dbh. Either remove the handler or use the 'unsafe' attribute."
1658 466 ▶ ) if $dbh->{HandleError} and ref $dbh->{HandleError} ne '__DBIC__DBH__ERROR__HANDLER__';
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"HandleError"} and ref $dbh->{"HandleError"} ne "__DBIC__DBH__ERROR__HANDLER__" 0 466 466
Condition66%2/3
$dbh->{"HandleError"} and ref $dbh->{"HandleError"} ne "__DBIC__DBH__ERROR__HANDLER__"
!ll&&!rl&&r
46330
MC/DC0%0/2
$dbh->{"HandleError"} and ref $dbh->{"HandleError"} ne "__DBIC__DBH__ERROR__HANDLER__"
$dbh->{"HandleError"} ref $dbh->{"HandleError"} ne "__DBIC__DBH__ERROR__HANDLER__"
Truth table66%2/3
A and B
A= $dbh->{"HandleError"}B= ref $dbh->{"HandleError"} ne "__DBIC__DBH__ERROR__HANDLER__"
ABresult
0X0
100
111
1659  
1660 # Default via _default_dbi_connect_attributes is 1, hence it was an explicit
1661 # request, or an external handle. Complain and set anyway
1662 466 ▶ unless ($dbh->{RaiseError}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh->{"RaiseError"}) 2 464 466
1663 2 ▶ carp( ref $info->[0] eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $info->[0] eq 'CODE' ? : 2 0 2
1664  
1665 ? "The 'RaiseError' of the externally supplied DBI handle is set to false. "
1666 ."DBIx::Class will toggle it back to true, unless the 'unsafe' connect "
1667 .'attribute has been supplied'
1668  
1669 : 'RaiseError => 0 supplied in your connection_info, without an explicit '
1670 .'unsafe => 1. Toggling RaiseError back to true'
1671 );
1672  
1673 2 $dbh->{RaiseError} = 1;
1674 }
1675  
1676 466 $dbh_error_handler_installer->($self, $dbh);
1677 }
1678 }
1679 180 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
1680 180 $self->throw_exception("DBI Connection failed: $_")
1681 646 };
1682  
1683 466 $self->_dbh_autocommit($dbh->{AutoCommit});
1684 466 return $dbh;
1685 }
1686  
1687 8 ▶sub txn_begin {
Subroutine txn_begin: called CC=2 SCAR=7.6
1688 # this means we have not yet connected and do not know the AC status
1689 # (e.g. coderef $dbh), need a full-fledged connection check
1690 40 ▶ if (! defined $_[0]->_dbh_autocommit) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[0]->_dbh_autocommit) { } 6 8 14
1691 8 $_[0]->ensure_connected;
1692 }
1693 # Otherwise simply connect or re-connect on pid changes
1694 else {
1695 0 $_[0]->_get_dbh;
1696 }
1697  
1698 0 shift->next::method(@_);
1699 }
1700  
1701 18044 ▶sub _exec_txn_begin {
Subroutine _exec_txn_begin: called CC=2 SCAR=6.9
1702 18044 my $self = shift;
1703  
1704 # if the user is utilizing txn_do - good for him, otherwise we need to
1705 # ensure that the $dbh is healthy on BEGIN.
1706 # We do this via ->dbh_do instead of ->dbh, so that the ->dbh "ping"
1707 # will be replaced by a failure of begin_work itself (which will be
1708 # then retried on reconnect)
1709 8668 ▶ if ($self->{_in_do_block}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_in_do_block'}) { } 297 17747 18044
1710 9669 $self->_dbh->begin_work;
1711 } else {
1712 17751 ▶ $self->dbh_do(sub { $_[1]->begin_work });
Subroutine __ANON__: called CC=1 SCAR=0.0
1713 }
1714 }
1715  
1716 9098 ▶sub txn_commit {
Subroutine txn_commit: called CC=7 SCAR=23.4
Pod documented
1717 9098 my $self = shift;
1718  
1719 9098 ▶ $self->throw_exception("Unable to txn_commit() on a disconnected storage")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_seems_connected 0 9098 9098
1720 unless $self->_seems_connected;
1721  
1722 # esoteric case for folks using external $dbh handles
1723 9098 ▶ if (! $self->transaction_depth and ! $self->_dbh->FETCH('AutoCommit') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->transaction_depth or $self->_dbh->FETCH("AutoCommit")) 0 9098 9098
Condition33%1/3
$self->transaction_depth or $self->_dbh->FETCH("AutoCommit")
l!l&&r!l&&!r
909800
MC/DC0%0/2
$self->transaction_depth or $self->_dbh->FETCH("AutoCommit")
$self->transaction_depth $self->_dbh->FETCH("AutoCommit")
Truth table33%1/3
A or B
A= $self->transaction_depthB= $self->_dbh->FETCH("AutoCommit")
ABresult
1X1
011
000
1724 0 carp "Storage transaction_depth 0 does not match "
1725 ."false AutoCommit of $self->{_dbh}, attempting COMMIT anyway";
1726 0 $self->transaction_depth(1);
1727 }
1728  
1729 9098 $self->next::method(@_);
1730  
1731 # if AutoCommit is disabled txn_depth never goes to 0
1732 # as a new txn is started immediately on commit
1733 9098 ▶ $self->transaction_depth(1) if (
Branch: 1 branch
BranchTrueFalseTotal
if not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit 0 9098 9098
Condition66%4/6
not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit
!ll&&!rl&&r
60084980
not $self->transaction_depth and defined $self->_dbh_autocommit
!ll&&!rl&&r
60008498
MC/DC0%0/3
not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit
not $self->transaction_depth defined $self->_dbh_autocommit not $self->_dbh_autocommit
Truth table50%2/4
not(A) and B and not(C)
A= not $self->transaction_depthB= defined $self->_dbh_autocommitC= not $self->_dbh_autocommit
ABCresult
0XX0
10X0
1100
1111
1734 !$self->transaction_depth
1735 and
1736 defined $self->_dbh_autocommit
1737 and
1738 ! $self->_dbh_autocommit
1739 );
1740 }
1741  
1742 8498 ▶sub _exec_txn_commit {
Subroutine _exec_txn_commit: called CC=1 SCAR=0.0
1743 8498 shift->_dbh->commit;
1744 }
1745  
1746 244 ▶sub txn_rollback {
Subroutine txn_rollback: called CC=7 SCAR=23.4
Pod documented
1747 244 my $self = shift;
1748  
1749 244 ▶ $self->throw_exception("Unable to txn_rollback() on a disconnected storage")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_seems_connected 0 244 244
1750 unless $self->_seems_connected;
1751  
1752 # esoteric case for folks using external $dbh handles
1753 244 ▶ if (! $self->transaction_depth and ! $self->_dbh->FETCH('AutoCommit') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->transaction_depth or $self->_dbh->FETCH("AutoCommit")) 0 244 244
Condition33%1/3
$self->transaction_depth or $self->_dbh->FETCH("AutoCommit")
l!l&&r!l&&!r
24400
MC/DC0%0/2
$self->transaction_depth or $self->_dbh->FETCH("AutoCommit")
$self->transaction_depth $self->_dbh->FETCH("AutoCommit")
Truth table33%1/3
A or B
A= $self->transaction_depthB= $self->_dbh->FETCH("AutoCommit")
ABresult
1X1
011
000
1754 0 carp "Storage transaction_depth 0 does not match "
1755 ."false AutoCommit of $self->{_dbh}, attempting ROLLBACK anyway";
1756 0 $self->transaction_depth(1);
1757 }
1758  
1759 244 $self->next::method(@_);
1760  
1761 # if AutoCommit is disabled txn_depth never goes to 0
1762 # as a new txn is started immediately on commit
1763 132 ▶ $self->transaction_depth(1) if (
Branch: 1 branch
BranchTrueFalseTotal
if not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit 0 132 132
Condition66%4/6
not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit
!ll&&!rl&&r
21300
not $self->transaction_depth and defined $self->_dbh_autocommit
!ll&&!rl&&r
20130
MC/DC0%0/3
not $self->transaction_depth and defined $self->_dbh_autocommit and not $self->_dbh_autocommit
not $self->transaction_depth defined $self->_dbh_autocommit not $self->_dbh_autocommit
Truth table50%2/4
not(A) and B and not(C)
A= not $self->transaction_depthB= defined $self->_dbh_autocommitC= not $self->_dbh_autocommit
ABCresult
0XX0
10X0
1100
1111
1764 !$self->transaction_depth
1765 and
1766 defined $self->_dbh_autocommit
1767 and
1768 ! $self->_dbh_autocommit
1769 );
1770 }
1771  
1772 130 ▶sub _exec_txn_rollback {
Subroutine _exec_txn_rollback: called CC=1 SCAR=0.0
1773 130 shift->_dbh->rollback;
1774 }
1775  
1776 # generate the DBI-specific stubs, which then fallback to ::Storage proper
1777 266 quote_sub __PACKAGE__ . "::$_" => sprintf (<<'EOS', $_) for qw(svp_begin svp_release svp_rollback);
1778 $_[0]->throw_exception('Unable to %s() on a disconnected storage')
1779 unless $_[0]->_seems_connected;
1780 shift->next::method(@_);
1781 EOS
1782  
1783 # This used to be the top-half of _execute. It was split out to make it
1784 # easier to override in NoBindVars without duping the rest. It takes up
1785 # all of _execute's args, and emits $sql, @bind.
1786 17711 ▶sub _prep_for_execute {
Subroutine _prep_for_execute: called CC=1 SCAR=0.0
1787 #my ($self, $op, $ident, $args) = @_;
1788 17711 return shift->_gen_sql_bind(@_)
1789 }
1790  
1791 18470 ▶sub _gen_sql_bind {
Subroutine _gen_sql_bind: called CC=9 SCAR=22.5
1792 18470 my ($self, $op, $ident, $args) = @_;
1793  
1794 18470 my ($colinfos, $from);
1795 18470 ▶ if ( blessed($ident) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ident)) 10613 7857 18470
1796 10613 $from = $ident->from;
1797 10613 $colinfos = $ident->columns_info;
1798 }
1799  
1800 18470 my ($sql, $bind);
1801 18470 ▶ ($sql, @$bind) = $self->sql_maker->$op( ($from || $ident), @$args );
Condition66%2/3
$from || $ident
l!l&&r!l&&!r
1061378570
MC/DC0%0/2
$from || $ident
$from $ident
Truth table66%2/3
A || B
A= $fromB= $ident
ABresult
1X1
011
000
1802  
1803 $bind = $self->_resolve_bindattrs(
1804 18466 ▶ $ident, [ @{$args->[2]{bind}||[]}, @$bind ], $colinfos
Condition100%2/2
$args->[2]{'bind'} || []
l!l
763410832
MC/DC100%1/1
$args->[2]{'bind'} || []
$args->[2]{'bind'}
Truth table100%2/2
A
A= $args->[2]{'bind'}
Aresult
11
00
1805 );
1806  
1807 18466 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{"DBIC_DT_SEARCH_OK"} and $op eq "select" and grep {length ref $_->[1] and builtin::blessed($_->[1]) and $_->[1]->isa("DateTime");} @$bind) 0 18466 18466
Condition66%4/6
not $ENV{"DBIC_DT_SEARCH_OK"} and $op eq "select" and grep {length ref $_->[1] and builtin::blessed($_->[1]) and $_->[1]->isa("DateTime");} @$bind
!ll&&!rl&&r
1061378530
not $ENV{"DBIC_DT_SEARCH_OK"} and $op eq "select"
!ll&&!rl&&r
0106137853
MC/DC0%0/3
not $ENV{"DBIC_DT_SEARCH_OK"} and $op eq "select" and grep {length ref $_->[1] and builtin::blessed($_->[1]) and $_->[1]->isa("DateTime");} @$bind
not $ENV{"DBIC_DT_SEARCH_OK"} $op eq "select" grep {length ref $_->[1] and builtin::blessed($_->[1]) and $_->[1]->isa("DateTime");} @$bind
Truth table50%2/4
not(A) and B and C
A= not $ENV{"DBIC_DT_SEARCH_OK"}B= $op eq "select"C= grep {length ref $_->[1] and builtin::blessed($_->[1]) and $_->[1]->isa("DateTime");} @$bind
ABCresult
0XX0
10X0
1100
1111
1808 ! $ENV{DBIC_DT_SEARCH_OK}
1809 and
1810 $op eq 'select'
1811 and
1812 grep {
1813 13971 ▶ length ref $_->[1]
Condition83%5/6
length ref $_->[1] && builtin::blessed($_->[1]) && $_->[1]->isa('DateTime')
!ll&&!rl&&r
1396740
length ref $_->[1] and builtin::blessed($_->[1])
!ll&&!rl&&r
1396254
MC/DC0%0/3
length ref $_->[1] && builtin::blessed($_->[1]) && $_->[1]->isa('DateTime')
length ref $_->[1] builtin::blessed($_->[1]) $_->[1]->isa('DateTime')
Truth table75%3/4
A and B && C
A= length ref $_->[1]B= builtin::blessed($_->[1])C= $_->[1]->isa('DateTime')
ABCresult
0XX0
10X0
1100
1111
1814 and
1815 blessed($_->[1])
1816 and
1817 $_->[1]->isa('DateTime')
1818 } @$bind
1819 ) {
1820 0 carp_unique 'DateTime objects passed to search() are not supported '
1821 . 'properly (InflateColumn::DateTime formats and settings are not '
1822 . 'respected.) See ".. format a DateTime object for searching?" in '
1823 . 'DBIx::Class::Manual::FAQ. To disable this warning for good '
1824 . 'set $ENV{DBIC_DT_SEARCH_OK} to true'
1825 }
1826  
1827 18466 return( $sql, $bind );
1828 }
1829  
1830 18545 ▶sub _resolve_bindattrs {
Subroutine _resolve_bindattrs: called CC=9 SCAR=22.1
1831 18545 my ($self, $ident, $bind, $colinfos) = @_;
1832  
1833 40683 ▶ my $resolve_bindinfo = sub {
Subroutine __ANON__: called CC=8 SCAR=21.1
1834 #my $infohash = shift;
1835  
1836 40683 ▶ $colinfos ||= { %{ $self->_resolve_column_info($ident) } };
Condition100%2/2
$colinfos ||= {%{$self->_resolve_column_info($ident);}}
l!l
341846499
MC/DC100%1/1
$colinfos ||= {%{$self->_resolve_column_info($ident);}}
$colinfos
Truth table100%2/2
A
A= $colinfos
Aresult
11
00
1837  
1838 40683 my $ret;
1839 40683 ▶ if (my $col = $_[0]->{dbic_colname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $_[0]{"dbic_colname"}) 40674 9 40683
1840 40674 $ret = { %{$_[0]} };
1841  
1842 $ret->{sqlt_datatype} ||= $colinfos->{$col}{data_type}
1843 40674 ▶ if $colinfos->{$col}{data_type};
Branch: 1 branch
BranchTrueFalseTotal
if $colinfos->{$col}{"data_type"} 40567 107 40674
Condition33%1/3
$ret->{"sqlt_datatype"} ||= $colinfos->{$col}{"data_type"}
l!l&&r!l&&!r
0405670
MC/DC0%0/2
$ret->{"sqlt_datatype"} ||= $colinfos->{$col}{"data_type"}
$ret->{"sqlt_datatype"} $colinfos->{$col}{"data_type"}
Truth table33%1/3
A ||= B
A= $ret->{"sqlt_datatype"}B= $colinfos->{$col}{"data_type"}
ABresult
1X1
011
000
1844  
1845 $ret->{sqlt_size} ||= $colinfos->{$col}{size}
1846 40674 ▶ if $colinfos->{$col}{size};
Branch: 1 branch
BranchTrueFalseTotal
if $colinfos->{$col}{"size"} 10437 30237 40674
Condition33%1/3
$ret->{"sqlt_size"} ||= $colinfos->{$col}{"size"}
l!l&&r!l&&!r
0104370
MC/DC0%0/2
$ret->{"sqlt_size"} ||= $colinfos->{$col}{"size"}
$ret->{"sqlt_size"} $colinfos->{$col}{"size"}
Truth table33%1/3
A ||= B
A= $ret->{"sqlt_size"}B= $colinfos->{$col}{"size"}
ABresult
1X1
011
000
1847 }
1848  
1849 40683 ▶ $ret || $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$ret or $_[0] 40674 9 40683
1850 18545 };
1851  
1852 return [ map {
1853 18545 ( ref $_ ne 'ARRAY' or @$_ != 2 ) ? [ {}, $_ ]
1854 : ( ! defined $_->[0] ) ? [ {}, $_->[1] ]
1855 : (ref $_->[0] eq 'HASH') ? [(
1856 24213 ▶ ! keys %{$_->[0]}
Branch: 1 branch
BranchTrueFalseTotal
ref $_->[0] eq 'SCALAR' ? : 123 18822 18945
1857 or
1858 exists $_->[0]{dbd_attrs}
1859 or
1860 $_->[0]{sqlt_datatype}
1861 ) ? $_->[0]
1862 : $resolve_bindinfo->($_->[0])
1863 , $_->[1]
1864 ]
1865 43393 ▶ : (ref $_->[0] eq 'SCALAR') ? [ { sqlt_datatype => ${$_->[0]} }, $_->[1] ]
Branch: 4 branches
BranchTrueFalseTotal
ref $_ ne 'ARRAY' || @$_ != 2 ? : 199 43194 43393
!defined($_->[0]) ? : 36 43158 43194
ref $_->[0] eq 'HASH' ? : 24213 18945 43158
!keys(%{$$_[0];}) || exists $_->[0]{'dbd_attrs'} || $_->[0]{'sqlt_datatype'} ? : 2352 21861 24213
Condition88%8/9
ref $_ ne "ARRAY" or @$_ != 2
l!l&&r!l&&!r
197243194
not keys %{$$_[0];} or exists $_->[0]{"dbd_attrs"} or $_->[0]{"sqlt_datatype"}
l!l&&r!l&&!r
70228221861
not keys %{$$_[0];} or exists $_->[0]{"dbd_attrs"}
l!l&&r!l&&!r
70024143
MC/DC100%2/2
ref $_ ne "ARRAY" or @$_ != 2
ref $_ ne "ARRAY" @$_ != 2
MC/DC66%2/3
not keys %{$$_[0];} or exists $_->[0]{"dbd_attrs"} or $_->[0]{"sqlt_datatype"}
not keys %{$$_[0];} exists $_->[0]{"dbd_attrs"} $_->[0]{"sqlt_datatype"}
Truth table100%3/3
A or B
A= ref $_ ne "ARRAY"B= @$_ != 2
ABresult
1X1
011
000
Truth table75%3/4
not(A) or B or C
A= not keys %{$$_[0];}B= exists $_->[0]{"dbd_attrs"}C= $_->[0]{"sqlt_datatype"}
ABCresult
1XX1
01X1
0011
0000
1866 : [ $resolve_bindinfo->(
1867 { dbic_colname => $_->[0] }
1868 ), $_->[1] ]
1869 } @$bind ];
1870 }
1871  
1872 141 ▶sub _format_for_trace {
Subroutine _format_for_trace: called CC=4 SCAR=14.2
1873 #my ($self, $bind) = @_;
1874  
1875 ### Turn @bind from something like this:
1876 ### ( [ "artist", 1 ], [ \%attrs, 3 ] )
1877 ### to this:
1878 ### ( "'1'", "'3'" )
1879  
1880 map {
1881 144 ▶ defined( $_ && $_->[1] )
Branch: 1 branch
BranchTrueFalseTotal
defined($_ && $_->[1]) ? : 140 4 144
Condition66%2/3
$_ && $_->[1]
!ll&&!rl&&r
04140
MC/DC50%1/2
$_ && $_->[1]
$_ $_->[1]
Truth table66%2/3
A && B
A= $_B= $_->[1]
ABresult
0X0
100
111
1882 ? qq{'$_->[1]'}
1883 : q{NULL}
1884 141 ▶ } @{$_[1] || []};
Condition50%1/2
$_[1] || []
l!l
1410
MC/DC0%0/1
$_[1] || []
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
1885 }
1886  
1887 17717 ▶sub _query_start {
Subroutine _query_start: called CC=2 SCAR=6.9
1888 17717 my ( $self, $sql, $bind ) = @_;
1889  
1890 17717 ▶ $self->debugobj->query_start( $sql, $self->_format_for_trace($bind) )
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 149 17568 17717
1891 if $self->debug;
1892 }
1893  
1894 17688 ▶sub _query_end {
Subroutine _query_end: called CC=2 SCAR=6.9
1895 17688 my ( $self, $sql, $bind ) = @_;
1896  
1897 17688 ▶ $self->debugobj->query_end( $sql, $self->_format_for_trace($bind) )
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 144 17544 17688
1898 if $self->debug;
1899 }
1900  
1901 17697 ▶sub _dbi_attrs_for_bind {
Subroutine _dbi_attrs_for_bind: called CC=7 SCAR=19.5
1902 17697 my ($self, $ident, $bind) = @_;
1903  
1904 17697 my @attrs;
1905  
1906 17697 for (map { $_->[0] } @$bind) {
1907 41940 push @attrs, do {
1908 41940 ▶ if (exists $_->{dbd_attrs}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_->{'dbd_attrs'}) { } 0 41940 41940
elsif ($_->{'sqlt_datatype'}) { } 41786 154 41940
1909 $_->{dbd_attrs}
1910 0 }
1911 elsif($_->{sqlt_datatype}) {
1912 # cache the result in the dbh_details hash, as it can not change unless
1913 # we connect to something else
1914 41786 ▶ my $cache = $self->_dbh_details->{_datatype_map_cache} ||= {};
Condition100%2/2
$self->_dbh_details->{"_datatype_map_cache"} ||= {}
l!l
41412374
MC/DC100%1/1
$self->_dbh_details->{"_datatype_map_cache"} ||= {}
$self->_dbh_details->{"_datatype_map_cache"}
Truth table100%2/2
A
A= $self->_dbh_details->{"_datatype_map_cache"}
Aresult
11
00
1915 41786 ▶ if (not exists $cache->{$_->{sqlt_datatype}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$cache{$_->{"sqlt_datatype"}}) 2375 39411 41786
1916 2375 ▶ $cache->{$_->{sqlt_datatype}} = $self->bind_attribute_by_data_type($_->{sqlt_datatype}) || undef;
Condition100%2/2
$self->bind_attribute_by_data_type($_->{'sqlt_datatype'}) || undef
l!l
6771698
MC/DC100%1/1
$self->bind_attribute_by_data_type($_->{'sqlt_datatype'}) || undef
$self->bind_attribute_by_data_type($_->{'sqlt_datatype'})
Truth table100%2/2
A
A= $self->bind_attribute_by_data_type($_->{'sqlt_datatype'})
Aresult
11
00
1917 }
1918 41786 $cache->{$_->{sqlt_datatype}};
1919 }
1920 else {
1921 154 undef; # always push something at this position
1922 }
1923 }
1924 }
1925  
1926 17697 return \@attrs;
1927 }
1928  
1929 10083 ▶sub _execute {
Subroutine _execute: called CC=2 SCAR=6.9
1930 10083 my ($self, $op, $ident, @args) = @_;
1931  
1932 10083 my ($sql, $bind) = $self->_prep_for_execute($op, $ident, \@args);
1933  
1934 # not even a PID check - we do not care about the state of the _dbh.
1935 # All we need is to get the appropriate drivers loaded if they aren't
1936 # already so that the assumption in ad7c50fc26e holds
1937 10082 ▶ $self->_populate_dbh unless $self->_dbh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_dbh 14 10068 10082
1938  
1939 10076 $self->dbh_do( _dbh_execute => # retry over disconnects
1940 $sql,
1941 $bind,
1942 $self->_dbi_attrs_for_bind($ident, $bind),
1943 );
1944 }
1945  
1946 10078 ▶sub _dbh_execute {
Subroutine _dbh_execute: called CC=5 SCAR=18.4
1947 10078 my ($self, $dbh, $sql, $bind, $bind_attrs) = @_;
1948  
1949 10078 $self->_query_start( $sql, $bind );
1950  
1951 10077 my $sth = $self->_bind_sth_params(
1952 $self->_prepare_sth($dbh, $sql),
1953 $bind,
1954 $bind_attrs,
1955 );
1956  
1957 # Can this fail without throwing an exception anyways???
1958 10059 my $rv = $sth->execute();
1959 10056 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 10056 10056
Condition0%0/5
$sth->errstr || $sth->err || 'Unknown error: execute() returned false, but error flags were not set...'
l!l
00
$sth->errstr or $sth->err
l!l&&r!l&&!r
000
MC/DC0%0/2
$sth->errstr || $sth->err || 'Unknown error: execute() returned false, but error flags were not set...'
$sth->errstr $sth->err
Truth table0%0/3
A or B
A= $sth->errstrB= $sth->err
ABresult
1X1
011
000
1960 $sth->errstr || $sth->err || 'Unknown error: execute() returned false, but error flags were not set...'
1961 ) if !$rv;
1962  
1963 10056 $self->_query_end( $sql, $bind );
1964  
1965 10056 ▶ return (wantarray ? ($rv, $sth, @$bind) : $rv);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8568 1488 10056
1966 }
1967  
1968 17703 ▶sub _prepare_sth {
Subroutine _prepare_sth: called CC=5 SCAR=20.1
1969 17703 my ($self, $dbh, $sql) = @_;
1970  
1971 # 3 is the if_active parameter which avoids active sth re-use
1972 17703 ▶ my $sth = $self->disable_sth_caching
Branch: 1 branch
BranchTrueFalseTotal
$self->disable_sth_caching ? : 10 17693 17703
1973 ? $dbh->prepare($sql)
1974 : $dbh->prepare_cached($sql, {}, 3);
1975  
1976 # XXX You would think RaiseError would make this impossible,
1977 # but apparently that's not true :(
1978 $self->throw_exception(
1979 $dbh->errstr
1980 ||
1981 sprintf( "\$dbh->prepare() of '%s' through %s failed *silently* without "
1982 .'an exception and/or setting $dbh->errstr',
1983 length ($sql) > 20
1984 ? substr($sql, 0, 20) . '...'
1985 : $sql
1986 ,
1987 'DBD::' . $dbh->{Driver}{Name},
1988 )
1989 17685 ▶ ) if !$sth;
Branch: 2 branches
BranchTrueFalseTotal
unless $sth 0 17685 17685
length $sql > 20 ? : 0 0 0
Condition0%0/3
$dbh->errstr || sprintf(q[$dbh->prepare() of '%s' through %s failed *silently* without an exception and/or setting $dbh->errstr], length $sql > 20 ? substr($sql, 0, 20) . '...' : $sql, 'DBD::' . $dbh->{'Driver'}{'Name'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbh->errstr || sprintf(q[$dbh->prepare() of '%s' through %s failed *silently* without an exception and/or setting $dbh->errstr], length $sql > 20 ? substr($sql, 0, 20) . '...' : $sql, 'DBD::' . $dbh->{'Driver'}{'Name'})
$dbh->errstr sprintf(q[$dbh->prepare() of '%s' through %s failed *silently* without an exception and/or setting $dbh->errstr], length $sql > 20 ? substr($sql, 0, 20) . '...' : $sql, 'DBD::' . $dbh->{'Driver'}{'Name'})
Truth table0%0/3
A || B
A= $dbh->errstrB= sprintf(q[$dbh->prepare() of '%s' through %s failed *silently* without an exception and/or setting $dbh->errstr], length $sql > 20 ? substr($sql, 0, 20) . '...' : $sql, 'DBD::' . $dbh->{'Driver'}{'Name'})
ABresult
1X1
011
000
1990  
1991 17685 $sth;
1992 }
1993  
1994 10059 ▶sub _bind_sth_params {
Subroutine _bind_sth_params: called CC=6 SCAR=19.3
1995 10059 my ($self, $sth, $bind, $bind_attrs) = @_;
1996  
1997 10059 for my $i (0 .. $#$bind) {
1998 20085 ▶ if (ref $bind->[$i][1] eq 'SCALAR') { # any scalarrefs are assumed to be bind_inouts
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bind->[$i][1] eq 'SCALAR') { } 0 20085 20085
1999 $sth->bind_param_inout(
2000 $i + 1, # bind params counts are 1-based
2001 $bind->[$i][1],
2002 0 ▶ $bind->[$i][0]{dbd_size} || $self->_max_column_bytesize($bind->[$i][0]), # size
Condition0%0/3
$bind->[$i][0]{'dbd_size'} || $self->_max_column_bytesize($bind->[$i][0])
l!l&&r!l&&!r
000
MC/DC0%0/2
$bind->[$i][0]{'dbd_size'} || $self->_max_column_bytesize($bind->[$i][0])
$bind->[$i][0]{'dbd_size'} $self->_max_column_bytesize($bind->[$i][0])
Truth table0%0/3
A || B
A= $bind->[$i][0]{'dbd_size'}B= $self->_max_column_bytesize($bind->[$i][0])
ABresult
1X1
011
000
2003 $bind_attrs->[$i],
2004 );
2005 }
2006 else {
2007 # FIXME SUBOPTIMAL - DBI needs fixing to always stringify regardless of DBD
2008 20085 ▶ my $v = ( length ref $bind->[$i][1] and is_plain_value $bind->[$i][1] )
Branch: 1 branch
BranchTrueFalseTotal
length ref $bind->[$i][1] && &is_plain_value($bind->[$i][1]) ? : 224 19861 20085
Condition100%3/3
length ref $bind->[$i][1] and &is_plain_value($bind->[$i][1])
!ll&&!rl&&r
198592224
MC/DC100%2/2
length ref $bind->[$i][1] and &is_plain_value($bind->[$i][1])
length ref $bind->[$i][1] &is_plain_value($bind->[$i][1])
Truth table100%3/3
A and B
A= length ref $bind->[$i][1]B= &is_plain_value($bind->[$i][1])
ABresult
0X0
100
111
2009 ? "$bind->[$i][1]"
2010 : $bind->[$i][1]
2011 ;
2012  
2013 20085 $sth->bind_param(
2014 $i + 1,
2015 # The temp-var is CRUCIAL - DO NOT REMOVE IT, breaks older DBD::SQLite RT#79576
2016 $v,
2017 $bind_attrs->[$i],
2018 );
2019 }
2020 }
2021  
2022 10059 $sth;
2023 }
2024  
2025 1493 ▶sub _prefetch_autovalues {
Subroutine _prefetch_autovalues: called CC=6 SCAR=25.9
2026 1493 my ($self, $source, $colinfo, $to_insert) = @_;
2027  
2028 1493 my %values;
2029 1493 for my $col (keys %$colinfo) {
2030 7600 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($colinfo->{$col}{"auto_nextval"} and !exists $to_insert->{$col} || &is_literal_value($to_insert->{$col})) 0 7600 7600
Condition16%1/6
$colinfo->{$col}{"auto_nextval"} and !exists $to_insert->{$col} || &is_literal_value($to_insert->{$col})
!ll&&!rl&&r
760000
not exists $to_insert->{$col} or &is_literal_value($to_insert->{$col})
l!l&&r!l&&!r
000
MC/DC0%0/3
$colinfo->{$col}{"auto_nextval"} and !exists $to_insert->{$col} || &is_literal_value($to_insert->{$col})
$colinfo->{$col}{"auto_nextval"} not exists $to_insert->{$col} &is_literal_value($to_insert->{$col})
Truth table25%1/4
A and not(B) or C
A= $colinfo->{$col}{"auto_nextval"}B= not exists $to_insert->{$col}C= &is_literal_value($to_insert->{$col})
ABCresult
0XX0
1000
11X1
1011
2031 $colinfo->{$col}{auto_nextval}
2032 and
2033 (
2034 ! exists $to_insert->{$col}
2035 or
2036 is_literal_value($to_insert->{$col})
2037 )
2038 ) {
2039 $values{$col} = $self->_sequence_fetch(
2040 'NEXTVAL',
2041 ( $colinfo->{$col}{sequence} ||=
2042 0 ▶ $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col)
Condition0%0/3
$colinfo->{$col}{"sequence"} ||= $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col)
l!l&&r!l&&!r
000
MC/DC0%0/2
$colinfo->{$col}{"sequence"} ||= $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col)
$colinfo->{$col}{"sequence"} $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col)
Truth table0%0/3
A ||= B
A= $colinfo->{$col}{"sequence"}B= $self->_dbh_get_autoinc_seq($self->_get_dbh, $source, $col)
ABresult
1X1
011
000
2043 ),
2044 );
2045 }
2046 }
2047  
2048 1493 \%values;
2049 }
2050  
2051 sub insert {
2052 my ($self, $source, $to_insert) = @_;
2053  
2054 my $col_infos = $source->columns_info;
2055  
2056 my $prefetched_values = $self->_prefetch_autovalues($source, $col_infos, $to_insert);
2057  
2058 # fuse the values, but keep a separate list of prefetched_values so that
2059 # they can be fused once again with the final return
2060 $to_insert = { %$to_insert, %$prefetched_values };
2061  
2062 my %pcols = map { $_ => 1 } $source->primary_columns;
2063  
2064 my (%retrieve_cols, $autoinc_supplied, $retrieve_autoinc_col);
2065  
2066 for my $col ($source->columns) {
2067  
2068 # first autoinc wins - this is why ->columns() in-order iteration is important
2069 #
2070 # FIXME - there ought to be a sanity-check for multiple is_auto_increment settings
2071 # or something...
2072 #
2073 if ($col_infos->{$col}{is_auto_increment}) {
2074  
2075 # FIXME - we seem to assume undef values as non-supplied.
2076 # This is wrong.
2077 # Investigate what does it take to s/defined/exists/
2078 # ( fails t/cdbi/copy.t amoong other things )
2079 $autoinc_supplied ||= 1 if defined $to_insert->{$col};
2080  
2081 $retrieve_autoinc_col ||= $col unless $autoinc_supplied;
2082 }
2083  
2084 # nothing to retrieve when explicit values are supplied
2085 next if (
2086 # FIXME - we seem to assume undef values as non-supplied.
2087 # This is wrong.
2088 # Investigate what does it take to s/defined/exists/
2089 # ( fails t/cdbi/copy.t amoong other things )
2090 defined $to_insert->{$col}
2091 and
2092 (
2093 # not a ref - cheaper to check before a call to is_literal_value()
2094 ! length ref $to_insert->{$col}
2095 or
2096 # not a literal we *MAY* need to pull out ( see check below )
2097 ! is_literal_value( $to_insert->{$col} )
2098 )
2099 );
2100  
2101 # the 'scalar keys' is a trick to preserve the ->columns declaration order
2102 $retrieve_cols{$col} = scalar keys %retrieve_cols if (
2103 $pcols{$col}
2104 or
2105 $col_infos->{$col}{retrieve_on_insert}
2106 );
2107 };
2108  
2109 # corner case of a non-supplied PK which is *not* declared as autoinc
2110 if (
2111 ! $autoinc_supplied
2112 and
2113 ! defined $retrieve_autoinc_col
2114 and
2115 # FIXME - first come-first serve, suboptimal...
2116 ($retrieve_autoinc_col) = ( grep
2117 {
2118 $pcols{$_}
2119 and
2120 ! $col_infos->{$_}{retrieve_on_insert}
2121 and
2122 ! defined $col_infos->{$_}{is_auto_increment}
2123 }
2124 sort
2125 { $retrieve_cols{$a} <=> $retrieve_cols{$b} }
2126 keys %retrieve_cols
2127 )
2128 ) {
2129 carp_unique(
2130 "Missing value for primary key column '$retrieve_autoinc_col' on "
2131 . "@{[ $source->source_name ]} - perhaps you forgot to set its "
2132 . "'is_auto_increment' attribute during add_columns()? Treating "
2133 . "'$retrieve_autoinc_col' implicitly as an autoinc, and attempting "
2134 . 'value retrieval'
2135 );
2136 }
2137  
2138 local $self->{_autoinc_supplied_for_op} = $autoinc_supplied;
2139 local $self->{_perform_autoinc_retrieval} = $retrieve_autoinc_col;
2140  
2141 my ($sqla_opts, @ir_container);
2142 if (%retrieve_cols and $self->_use_insert_returning) {
2143 $sqla_opts->{returning_container} = \@ir_container
2144 if $self->_use_insert_returning_bound;
2145  
2146 $sqla_opts->{returning} = [
2147 sort { $retrieve_cols{$a} <=> $retrieve_cols{$b} } keys %retrieve_cols
2148 ];
2149 }
2150  
2151 my ($rv, $sth) = $self->_execute('insert', $source, $to_insert, $sqla_opts);
2152  
2153 my %returned_cols = %$to_insert;
2154 if (my $retlist = $sqla_opts->{returning}) { # if IR is supported - we will get everything in one set
2155  
2156 unless( @ir_container ) {
2157 try {
2158  
2159 # FIXME - need to investigate why Caelum silenced this in 4d4dc518
2160 local $SIG{__WARN__} = sub {};
2161  
2162 @ir_container = $sth->fetchrow_array;
2163 $sth->finish;
2164  
2165 } catch {
2166 # Evict the $sth from the cache in case we got here, since the finish()
2167 # is crucial, at least on older Firebirds, possibly on other engines too
2168 #
2169 # It would be too complex to make this a proper subclass override,
2170 # and besides we already take the try{} penalty, adding a catch that
2171 # triggers infrequently is a no-brainer
2172 #
2173 if( my $kids = $self->_dbh->{CachedKids} ) {
2174 $kids->{$_} == $sth and delete $kids->{$_}
2175 for keys %$kids
2176 }
2177 };
2178 }
2179  
2180 @returned_cols{@$retlist} = @ir_container if @ir_container;
2181 }
2182 else {
2183 # pull in PK if needed and then everything else
2184 if (my @missing_pri = grep { $pcols{$_} } keys %retrieve_cols) {
2185  
2186 $self->throw_exception( "Missing primary key but Storage doesn't support last_insert_id" )
2187 unless $self->can('last_insert_id');
2188  
2189 my @pri_values = $self->last_insert_id($source, @missing_pri);
2190  
2191 $self->throw_exception( "Can't get last insert id" )
2192 unless (@pri_values == @missing_pri);
2193  
2194 @returned_cols{@missing_pri} = @pri_values;
2195 delete @retrieve_cols{@missing_pri};
2196 }
2197  
2198 # if there is more left to pull
2199 if (%retrieve_cols) {
2200 $self->throw_exception(
2201 'Unable to retrieve additional columns without a Primary Key on ' . $source->source_name
2202 ) unless %pcols;
2203  
2204 my @left_to_fetch = sort { $retrieve_cols{$a} <=> $retrieve_cols{$b} } keys %retrieve_cols;
2205  
2206 my $cur = DBIx::Class::ResultSet->new($source, {
2207 where => { map { $_ => $returned_cols{$_} } (keys %pcols) },
2208 select => \@left_to_fetch,
2209 })->cursor;
2210  
2211 @returned_cols{@left_to_fetch} = $cur->next;
2212  
2213 $self->throw_exception('Duplicate row returned for PK-search after fresh insert')
2214 if scalar $cur->next;
2215 }
2216 }
2217  
2218 return { %$prefetched_values, %returned_cols };
2219 }
2220  
2221 1493 ▶sub insert_bulk {
Subroutine insert_bulk: called CC=3 SCAR=11.0
Pod undocumented
2222 1493 carp_unique(
2223 'insert_bulk() should have never been exposed as a public method and '
2224 . 'calling it is depecated as of Aug 2014. If you believe having a genuine '
2225 . 'use for this method please contact the development team via '
2226 . DBIx::Class::_ENV_::HELP_URL
2227 );
2228  
2229 1493 ▶ return '0E0' unless @{$_[3]||[]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$_[3] or [];} 1301 6299 7600
Condition50%1/2
$_[3] || []
l!l
075
MC/DC0%0/1
$_[3] || []
$_[3]
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
2230  
2231 1493 shift->_insert_bulk(@_);
2232 }
2233  
2234 0 ▶sub _insert_bulk {
Subroutine _insert_bulk: not called CC=27 SCAR=54.9
2235 8 my ($self, $source, $cols, $data) = @_;
2236  
2237 $self->throw_exception('Calling _insert_bulk without a dataset to process makes no sense')
2238 ▶ unless @{$data||[]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$data or [];} 0 0 0
2239  
2240 my $colinfos = $source->columns_info($cols);
2241  
2242 local $self->{_autoinc_supplied_for_op} =
2243 (grep { $_->{is_auto_increment} } values %$colinfos)
2244 ? 1
2245 : 0
2246 ;
2247  
2248 # get a slice type index based on first row of data
2249 # a "column" in this context may refer to more than one bind value
2250 # e.g. \[ '?, ?', [...], [...] ]
2251 #
2252 # construct the value type index - a description of values types for every
2253 # per-column slice of $data:
2254 #
2255 # nonexistent - nonbind literal
2256 # 0 - regular value
2257 # [] of bindattrs - resolved attribute(s) of bind(s) passed via literal+bind \[] combo
2258 #
2259 # also construct the column hash to pass to the SQL generator. For plain
2260 # (non literal) values - convert the members of the first row into a
2261 # literal+bind combo, with extra positional info in the bind attr hashref.
2262 # This will allow us to match the order properly, and is so contrived
2263 # because a user-supplied literal/bind (or something else specific to a
2264 # resultsource and/or storage driver) can inject extra binds along the
2265 # way, so one can't rely on "shift positions" ordering at all. Also we
2266 # can't just hand SQLMaker a set of some known "values" (e.g. hashrefs that
2267 # can be later matched up by address), because we want to supply a real
2268 # value on which perhaps e.g. datatype checks will be performed
2269 my ($proto_data, $serialized_bind_type_by_col_idx);
2270 for my $col_idx (0..$#$cols) {
2271 my $colname = $cols->[$col_idx];
2272 if (ref $data->[0][$col_idx] eq 'SCALAR') {
2273 # no bind value at all - no type
2274  
2275 $proto_data->{$colname} = $data->[0][$col_idx];
2276 }
2277 elsif (ref $data->[0][$col_idx] eq 'REF' and ref ${$data->[0][$col_idx]} eq 'ARRAY' ) {
2278 # repack, so we don't end up mangling the original \[]
2279 my ($sql, @bind) = @${$data->[0][$col_idx]};
2280  
2281 # normalization of user supplied stuff
2282 my $resolved_bind = $self->_resolve_bindattrs(
2283 $source, \@bind, $colinfos,
2284 );
2285  
2286 # store value-less (attrs only) bind info - we will be comparing all
2287 # supplied binds against this for sanity
2288 $serialized_bind_type_by_col_idx->{$col_idx} = serialize [ map { $_->[0] } @$resolved_bind ];
2289  
2290 $proto_data->{$colname} = \[ $sql, map { [
2291 # inject slice order to use for $proto_bind construction
2292 { %{$resolved_bind->[$_][0]}, _bind_data_slice_idx => $col_idx, _literal_bind_subindex => $_+1 }
2293 =>
2294 $resolved_bind->[$_][1]
2295 ] } (0 .. $#bind)
2296 ];
2297 }
2298 else {
2299 $serialized_bind_type_by_col_idx->{$col_idx} = undef;
2300  
2301 $proto_data->{$colname} = \[ '?', [
2302 { dbic_colname => $colname, _bind_data_slice_idx => $col_idx }
2303 =>
2304 $data->[0][$col_idx]
2305 ] ];
2306 }
2307 }
2308  
2309 my ($sql, $proto_bind) = $self->_prep_for_execute (
2310 'insert',
2311 $source,
2312 [ $proto_data ],
2313 );
2314  
2315 if (! @$proto_bind and keys %$serialized_bind_type_by_col_idx) {
2316 # if the bindlist is empty and we had some dynamic binds, this means the
2317 # storage ate them away (e.g. the NoBindVars component) and interpolated
2318 # them directly into the SQL. This obviously can't be good for multi-inserts
2319 $self->throw_exception('Unable to invoke fast-path insert without storage placeholder support');
2320 }
2321  
2322 # sanity checks
2323 # FIXME - devise a flag "no babysitting" or somesuch to shut this off
2324 #
2325 # use an error reporting closure for convenience (less to pass)
2326 8 ▶ my $bad_slice_report_cref = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2327 my ($msg, $r_idx, $c_idx) = @_;
2328 $self->throw_exception(sprintf "%s for column '%s' in populate slice:\n%s",
2329 $msg,
2330 $cols->[$c_idx],
2331 do {
2332 require Data::Dumper::Concise;
2333 local $Data::Dumper::Maxdepth = 5;
2334 Data::Dumper::Concise::Dumper ({
2335 map { $cols->[$_] =>
2336 $data->[$r_idx][$_]
2337 } 0..$#$cols
2338 }),
2339 }
2340 );
2341 };
2342  
2343 for my $col_idx (0..$#$cols) {
2344 my $reference_val = $data->[0][$col_idx];
2345  
2346 for my $row_idx (1..$#$data) { # we are comparing against what we got from [0] above, hence start from 1
2347 my $val = $data->[$row_idx][$col_idx];
2348  
2349 if (! exists $serialized_bind_type_by_col_idx->{$col_idx}) { # literal no binds
2350 if (ref $val ne 'SCALAR') {
2351 $bad_slice_report_cref->(
2352 "Incorrect value (expecting SCALAR-ref \\'$$reference_val')",
2353 $row_idx,
2354 $col_idx,
2355 );
2356 }
2357 elsif ($$val ne $$reference_val) {
2358 $bad_slice_report_cref->(
2359 "Inconsistent literal SQL value (expecting \\'$$reference_val')",
2360 $row_idx,
2361 $col_idx,
2362 );
2363 }
2364 }
2365 elsif (! defined $serialized_bind_type_by_col_idx->{$col_idx} ) { # regular non-literal value
2366 if (is_literal_value($val)) {
2367 $bad_slice_report_cref->("Literal SQL found where a plain bind value is expected", $row_idx, $col_idx);
2368 }
2369 }
2370 else { # binds from a \[], compare type and attrs
2371 if (ref $val ne 'REF' or ref $$val ne 'ARRAY') {
2372 $bad_slice_report_cref->(
2373 "Incorrect value (expecting ARRAYREF-ref \\['${$reference_val}->[0]', ... ])",
2374 $row_idx,
2375 $col_idx,
2376 );
2377 }
2378 # start drilling down and bail out early on identical refs
2379 elsif (
2380 $reference_val != $val
2381 or
2382 $$reference_val != $$val
2383 ) {
2384 if (${$val}->[0] ne ${$reference_val}->[0]) {
2385 $bad_slice_report_cref->(
2386 "Inconsistent literal/bind SQL (expecting \\['${$reference_val}->[0]', ... ])",
2387 $row_idx,
2388 $col_idx,
2389 );
2390 }
2391 # need to check the bind attrs - a bind will happen only once for
2392 # the entire dataset, so any changes further down will be ignored.
2393 elsif (
2394 $serialized_bind_type_by_col_idx->{$col_idx}
2395 ne
2396 serialize [
2397 map
2398 { $_->[0] }
2399 @{$self->_resolve_bindattrs(
2400 $source, [ @{$$val}[1 .. $#$$val] ], $colinfos,
2401 )}
2402 ]
2403 ) {
2404 $bad_slice_report_cref->(
2405 'Differing bind attributes on literal/bind values not supported',
2406 $row_idx,
2407 $col_idx,
2408 );
2409 }
2410 }
2411 }
2412 }
2413 }
2414  
2415 # neither _dbh_execute_for_fetch, nor _dbh_execute_inserts_with_no_binds
2416 # are atomic (even if execute_for_fetch is a single call). Thus a safety
2417 # scope guard
2418 my $guard = $self->txn_scope_guard;
2419  
2420 $self->_query_start( $sql, @$proto_bind ? [[undef => '__BULK_INSERT__' ]] : () );
2421 my $sth = $self->_prepare_sth($self->_dbh, $sql);
2422 my $rv = do {
2423 if (@$proto_bind) {
2424 # proto bind contains the information on which pieces of $data to pull
2425 # $cols is passed in only for prettier error-reporting
2426 $self->_dbh_execute_for_fetch( $source, $sth, $proto_bind, $cols, $data );
2427 }
2428 else {
2429 # bind_param_array doesn't work if there are no binds
2430 $self->_dbh_execute_inserts_with_no_binds( $sth, scalar @$data );
2431 }
2432 };
2433  
2434 $self->_query_end( $sql, @$proto_bind ? [[ undef => '__BULK_INSERT__' ]] : () );
2435  
2436 $guard->commit;
2437  
2438 return wantarray ? ($rv, $sth, @$proto_bind) : $rv;
2439 }
2440  
2441 # execute_for_fetch is capable of returning data just fine (it means it
2442 # can be used for INSERT...RETURNING and UPDATE...RETURNING. Since this
2443 # is the void-populate fast-path we will just ignore this altogether
2444 # for the time being.
2445 15249 ▶sub _dbh_execute_for_fetch {
Subroutine _dbh_execute_for_fetch: called CC=12 SCAR=24.8
2446 16742 my ($self, $source, $sth, $proto_bind, $cols, $data) = @_;
2447  
2448 # If we have any bind attributes to take care of, we will bind the
2449 # proto-bind data (which will never be used by execute_for_fetch)
2450 # However since column bindtypes are "sticky", this is sufficient
2451 # to get the DBD to apply the bindtype to all values later on
2452 16911 my $bind_attrs = $self->_dbi_attrs_for_bind($source, $proto_bind);
2453  
2454 16742 for my $i (0 .. $#$proto_bind) {
2455 30966 ▶ $sth->bind_param (
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_attrs->[$i] 13947 16827 30774
2456 $i+1, # DBI bind indexes are 1-based
2457 $proto_bind->[$i][1],
2458 $bind_attrs->[$i],
2459 ) if defined $bind_attrs->[$i];
2460 }
2461  
2462 # At this point $data slots named in the _bind_data_slice_idx of
2463 # each piece of $proto_bind are either \[]s or plain values to be
2464 # passed in. Construct the dispensing coderef. *NOTE* the order
2465 # of $data will differ from this of the ?s in the SQL (due to
2466 # alphabetical ordering by colname). We actually do want to
2467 # preserve this behavior so that prepare_cached has a better
2468 # chance of matching on unrelated calls
2469  
2470 22849 my $fetch_row_idx = -1; # saner loop this way
2471 44410 ▶ my $fetch_tuple = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
2472 44429 ▶ return undef if ++$fetch_row_idx > $#$data;
Branch: 1 branch
BranchTrueFalseTotal
if ++$fetch_row_idx > $data->$#* 7639 119331 126970
2473  
2474 return [ map {
2475 my $v = ! defined $_->{_literal_bind_subindex}
2476  
2477 ? $data->[ $fetch_row_idx ]->[ $_->{_bind_data_slice_idx} ]
2478  
2479 # There are no attributes to resolve here - we already did everything
2480 # when we constructed proto_bind. However we still want to sanity-check
2481 # what the user supplied, so pass stuff through to the resolver *anyway*
2482 : $self->_resolve_bindattrs (
2483 undef, # a fake rsrc
2484 126221 ▶ [ ${ $data->[ $fetch_row_idx ]->[ $_->{_bind_data_slice_idx} ]}->[ $_->{_literal_bind_subindex} ] ],
Branch: 1 branch
BranchTrueFalseTotal
!defined($_->{'_literal_bind_subindex'}) ? : 183875 80 183955
2485 {}, # a fake column_info bag
2486 )->[0][1]
2487 ;
2488  
2489 # FIXME SUBOPTIMAL - DBI needs fixing to always stringify regardless of DBD
2490 # For the time being forcibly stringify whatever is stringifiable
2491 112018 ▶ (length ref $v and is_plain_value $v)
Branch: 1 branch
BranchTrueFalseTotal
length ref $v && &is_plain_value($v) ? : 51 104357 104408
Condition100%3/3
length ref $v and &is_plain_value($v)
!ll&&!rl&&r
1029261226242
MC/DC50%1/2
length ref $v and &is_plain_value($v)
length ref $v &is_plain_value($v)
Truth table66%2/3
A and B
A= length ref $vB= &is_plain_value($v)
ABresult
0X0
100
111
2492 ? "$v"
2493 : $v
2494 ;
2495 58611 } map { $_->[0] } @$proto_bind ];
2496 30780 };
2497  
2498 16550 my $tuple_status = [];
2499 22849 my ($rv, $err);
2500 7621 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
2501 15249 $rv = $sth->execute_for_fetch(
2502 $fetch_tuple,
2503 $tuple_status,
2504 );
2505 }
2506 2 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
2507 7630 $err = shift;
2508 33151 };
2509  
2510 # Not all DBDs are create equal. Some throw on error, some return
2511 # an undef $rv, and some set $sth->err - try whatever we can
2512 30972 ▶ $err = ($sth->errstr || 'UNKNOWN ERROR ($sth->errstr is unset)') if (
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and !defined($rv) || $sth->err 6185 10365 16550
Condition88%8/9
not defined $err and !defined($rv) || $sth->err
!ll&&!rl&&r
763088450
not defined $rv or $sth->err
l!l&&r!l&&!r
254881111566
$sth->errstr || 'UNKNOWN ERROR ($sth->errstr is unset)'
l!l
1142812811
MC/DC0%0/3
not defined $err and !defined($rv) || $sth->err
not defined $err not defined $rv $sth->err
MC/DC100%1/1
$sth->errstr || 'UNKNOWN ERROR ($sth->errstr is unset)'
$sth->errstr
Truth table0%0/4
not(A) and not(B) or C
A= not defined $errB= not defined $rvC= $sth->err
ABCresult
0XX0
1000
11X1
1011
Truth table100%2/2
A
A= $sth->errstr
Aresult
11
00
2513 ! defined $err
2514 and
2515 ( !defined $rv or $sth->err )
2516 );
2517  
2518 # Statement must finish even if there was an exception.
2519 7621 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
2520 30966 $sth->finish
2521 }
2522 0 ▶ catch {
Subroutine __ANON__: not called CC=2 SCAR=6.9
2523 23083 ▶ $err = shift unless defined $err
Branch: 1 branch
BranchTrueFalseTotal
unless defined $err 1 16 17
2524 7636 };
2525  
2526 7640 ▶ if (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 3942 33137 37079
2527 22 my $i = 0;
2528 22 ▶ ++$i while $i <= $#$tuple_status && !ref $tuple_status->[$i];
Branch: 1 branch
BranchTrueFalseTotal
$i <= $tuple_status->$#* and not ref $tuple_status->[$i] and do { ++$i } 1252 24271 25523
Condition100%3/3
$i <= $tuple_status->$#* and not ref $tuple_status->[$i]
!ll&&!rl&&r
123032470
MC/DC50%1/2
$i <= $tuple_status->$#* and not ref $tuple_status->[$i]
$i <= $tuple_status->$#* not ref $tuple_status->[$i]
Truth table66%2/3
A and not(B)
A= $i <= $tuple_status->$#*B= not ref $tuple_status->[$i]
ABresult
0X0
100
111
2529  
2530 1514 ▶ $self->throw_exception("Unexpected populate error: $err")
Branch: 1 branch
BranchTrueFalseTotal
if $i > $tuple_status->$#* 1 9122 9123
2531 if ($i > $#$tuple_status);
2532  
2533 1514 require Data::Dumper::Concise;
2534 $self->throw_exception(sprintf "execute_for_fetch() aborted with '%s' at populate slice:\n%s",
2535 ($tuple_status->[$i][1] || $err),
2536 1519 ▶ Data::Dumper::Concise::Dumper( { map { $cols->[$_] => $data->[$i][$_] } (0 .. $#$cols) } ),
Condition100%3/3
$tuple_status->[$i][1] || $err
l!l&&r!l&&!r
130919120
MC/DC100%2/2
$tuple_status->[$i][1] || $err
$tuple_status->[$i][1] $err
Truth table100%3/3
A || B
A= $tuple_status->[$i][1]B= $err
ABresult
1X1
011
000
2537 );
2538 }
2539  
2540 7643 return $rv;
2541 }
2542  
2543 2 ▶sub _dbh_execute_inserts_with_no_binds {
Subroutine _dbh_execute_inserts_with_no_binds: called CC=2 SCAR=6.9
2544 82300 my ($self, $sth, $count) = @_;
2545  
2546 82300 my $err;
2547 2 ▶ try {
Subroutine __ANON__: called CC=2 SCAR=6.9
2548 4 my $dbh = $self->_get_dbh;
2549 29 local $dbh->{RaiseError} = 1;
2550 3 local $dbh->{PrintError} = 0;
2551  
2552 4 $sth->execute foreach 1..$count;
2553 }
2554 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=0.0
2555 7 $err = shift;
2556 1246 };
2557  
2558 # Make sure statement is finished even if there was an exception.
2559 2 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
2560 9 $sth->finish
2561 }
2562 0 ▶ catch {
Subroutine __ANON__: not called CC=2 SCAR=6.9
2563 7 ▶ $err = shift unless defined $err;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $err 1227 288 1515
2564 1229 };
2565  
2566 1229 ▶ $self->throw_exception($err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 1 81029 81030
2567  
2568 82519 return $count;
2569 }
2570  
2571 sub update {
2572 #my ($self, $source, @args) = @_;
2573 shift->_execute('update', @_);
2574 }
2575  
2576  
2577 sub delete {
2578 #my ($self, $source, @args) = @_;
2579 shift->_execute('delete', @_);
2580 }
2581  
2582 7319 ▶sub _select {
Subroutine _select: called CC=1 SCAR=0.0
2583 8808 my $self = shift;
2584 7099 $self->_execute($self->_select_args(@_));
2585 }
2586  
2587 760 ▶sub _select_args_to_query {
Subroutine _select_args_to_query: called CC=4 SCAR=14.0
2588 770 my $self = shift;
2589  
2590 $self->throw_exception(
2591 "Unable to generate limited query representation with 'software_limit' enabled"
2592 766 ▶ ) if ($_[3]->{software_limit} and ($_[3]->{offset} or $_[3]->{rows}) );
Branch: 1 branch
BranchTrueFalseTotal
if $_[3]{"software_limit"} and $_[3]{"offset"} || $_[3]{"rows"} 7 2004 2011
Condition66%4/6
$_[3]{"software_limit"} and $_[3]{"offset"} || $_[3]{"rows"}
!ll&&!rl&&r
76102
$_[3]{"offset"} or $_[3]{"rows"}
l!l&&r!l&&!r
031
MC/DC33%1/3
$_[3]{"software_limit"} and $_[3]{"offset"} || $_[3]{"rows"}
$_[3]{"software_limit"} $_[3]{"offset"} $_[3]{"rows"}
Truth table50%2/4
A and B or C
A= $_[3]{"software_limit"}B= $_[3]{"offset"}C= $_[3]{"rows"}
ABCresult
0XX0
1000
11X1
1011
2593  
2594 # my ($op, $ident, $select, $cond, $rs_attrs, $rows, $offset)
2595 # = $self->_select_args($ident, $select, $cond, $attrs);
2596 765 my ($op, $ident, @args) =
2597 $self->_select_args(@_);
2598  
2599 # my ($sql, $prepared_bind) = $self->_gen_sql_bind($op, $ident, [ $select, $cond, $rs_attrs, $rows, $offset ]);
2600 760 my ($sql, $bind) = $self->_gen_sql_bind($op, $ident, \@args);
2601  
2602 # reuse the bind arrayref
2603 8379 unshift @{$bind}, "($sql)";
2604 8379 \$bind;
2605 }
2606  
2607 7858 ▶sub _select_args {
Subroutine _select_args: called CC=26 SCAR=32.8
2608 15481 my ($self, $ident, $select, $where, $orig_attrs) = @_;
2609  
2610 # FIXME - that kind of caching would be nice to have
2611 # however currently we *may* pass the same $orig_attrs
2612 # with different ident/select/where
2613 # the whole interface needs to be rethought, since it
2614 # was centered around the flawed SQLMaker API. We can do
2615 # soooooo much better now. But that is also another
2616 # battle...
2617 #return (
2618 # 'select', $orig_attrs->{!args_as_stored_at_the_end_of_this_method!}
2619 #) if $orig_attrs->{!args_as_stored_at_the_end_of_this_method!};
2620  
2621 15481 my $sql_maker = $self->sql_maker;
2622  
2623 15479 my $attrs = {
2624 %$orig_attrs,
2625 select => $select,
2626 from => $ident,
2627 where => $where,
2628 };
2629  
2630 # Sanity check the attributes (SQLMaker does it too, but
2631 # in case of a software_limit we'll never reach there)
2632 7860 ▶ if (defined $attrs->{offset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{"offset"}) 207 8883 9090
2633 $self->throw_exception('A supplied offset attribute must be a non-negative integer')
2634 7828 ▶ if ( $attrs->{offset} =~ /\D/ or $attrs->{offset} < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"offset"} =~ /\D/ or $attrs->{"offset"} < 0 2 1700 1702
Condition100%3/3
$attrs->{"offset"} =~ /\D/ or $attrs->{"offset"} < 0
l!l&&r!l&&!r
2641229207
MC/DC0%0/2
$attrs->{"offset"} =~ /\D/ or $attrs->{"offset"} < 0
$attrs->{"offset"} =~ /\D/ $attrs->{"offset"} < 0
Truth table33%1/3
A or B
A= $attrs->{"offset"} =~ /\D/B= $attrs->{"offset"} < 0
ABresult
1X1
011
000
2635 }
2636  
2637 15479 ▶ if (defined $attrs->{rows}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $attrs->{'rows'}) { } 9361 6121 15482
elsif ($attrs->{'offset'}) { } 7633 6109 13742
2638 $self->throw_exception("The rows attribute must be a positive integer if present")
2639 9361 ▶ if ( $attrs->{rows} =~ /\D/ or $attrs->{rows} <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"rows"} =~ /\D/ or $attrs->{"rows"} <= 0 7619 1742 9361
Condition33%1/3
$attrs->{"rows"} =~ /\D/ or $attrs->{"rows"} <= 0
l!l&&r!l&&!r
001740
MC/DC0%0/2
$attrs->{"rows"} =~ /\D/ or $attrs->{"rows"} <= 0
$attrs->{"rows"} =~ /\D/ $attrs->{"rows"} <= 0
Truth table33%1/3
A or B
A= $attrs->{"rows"} =~ /\D/B= $attrs->{"rows"} <= 0
ABresult
1X1
011
000
2640 }
2641 elsif ($attrs->{offset}) {
2642 # MySQL actually recommends this approach. I cringe.
2643 17 $attrs->{rows} = $sql_maker->__max_int;
2644 }
2645  
2646 # see if we will need to tear the prefetch apart to satisfy group_by == select
2647 # this is *extremely tricky* to get right, I am still not sure I did
2648 #
2649 7863 my ($prefetch_needs_subquery, @limit_args);
2650  
2651 7863 ▶ if ( $attrs->{_grouped_by_distinct} and $attrs->{collapse} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($attrs->{'_grouped_by_distinct'} and $attrs->{'collapse'}) { } 11 15468 15479
elsif ($prefetch_needs_subquery || !$attrs->{'_simple_passthrough_construction'} and $attrs->{'group_by'} and @{$attrs->{'group_by'};} and my $grp_aliases = &try(sub { $self->_resolve_aliastypes_from_select_args({'from', $attrs->{'from'}, 'group_by', $attrs->{'group_by'}}); } )) { } 47 7800 7847
elsif ($attrs->{'rows'} and $attrs->{'collapse'}) { } 61 13833 13894
Condition100%3/3
$attrs->{"_grouped_by_distinct"} and $attrs->{"collapse"}
!ll&&!rl&&r
77678011
MC/DC100%2/2
$attrs->{"_grouped_by_distinct"} and $attrs->{"collapse"}
$attrs->{"_grouped_by_distinct"} $attrs->{"collapse"}
Truth table100%3/3
A and B
A= $attrs->{"_grouped_by_distinct"}B= $attrs->{"collapse"}
ABresult
0X0
100
111
2652 # we already know there is a valid group_by (we made it) and we know it is
2653 # intended to be based *only* on non-multi stuff
2654 # short circuit the group_by parsing below
2655 16 $prefetch_needs_subquery = 1;
2656 }
2657 ▶ elsif (
Condition75%9/12
$prefetch_needs_subquery || !$attrs->{"_simple_passthrough_construction"} and $attrs->{"group_by"} and @{$attrs->{"group_by"};} and my $grp_aliases = &try(sub { $self->_resolve_aliastypes_from_select_args({"from", $attrs->{"from"}, "group_by", $attrs->{"group_by"}}); } )
!ll&&!rl&&r
7800047
$prefetch_needs_subquery || !$attrs->{"_simple_passthrough_construction"} and $attrs->{"group_by"} and @{$attrs->{"group_by"};}
!ll&&!rl&&r
7800047
$prefetch_needs_subquery || !$attrs->{"_simple_passthrough_construction"} and $attrs->{"group_by"}
!ll&&!rl&&r
744835247
$prefetch_needs_subquery or not $attrs->{"_simple_passthrough_construction"}
l!l&&r!l&&!r
03997448
MC/DC40%2/5
$prefetch_needs_subquery || !$attrs->{"_simple_passthrough_construction"} and $attrs->{"group_by"} and @{$attrs->{"group_by"};} and my $grp_aliases = &try(sub { $self->_resolve_aliastypes_from_select_args({"from", $attrs->{"from"}, "group_by", $attrs->{"group_by"}}); } )
$prefetch_needs_subquery not $attrs->{"_simple_passthrough_construction"} $attrs->{"group_by"} @{$attrs->{"group_by"};} my $grp_aliases = &try(sub { $self->_resolve_aliastypes_from_select_args({"from", $attrs->{"from"}, "group_by", $attrs->{"group_by"}}); } )
Truth table33%3/9
A or not(B) and C and D and E
A= $prefetch_needs_subqueryB= not $attrs->{"_simple_passthrough_construction"}C= $attrs->{"group_by"}D= @{$attrs->{"group_by"};}E= my $grp_aliases = &try(sub { $self->_resolve_aliastypes_from_select_args({"from", $attrs->{"from"}, "group_by", $attrs->{"group_by"}}); } )
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
2658 # The rationale is that even if we do *not* have collapse, we still
2659 # need to wrap the core grouped select/group_by in a subquery
2660 # so that databases that care about group_by/select equivalence
2661 # are happy (this includes MySQL in strict_mode)
2662 # If any of the other joined tables are referenced in the group_by
2663 # however - the user is on their own
2664 ( $prefetch_needs_subquery or ! $attrs->{_simple_passthrough_construction} )
2665 and
2666 $attrs->{group_by}
2667 and
2668 52 @{$attrs->{group_by}}
2669 and
2670 47 ▶ my $grp_aliases = try { # try{} because $attrs->{from} may be unreadable
Subroutine __ANON__: called CC=1 SCAR=0.0
2671 $self->_resolve_aliastypes_from_select_args({ from => $attrs->{from}, group_by => $attrs->{group_by} })
2672 47 }
2673 ) {
2674 # no aliases other than our own in group_by
2675 # if there are - do not allow subquery even if limit is present
2676 57 ▶ $prefetch_needs_subquery = ! scalar grep { $_ ne $attrs->{alias} } keys %{ $grp_aliases->{grouping} || {} };
Condition50%1/2
$grp_aliases->{'grouping'} || {}
l!l
470
MC/DC0%0/1
$grp_aliases->{'grouping'} || {}
$grp_aliases->{'grouping'}
Truth table50%1/2
A
A= $grp_aliases->{'grouping'}
Aresult
11
00
2677 }
2678 ▶ elsif ( $attrs->{rows} && $attrs->{collapse} ) {
Condition100%3/3
$attrs->{"rows"} and $attrs->{"collapse"}
!ll&&!rl&&r
6094164561
MC/DC100%2/2
$attrs->{"rows"} and $attrs->{"collapse"}
$attrs->{"rows"} $attrs->{"collapse"}
Truth table100%3/3
A and B
A= $attrs->{"rows"}B= $attrs->{"collapse"}
ABresult
0X0
100
111
2679 # active collapse with a limit - that one is a no-brainer unless
2680 # overruled by a group_by above
2681 61 $prefetch_needs_subquery = 1;
2682 }
2683  
2684 7858 ▶ if ($prefetch_needs_subquery) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prefetch_needs_subquery) { } 87 7771 7858
elsif (not $attrs->{'software_limit'}) { } 7765 6 7771
2685 87 $attrs = $self->_adjust_select_args_for_complex_prefetch ($attrs);
2686 }
2687 elsif (! $attrs->{software_limit} ) {
2688 push @limit_args, (
2689 $attrs->{rows} || (),
2690 7765 ▶ $attrs->{offset} || (),
Condition83%5/6
$attrs->{'rows'} || ()
l!l&&r!l&&!r
167306092
$attrs->{'offset'} || ()
l!l&&r!l&&!r
13315406092
MC/DC50%1/2
$attrs->{'rows'} || ()
$attrs->{'rows'} ()
MC/DC100%2/2
$attrs->{'offset'} || ()
$attrs->{'offset'} ()
Truth table66%2/3
A || B
A= $attrs->{'rows'}B= ()
ABresult
1X1
011
000
Truth table100%3/3
A || B
A= $attrs->{'offset'}B= ()
ABresult
1X1
011
000
2691 );
2692 }
2693  
2694 # try to simplify the joinmap further (prune unreferenced type-single joins)
2695 7857 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $prefetch_needs_subquery and ref $attrs->{"from"} and builtin::reftype($attrs->{"from"}) eq "ARRAY" and @{$attrs->{"from"};} != 1) 846 7011 7857
Condition88%8/9
not $prefetch_needs_subquery and ref $attrs->{"from"} and builtin::reftype($attrs->{"from"}) eq "ARRAY" and @{$attrs->{"from"};} != 1
!ll&&!rl&&r
896922846
not $prefetch_needs_subquery and ref $attrs->{"from"} and builtin::reftype($attrs->{"from"}) eq "ARRAY"
!ll&&!rl&&r
8637768
not $prefetch_needs_subquery and ref $attrs->{"from"}
!ll&&!rl&&r
8607771
MC/DC75%3/4
not $prefetch_needs_subquery and ref $attrs->{"from"} and builtin::reftype($attrs->{"from"}) eq "ARRAY" and @{$attrs->{"from"};} != 1
not $prefetch_needs_subquery ref $attrs->{"from"} builtin::reftype($attrs->{"from"}) eq "ARRAY" @{$attrs->{"from"};} != 1
Truth table80%4/5
not(A) and B and C and D
A= not $prefetch_needs_subqueryB= ref $attrs->{"from"}C= builtin::reftype($attrs->{"from"}) eq "ARRAY"D= @{$attrs->{"from"};} != 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2696 ! $prefetch_needs_subquery # already pruned
2697 and
2698 ref $attrs->{from}
2699 and
2700 reftype $attrs->{from} eq 'ARRAY'
2701 and
2702 7768 @{$attrs->{from}} != 1
2703 ) {
2704 846 ($attrs->{from}, $attrs->{_aliastypes}) = $self->_prune_unused_joins ($attrs);
2705 }
2706  
2707 # FIXME this is a gross, inefficient, largely incorrect and fragile hack
2708 # during the result inflation stage we *need* to know what was the aliastype
2709 # map as sqla saw it when the final pieces of SQL were being assembled
2710 # Originally we simply carried around the entirety of $attrs, but this
2711 # resulted in resultsets that are being reused growing continuously, as
2712 # the hash in question grew deeper and deeper.
2713 # Instead hand-pick what to take with us here (we actually don't need much
2714 # at this point just the map itself)
2715 7857 $orig_attrs->{_last_sqlmaker_alias_map} = $attrs->{_aliastypes};
2716  
2717 ###
2718 # my $alias2source = $self->_resolve_ident_sources ($ident);
2719 #
2720 # This would be the point to deflate anything found in $attrs->{where}
2721 # (and leave $attrs->{bind} intact). Problem is - inflators historically
2722 # expect a result object. And all we have is a resultsource (it is trivial
2723 # to extract deflator coderefs via $alias2source above).
2724 #
2725 # I don't see a way forward other than changing the way deflators are
2726 # invoked, and that's just bad...
2727 ###
2728  
2729 7857 return ( 'select', @{$attrs}{qw(from select where)}, $attrs, @limit_args );
2730 }
2731  
2732 # Returns a counting SELECT for a simple count
2733 # query. Abstracted so that a storage could override
2734 # this to { count => 'firstcol' } or whatever makes
2735 # sense as a performance optimization
2736 608 ▶sub _count_select {
Subroutine _count_select: called CC=1 SCAR=0.0
2737 #my ($self, $source, $rs_attrs) = @_;
2738 608 return { count => '*' };
2739 }
2740  
2741 =head2 select
2742  
2743 =over 4
2744  
2745 =item Arguments: $ident, $select, $condition, $attrs
2746  
2747 =back
2748  
2749 Handle a SQL select statement.
2750  
2751 =cut
2752  
2753 sub select {
2754 my $self = shift;
2755 my ($ident, $select, $condition, $attrs) = @_;
2756 return $self->cursor_class->new($self, \@_, $attrs);
2757 }
2758  
2759 sub select_single {
2760 my $self = shift;
2761 my ($rv, $sth, @bind) = $self->_select(@_);
2762 my @row = $sth->fetchrow_array;
2763 my @nextrow = $sth->fetchrow_array if @row;
2764 if(@row && @nextrow) {
2765 carp "Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single";
2766 }
2767 # Need to call finish() to work round broken DBDs
2768 $sth->finish();
2769 return @row;
2770 }
2771  
2772 =head2 sql_limit_dialect
2773  
2774 This is an accessor for the default SQL limit dialect used by a particular
2775 storage driver. Can be overridden by supplying an explicit L</limit_dialect>
2776 to L<DBIx::Class::Schema/connect>. For a list of available limit dialects
2777 see L<DBIx::Class::SQLMaker::LimitDialects>.
2778  
2779 =cut
2780  
2781 3784 ▶sub _dbh_columns_info_for {
Subroutine _dbh_columns_info_for: called CC=12 SCAR=33.5
2782 3784 my ($self, $dbh, $table) = @_;
2783  
2784 3784 ▶ if ($dbh->can('column_info')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->can("column_info")) 2425 294 2719
2785 3784 my %result;
2786 my $caught;
2787 2719 ▶ try {
Subroutine __ANON__: called CC=4 SCAR=13.9
2788 4 ▶ my ($schema,$tab) = $table =~ /^(.+?)\.(.+)$/ ? ($1,$2) : (undef,$table);
Branch: 1 branch
BranchTrueFalseTotal
$table =~ /^(.+?)\.(.+)$/ ? : 0 4 4
2789 4 my $sth = $dbh->column_info( undef,$schema, $tab, '%' );
2790 4 $sth->execute();
2791 4 ▶ while ( my $info = $sth->fetchrow_hashref() ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = $sth->fetchrow_hashref) 14 4 18
2792 14 my %column_info;
2793 14 $column_info{data_type} = $info->{TYPE_NAME};
2794 14 $column_info{size} = $info->{COLUMN_SIZE};
2795 14 ▶ $column_info{is_nullable} = $info->{NULLABLE} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$info->{'NULLABLE'} ? : 6 8 14
2796 14 $column_info{default_value} = $info->{COLUMN_DEF};
2797 14 my $col_name = $info->{COLUMN_NAME};
2798 14 $col_name =~ s/^\"(.*)\"$/$1/;
2799  
2800 14 $result{$col_name} = \%column_info;
2801 }
2802 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2803 0 $caught = 1;
2804 2719 };
2805 2719 ▶ return \%result if !$caught && scalar keys %result;
Branch: 1 branch
BranchTrueFalseTotal
if not $caught and scalar keys %result 7 2712 2719
Condition100%3/3
not $caught and scalar keys %result
!ll
29424223
MC/DC100%1/1
not $caught and scalar keys %result
not $caught
Truth table100%2/2
not(A)
A= not $caught
Aresult
00
11
2806 }
2807  
2808 2715 my %result;
2809 2715 my $sth = $dbh->prepare($self->sql_maker->select($table, undef, \'1 = 0'));
2810 2715 $sth->execute;
2811 3 my @columns = @{$sth->{NAME_lc}};
2812 2715 for my $i ( 0 .. $#columns ){
2813 0 my %column_info;
2814 0 $column_info{data_type} = $sth->{TYPE}->[$i];
2815 0 $column_info{size} = $sth->{PRECISION}->[$i];
2816 0 ▶ $column_info{is_nullable} = $sth->{NULLABLE}->[$i] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sth->{'NULLABLE'}[$i] ? : 0 0 0
2817  
2818 0 ▶ if ($column_info{data_type} =~ m/^(.*?)\((.*?)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column_info{"data_type"} =~ /^(.*?)\((.*?)\)$/) 0 0 0
2819 0 $column_info{data_type} = $1;
2820 0 $column_info{size} = $2;
2821 }
2822  
2823 0 $result{$columns[$i]} = \%column_info;
2824 }
2825 0 $sth->finish;
2826  
2827 0 foreach my $col (keys %result) {
2828 0 my $colinfo = $result{$col};
2829 0 my $type_num = $colinfo->{data_type};
2830 0 my $type_name;
2831 0 ▶ if(defined $type_num && $dbh->can('type_info')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_num and $dbh->can("type_info")) 0 0 0
Condition0%0/3
defined $type_num and $dbh->can("type_info")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type_num and $dbh->can("type_info")
defined $type_num $dbh->can("type_info")
Truth table0%0/3
A and B
A= defined $type_numB= $dbh->can("type_info")
ABresult
0X0
100
111
2832 0 my $type_info = $dbh->type_info($type_num);
2833 0 ▶ $type_name = $type_info->{TYPE_NAME} if $type_info;
Branch: 1 branch
BranchTrueFalseTotal
if $type_info 0 0 0
2834 0 ▶ $colinfo->{data_type} = $type_name if $type_name;
Branch: 1 branch
BranchTrueFalseTotal
if $type_name 0 0 0
2835 }
2836 }
2837  
2838 0 return \%result;
2839 }
2840  
2841 4 ▶sub columns_info_for {
Subroutine columns_info_for: called CC=1 SCAR=0.0
Pod documented
2842 4 my ($self, $table) = @_;
2843 4 $self->_dbh_columns_info_for ($self->_get_dbh, $table);
2844 }
2845  
2846 =head2 last_insert_id
2847  
2848 Return the row id of the last insert.
2849  
2850 =cut
2851  
2852 1226 ▶sub _dbh_last_insert_id {
Subroutine _dbh_last_insert_id: called CC=2 SCAR=7.9
2853 1226 my ($self, $dbh, $source, $col) = @_;
2854  
2855 1226 ▶ my $id = try { $dbh->last_insert_id (undef, undef, $source->name, $col) };
Subroutine __ANON__: called CC=1 SCAR=0.0
2856  
2857 1226 ▶ return $id if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 1226 0 1226
2858  
2859 0 my $class = ref $self;
2860 0 $self->throw_exception ("No storage specific _dbh_last_insert_id() method implemented in $class, and the generic DBI::last_insert_id() failed");
2861 }
2862  
2863 1226 ▶sub last_insert_id {
Subroutine last_insert_id: called CC=1 SCAR=0.0
Pod documented
2864 1226 my $self = shift;
2865 1226 $self->_dbh_last_insert_id ($self->_dbh, @_);
2866 }
2867  
2868 =head2 _native_data_type
2869  
2870 =over 4
2871  
2872 =item Arguments: $type_name
2873  
2874 =back
2875  
2876 This API is B<EXPERIMENTAL>, will almost definitely change in the future, and
2877 currently only used by L<::AutoCast|DBIx::Class::Storage::DBI::AutoCast> and
2878 L<::Sybase::ASE|DBIx::Class::Storage::DBI::Sybase::ASE>.
2879  
2880 The default implementation returns C<undef>, implement in your Storage driver if
2881 you need this functionality.
2882  
2883 Should map types from other databases to the native RDBMS type, for example
2884 C<VARCHAR2> to C<VARCHAR>.
2885  
2886 Types with modifiers should map to the underlying data type. For example,
2887 C<INTEGER AUTO_INCREMENT> should become C<INTEGER>.
2888  
2889 Composite types should map to the container type, for example
2890 C<ENUM(foo,bar,baz)> becomes C<ENUM>.
2891  
2892 =cut
2893  
2894 0 ▶sub _native_data_type {
Subroutine _native_data_type: not called CC=1 SCAR=6.9
2895 #my ($self, $data_type) = @_;
2896 return undef
2897 0 }
2898  
2899 # Check if placeholders are supported at all
2900 0 ▶sub _determine_supports_placeholders {
Subroutine _determine_supports_placeholders: not called CC=1 SCAR=6.9
2901 0 my $self = shift;
2902 0 my $dbh = $self->_get_dbh;
2903  
2904 # some drivers provide a $dbh attribute (e.g. Sybase and $dbh->{syb_dynamic_supported})
2905 # but it is inaccurate more often than not
2906 0 ▶ return try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2907 0 local $dbh->{PrintError} = 0;
2908 0 local $dbh->{RaiseError} = 1;
2909 0 $dbh->do('select ?', {}, 1);
2910 0 1;
2911 }
2912 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2913 0 0;
2914 0 };
2915 }
2916  
2917 # Check if placeholders bound to non-string types throw exceptions
2918 #
2919 0 ▶sub _determine_supports_typeless_placeholders {
Subroutine _determine_supports_typeless_placeholders: not called CC=1 SCAR=6.9
2920 0 my $self = shift;
2921 0 my $dbh = $self->_get_dbh;
2922  
2923 0 ▶ return try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2924 0 local $dbh->{PrintError} = 0;
2925 0 local $dbh->{RaiseError} = 1;
2926 # this specifically tests a bind that is NOT a string
2927 0 $dbh->do('select 1 where 1 = ?', {}, 1);
2928 0 1;
2929 }
2930 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2931 0 0;
2932 0 };
2933 }
2934  
2935 =head2 sqlt_type
2936  
2937 Returns the database driver name.
2938  
2939 =cut
2940  
2941 sub sqlt_type {
2942 shift->_get_dbh->{Driver}->{Name};
2943 }
2944  
2945 =head2 bind_attribute_by_data_type
2946  
2947 Given a datatype from column info, returns a database specific bind
2948 attribute for C<< $dbh->bind_param($val,$attribute) >> or nothing if we will
2949 let the database planner just handle it.
2950  
2951 This method is always called after the driver has been determined and a DBI
2952 connection has been established. Therefore you can refer to C<DBI::$constant>
2953 and/or C<DBD::$driver::$constant> directly, without worrying about loading
2954 the correct modules.
2955  
2956 =cut
2957  
2958 2 ▶sub bind_attribute_by_data_type {
Subroutine bind_attribute_by_data_type: called CC=1 SCAR=0.0
Pod documented
2959 2 return;
2960 }
2961  
2962 =head2 is_datatype_numeric
2963  
2964 Given a datatype from column_info, returns a boolean value indicating if
2965 the current RDBMS considers it a numeric value. This controls how
2966 L<DBIx::Class::Row/set_column> decides whether to mark the column as
2967 dirty - when the datatype is deemed numeric a C<< != >> comparison will
2968 be performed instead of the usual C<eq>.
2969  
2970 =cut
2971  
2972 45 ▶sub is_datatype_numeric {
Subroutine is_datatype_numeric: called CC=2 SCAR=7.2
Pod documented
2973 #my ($self, $dt) = @_;
2974  
2975 45 ▶ return 0 unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 45 45
2976  
2977 45 $_[1] =~ /^ (?:
2978 numeric | int(?:eger)? | (?:tiny|small|medium|big)int | dec(?:imal)? | real | float | double (?: \s+ precision)? | (?:big)?serial
2979 ) $/ix;
2980 }
2981  
2982  
2983 =head2 create_ddl_dir
2984  
2985 =over 4
2986  
2987 =item Arguments: $schema, \@databases, $version, $directory, $preversion, \%sqlt_args
2988  
2989 =back
2990  
2991 Creates a SQL file based on the Schema, for each of the specified
2992 database engines in C<\@databases> in the given directory.
2993 (note: specify L<SQL::Translator> names, not L<DBI> driver names).
2994  
2995 Given a previous version number, this will also create a file containing
2996 the ALTER TABLE statements to transform the previous schema into the
2997 current one. Note that these statements may contain C<DROP TABLE> or
2998 C<DROP COLUMN> statements that can potentially destroy data.
2999  
3000 The file names are created using the C<ddl_filename> method below, please
3001 override this method in your schema if you would like a different file
3002 name format. For the ALTER file, the same format is used, replacing
3003 $version in the name with "$preversion-$version".
3004  
3005 See L<SQL::Translator/METHODS> for a list of values for C<\%sqlt_args>.
3006 The most common value for this would be C<< { add_drop_table => 1 } >>
3007 to have the SQL produced include a C<DROP TABLE> statement for each table
3008 created. For quoting purposes supply C<quote_identifiers>.
3009  
3010 If no arguments are passed, then the following default values are assumed:
3011  
3012 =over 4
3013  
3014 =item databases - ['MySQL', 'SQLite', 'PostgreSQL']
3015  
3016 =item version - $schema->schema_version
3017  
3018 =item directory - './'
3019  
3020 =item preversion - <none>
3021  
3022 =back
3023  
3024 By default, C<\%sqlt_args> will have
3025  
3026 { add_drop_table => 1, ignore_constraint_names => 1, ignore_index_names => 1 }
3027  
3028 merged with the hash passed in. To disable any of those features, pass in a
3029 hashref like the following
3030  
3031 { ignore_constraint_names => 0, # ... other options }
3032  
3033  
3034 WARNING: You are strongly advised to check all SQL files created, before applying
3035 them.
3036  
3037 =cut
3038  
3039 0 ▶sub create_ddl_dir {
Subroutine create_ddl_dir: not called CC=32 SCAR=69.6
Pod documented
3040 0 my ($self, $schema, $databases, $version, $dir, $preversion, $sqltargs) = @_;
3041  
3042 0 ▶ unless ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
3043 0 carp "No directory given, using ./\n";
3044 0 $dir = './';
3045 } else {
3046 0 ▶ -d $dir
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or require File::Path and File::Path::mkpath(["$dir"]) or $self->throw_exception("Failed to create '${dir}': " . ($! || $@ || "error unknown")) 0 0 0
Condition0%0/11
-d $dir or require File::Path and File::Path::mkpath(["$dir"])
l!l&&r!l&&!r
000
require File::Path and File::Path::mkpath(["$dir"])
!ll&&!rl&&r
000
$! || $@ || 'error unknown'
l!l
00
$! or $@
l!l&&r!l&&!r
000
MC/DC0%0/3
-d $dir or require File::Path and File::Path::mkpath(["$dir"])
-d $dir require File::Path File::Path::mkpath(["$dir"])
MC/DC0%0/2
$! || $@ || 'error unknown'
$! $@
Truth table0%0/4
A or B and C
A= -d $dirB= require File::PathC= File::Path::mkpath(["$dir"])
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/3
A or B
A= $!B= $@
ABresult
1X1
011
000
3047 or
3048 (require File::Path and File::Path::mkpath (["$dir"])) # mkpath does not like objects (i.e. Path::Class::Dir)
3049 or
3050 $self->throw_exception(
3051 "Failed to create '$dir': " . ($! || $@ || 'error unknown')
3052 );
3053 }
3054  
3055 0 ▶ $self->throw_exception ("Directory '$dir' does not exist\n") unless(-d $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
3056  
3057 0 ▶ $databases ||= ['MySQL', 'SQLite', 'PostgreSQL'];
Condition0%0/2
$databases ||= ["MySQL", "SQLite", "PostgreSQL"]
l!l
00
MC/DC0%0/1
$databases ||= ["MySQL", "SQLite", "PostgreSQL"]
$databases
Truth table0%0/2
A
A= $databases
Aresult
11
00
3058 0 ▶ $databases = [ $databases ] if(ref($databases) ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $databases ne "ARRAY" 0 0 0
3059  
3060 0 ▶ my $schema_version = $schema->schema_version || '1.x';
Condition0%0/2
$schema->schema_version || '1.x'
l!l
00
MC/DC0%0/1
$schema->schema_version || '1.x'
$schema->schema_version
Truth table0%0/2
A
A= $schema->schema_version
Aresult
11
00
3061 0 ▶ $version ||= $schema_version;
Condition0%0/3
$version ||= $schema_version
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $schema_version
$version $schema_version
Truth table0%0/3
A ||= B
A= $versionB= $schema_version
ABresult
1X1
011
000
3062  
3063 $sqltargs = {
3064 add_drop_table => 1,
3065 ignore_constraint_names => 1,
3066 ignore_index_names => 1,
3067 quote_identifiers => $self->sql_maker->_quoting_enabled,
3068 0 ▶ %{$sqltargs || {}}
Condition0%0/2
$sqltargs || {}
l!l
00
MC/DC0%0/1
$sqltargs || {}
$sqltargs
Truth table0%0/2
A
A= $sqltargs
Aresult
11
00
3069 };
3070  
3071 0 ▶ unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("DBIx::Class::Optional::Dependencies"->req_ok_for("deploy")) 0 0 0
3072 0 $self->throw_exception("Can't create a ddl file without " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') );
3073 }
3074  
3075 0 my $sqlt = SQL::Translator->new( $sqltargs );
3076  
3077 0 $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
3078 0 ▶ my $sqlt_schema = $sqlt->translate({ data => $schema })
Branch: 1 branch
BranchTrueFalseTotal
my $sqlt_schema = $sqlt->translate({"data", $schema}) or $self->throw_exception($sqlt->error) 0 0 0
3079 or $self->throw_exception ($sqlt->error);
3080  
3081 0 foreach my $db (@$databases) {
3082 0 $sqlt->reset();
3083 0 $sqlt->{schema} = $sqlt_schema;
3084 0 $sqlt->producer($db);
3085  
3086 0 my $file;
3087 0 my $filename = $schema->ddl_filename($db, $version, $dir);
3088 0 ▶ if (-e $filename && ($version eq $schema_version )) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filename and $version eq $schema_version) 0 0 0
Condition0%0/3
-e $filename and $version eq $schema_version
!ll&&!rl&&r
000
MC/DC0%0/2
-e $filename and $version eq $schema_version
-e $filename $version eq $schema_version
Truth table0%0/3
A and B
A= -e $filenameB= $version eq $schema_version
ABresult
0X0
100
111
3089 # if we are dumping the current version, overwrite the DDL
3090 0 carp "Overwriting existing DDL file - $filename";
3091 0 unlink($filename);
3092 }
3093  
3094 0 my $output = $sqlt->translate;
3095 0 ▶ if(!$output) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output) 0 0 0
3096 0 carp("Failed to translate to $db, skipping. (" . $sqlt->error . ")");
3097 0 next;
3098 }
3099 0 ▶ if(!open($file, ">$filename")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $file, ">$filename") 0 0 0
3100 0 $self->throw_exception("Can't open $filename for writing ($!)");
3101 0 next;
3102 }
3103 0 print $file $output;
3104 0 close($file);
3105  
3106 0 ▶ next unless ($preversion);
Branch: 1 branch
BranchTrueFalseTotal
unless $preversion 0 0 0
3107  
3108 0 require SQL::Translator::Diff;
3109  
3110 0 my $prefilename = $schema->ddl_filename($db, $preversion, $dir);
3111 0 ▶ if(!-e $prefilename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $prefilename) 0 0 0
3112 0 carp("No previous schema file found ($prefilename)");
3113 0 next;
3114 }
3115  
3116 0 my $difffile = $schema->ddl_filename($db, $version, $dir, $preversion);
3117 0 ▶ if(-e $difffile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $difffile) 0 0 0
3118 0 carp("Overwriting existing diff file - $difffile");
3119 0 unlink($difffile);
3120 }
3121  
3122 0 my $source_schema;
3123 {
3124 0 my $t = SQL::Translator->new($sqltargs);
3125 0 $t->debug( 0 );
3126 0 $t->trace( 0 );
3127  
3128 0 ▶ $t->parser( $db )
Branch: 1 branch
BranchTrueFalseTotal
$t->parser($db) or $self->throw_exception($t->error) 0 0 0
3129 or $self->throw_exception ($t->error);
3130  
3131 0 ▶ my $out = $t->translate( $prefilename )
Branch: 1 branch
BranchTrueFalseTotal
my $out = $t->translate($prefilename) or $self->throw_exception($t->error) 0 0 0
3132 or $self->throw_exception ($t->error);
3133  
3134 0 $source_schema = $t->schema;
3135  
3136 0 ▶ $source_schema->name( $prefilename )
Branch: 1 branch
BranchTrueFalseTotal
unless $source_schema->name 0 0 0
3137 unless ( $source_schema->name );
3138 }
3139  
3140 # The "new" style of producers have sane normalization and can support
3141 # diffing a SQL file against a DBIC->SQLT schema. Old style ones don't
3142 # And we have to diff parsed SQL against parsed SQL.
3143 0 my $dest_schema = $sqlt_schema;
3144  
3145 0 ▶ unless ( "SQL::Translator::Producer::$db"->can('preprocess_schema') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (("SQL::Translator::Producer::$db")->can("preprocess_schema")) 0 0 0
3146 0 my $t = SQL::Translator->new($sqltargs);
3147 0 $t->debug( 0 );
3148 0 $t->trace( 0 );
3149  
3150 0 ▶ $t->parser( $db )
Branch: 1 branch
BranchTrueFalseTotal
$t->parser($db) or $self->throw_exception($t->error) 0 0 0
3151 or $self->throw_exception ($t->error);
3152  
3153 0 ▶ my $out = $t->translate( $filename )
Branch: 1 branch
BranchTrueFalseTotal
my $out = $t->translate($filename) or $self->throw_exception($t->error) 0 0 0
3154 or $self->throw_exception ($t->error);
3155  
3156 0 $dest_schema = $t->schema;
3157  
3158 0 ▶ $dest_schema->name( $filename )
Branch: 1 branch
BranchTrueFalseTotal
unless $dest_schema->name 0 0 0
3159 unless $dest_schema->name;
3160 }
3161  
3162 0 my $diff = do {
3163 # FIXME - this is a terrible workaround for
3164 # https://github.com/dbsrgits/sql-translator/commit/2d23c1e
3165 # Fixing it in this sloppy manner so that we don't hve to
3166 # lockstep an SQLT release as well. Needs to be removed at
3167 # some point, and SQLT dep bumped
3168 0 ▶ local $SQL::Translator::Producer::SQLite::NO_QUOTES
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::SQLite::NO_QUOTES 0 0 0
3169 if $SQL::Translator::Producer::SQLite::NO_QUOTES;
3170  
3171 0 SQL::Translator::Diff::schema_diff($source_schema, $db,
3172 $dest_schema, $db,
3173 $sqltargs
3174 );
3175 };
3176  
3177 0 ▶ if(!open $file, ">$difffile") {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $file, ">$difffile") 0 0 0
3178 0 $self->throw_exception("Can't write to $difffile ($!)");
3179 0 next;
3180 }
3181 0 print $file $diff;
3182 0 close($file);
3183 }
3184 }
3185  
3186 =head2 deployment_statements
3187  
3188 =over 4
3189  
3190 =item Arguments: $schema, $type, $version, $directory, $sqlt_args
3191  
3192 =back
3193  
3194 Returns the statements used by L<DBIx::Class::Storage/deploy>
3195 and L<DBIx::Class::Schema/deploy>.
3196  
3197 The L<SQL::Translator> (not L<DBI>) database driver name can be explicitly
3198 provided in C<$type>, otherwise the result of L</sqlt_type> is used as default.
3199  
3200 C<$directory> is used to return statements from files in a previously created
3201 L</create_ddl_dir> directory and is optional. The filenames are constructed
3202 from L<DBIx::Class::Schema/ddl_filename>, the schema name and the C<$version>.
3203  
3204 If no C<$directory> is specified then the statements are constructed on the
3205 fly using L<SQL::Translator> and C<$version> is ignored.
3206  
3207 See L<SQL::Translator/METHODS> for a list of values for C<$sqlt_args>.
3208  
3209 =cut
3210  
3211 sub deployment_statements {
3212 my ($self, $schema, $type, $version, $dir, $sqltargs) = @_;
3213 $type ||= $self->sqlt_type;
3214 $version ||= $schema->schema_version || '1.x';
3215 $dir ||= './';
3216 my $filename = $schema->ddl_filename($type, $version, $dir);
3217 if(-f $filename)
3218 {
3219 # FIXME replace this block when a proper sane sql parser is available
3220 my $file;
3221 open($file, "<$filename")
3222 or $self->throw_exception("Can't open $filename ($!)");
3223 my @rows = <$file>;
3224 close($file);
3225 return join('', @rows);
3226 }
3227  
3228 unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') ) {
3229 $self->throw_exception("Can't deploy without a ddl_dir or " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') );
3230 }
3231  
3232 # sources needs to be a parser arg, but for simplicity allow at top level
3233 # coming in
3234 $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources}
3235 if exists $sqltargs->{sources};
3236  
3237 $sqltargs->{quote_identifiers} = $self->sql_maker->_quoting_enabled
3238 unless exists $sqltargs->{quote_identifiers};
3239  
3240 my $tr = SQL::Translator->new(
3241 producer => "SQL::Translator::Producer::${type}",
3242 %$sqltargs,
3243 parser => 'SQL::Translator::Parser::DBIx::Class',
3244 data => $schema,
3245 );
3246  
3247 return preserve_context {
3248 $tr->translate
3249 } after => sub {
3250 $self->throw_exception( 'Unable to produce deployment statements: ' . $tr->error)
3251 unless defined $_[0];
3252 };
3253 }
3254  
3255 # FIXME deploy() currently does not accurately report sql errors
3256 # Will always return true while errors are warned
3257 0 ▶sub deploy {
Subroutine deploy: not called CC=6 SCAR=37.4
Pod documented
3258 0 my ($self, $schema, $type, $sqltargs, $dir) = @_;
3259 0 ▶ my $deploy = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
3260 0 my $line = shift;
3261 0 ▶ return if(!$line);
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
3262 0 ▶ return if($line =~ /^--/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^--/ 0 0 0
3263 # next if($line =~ /^DROP/m);
3264 0 ▶ return if($line =~ /^BEGIN TRANSACTION/m);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^BEGIN TRANSACTION/m 0 0 0
3265 0 ▶ return if($line =~ /^COMMIT/m);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^COMMIT/m 0 0 0
3266 0 ▶ return if $line =~ /^\s+$/; # skip whitespace only
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 0 0 0
3267 0 $self->_query_start($line);
3268 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3269 # do a dbh_do cycle here, as we need some error checking in
3270 # place (even though we will ignore errors)
3271 0 ▶ $self->dbh_do (sub { $_[1]->do($line) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
3272 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3273 0 carp qq{$_ (running "${line}")};
3274 0 };
3275 0 $self->_query_end($line);
3276 0 };
3277 0 ▶ my @statements = $schema->deployment_statements($type, undef, $dir, { %{ $sqltargs || {} }, no_comments => 1 } );
Condition0%0/2
$sqltargs || {}
l!l
00
MC/DC0%0/1
$sqltargs || {}
$sqltargs
Truth table0%0/2
A
A= $sqltargs
Aresult
11
00
3278 0 ▶ if (@statements > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@statements > 1) { } 0 0 0
elsif (@statements == 1) { } 0 0 0
3279 0 foreach my $statement (@statements) {
3280 0 $deploy->( $statement );
3281 }
3282 }
3283 elsif (@statements == 1) {
3284 # split on single line comments and end of statements
3285 0 foreach my $line ( split(/\s*--.*\n|;\n/, $statements[0])) {
3286 0 $deploy->( $line );
3287 }
3288 }
3289 }
3290  
3291 =head2 datetime_parser
3292  
3293 Returns the datetime parser class
3294  
3295 =cut
3296  
3297 1 ▶sub datetime_parser {
Subroutine datetime_parser: called CC=2 SCAR=7.6
Pod documented
3298 1 my $self = shift;
3299 1 ▶ return $self->{datetime_parser} ||= do {
Condition33%1/3
$self->{"datetime_parser"} ||= do { $self->build_datetime_parser(@_) }
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"datetime_parser"} ||= do { $self->build_datetime_parser(@_) }
$self->{"datetime_parser"} do { $self->build_datetime_parser(@_) }
Truth table33%1/3
A ||= B
A= $self->{"datetime_parser"}B= do { $self->build_datetime_parser(@_) }
ABresult
1X1
011
000
3300 1 $self->build_datetime_parser(@_);
3301 };
3302 }
3303  
3304 =head2 datetime_parser_type
3305  
3306 Defines the datetime parser class - currently defaults to L<DateTime::Format::MySQL>
3307  
3308 =head2 build_datetime_parser
3309  
3310 See L</datetime_parser>
3311  
3312 =cut
3313  
3314 sub build_datetime_parser {
3315 my $self = shift;
3316 my $type = $self->datetime_parser_type(@_);
3317 return $type;
3318 }
3319  
3320  
3321 =head2 is_replicating
3322  
3323 A boolean that reports if a particular L<DBIx::Class::Storage::DBI> is set to
3324 replicate from a master database. Default is undef, which is the result
3325 returned by databases that don't support replication.
3326  
3327 =cut
3328  
3329 0 ▶sub is_replicating {
Subroutine is_replicating: not called CC=1 SCAR=6.9
Pod documented
3330 0 return;
3331  
3332 }
3333  
3334 =head2 lag_behind_master
3335  
3336 Returns a number that represents a certain amount of lag behind a master db
3337 when a given storage is replicating. The number is database dependent, but
3338 starts at zero and increases with the amount of lag. Default in undef
3339  
3340 =cut
3341  
3342 0 ▶sub lag_behind_master {
Subroutine lag_behind_master: not called CC=1 SCAR=6.9
Pod documented
3343 0 return;
3344 }
3345  
3346 =head2 relname_to_table_alias
3347  
3348 =over 4
3349  
3350 =item Arguments: $relname, $join_count
3351  
3352 =item Return Value: $alias
3353  
3354 =back
3355  
3356 L<DBIx::Class> uses L<DBIx::Class::Relationship> names as table aliases in
3357 queries.
3358  
3359 This hook is to allow specific L<DBIx::Class::Storage> drivers to change the
3360 way these aliases are named.
3361  
3362 The default behavior is C<< "$relname_$join_count" if $join_count > 1 >>,
3363 otherwise C<"$relname">.
3364  
3365 =cut
3366  
3367 1655 ▶sub relname_to_table_alias {
Subroutine relname_to_table_alias: called CC=3 SCAR=11.0
Pod documented
3368 1655 my ($self, $relname, $join_count) = @_;
3369  
3370 1655 ▶ my $alias = ($join_count && $join_count > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$join_count && $join_count > 1 ? : 69 1586 1655
Condition100%3/3
$join_count and $join_count > 1
!ll&&!rl&&r
137920769
MC/DC100%2/2
$join_count and $join_count > 1
$join_count $join_count > 1
Truth table100%3/3
A and B
A= $join_countB= $join_count > 1
ABresult
0X0
100
111
3371 join('_', $relname, $join_count) : $relname);
3372  
3373 1655 return $alias;
3374 }
3375  
3376 # The size in bytes to use for DBI's ->bind_param_inout, this is the generic
3377 # version and it may be necessary to amend or override it for a specific storage
3378 # if such binds are necessary.
3379 0 ▶sub _max_column_bytesize {
Subroutine _max_column_bytesize: not called CC=10 SCAR=47.0
3380 0 my ($self, $attr) = @_;
3381  
3382 0 my $max_size;
3383  
3384 0 ▶ if ($attr->{sqlt_datatype}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"sqlt_datatype"}) 0 0 0
3385 0 my $data_type = lc($attr->{sqlt_datatype});
3386  
3387 0 ▶ if ($attr->{sqlt_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"sqlt_size"}) 0 0 0
3388  
3389 # String/sized-binary types
3390 0 ▶ if ($data_type =~ /^(?:
Branch: 2 branches
BranchTrueFalseTotal
if ($data_type =~ /^(?: l? (?:var)? char(?:acter)? (?:\s*varying)? | (?:var)? binary (?:\s*varying)? | raw )\b/x) { } 0 0 0
elsif ($data_type =~ /^(?: national \s* character (?:\s*varying)? | nchar | univarchar | nvarchar )\b/x) { } 0 0 0
3391 l? (?:var)? char(?:acter)? (?:\s*varying)?
3392 |
3393 (?:var)? binary (?:\s*varying)?
3394 |
3395 raw
3396 )\b/x
3397 ) {
3398 0 $max_size = $attr->{sqlt_size};
3399 }
3400 # Other charset/unicode types, assume scale of 4
3401 elsif ($data_type =~ /^(?:
3402 national \s* character (?:\s*varying)?
3403 |
3404 nchar
3405 |
3406 univarchar
3407 |
3408 nvarchar
3409 )\b/x
3410 ) {
3411 0 $max_size = $attr->{sqlt_size} * 4;
3412 }
3413 }
3414  
3415 0 ▶ if (!$max_size and !$self->_is_lob_type($data_type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($max_size or $self->_is_lob_type($data_type)) 0 0 0
Condition0%0/3
$max_size or $self->_is_lob_type($data_type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$max_size or $self->_is_lob_type($data_type)
$max_size $self->_is_lob_type($data_type)
Truth table0%0/3
A or B
A= $max_sizeB= $self->_is_lob_type($data_type)
ABresult
1X1
011
000
3416 0 $max_size = 100 # for all other (numeric?) datatypes
3417 }
3418 }
3419  
3420 0 ▶ $max_size || $self->_dbic_connect_attributes->{LongReadLen} || $self->_get_dbh->{LongReadLen} || 8000;
Branch: 1 branch
BranchTrueFalseTotal
$max_size or $self->_dbic_connect_attributes->{"LongReadLen"} or $self->_get_dbh->{"LongReadLen"} or 8000 0 0 0
Condition0%0/6
$max_size or $self->_dbic_connect_attributes->{"LongReadLen"} or $self->_get_dbh->{"LongReadLen"}
l!l&&r!l&&!r
000
$max_size or $self->_dbic_connect_attributes->{"LongReadLen"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$max_size or $self->_dbic_connect_attributes->{"LongReadLen"} or $self->_get_dbh->{"LongReadLen"}
$max_size $self->_dbic_connect_attributes->{"LongReadLen"} $self->_get_dbh->{"LongReadLen"}
Truth table0%0/4
A or B or C
A= $max_sizeB= $self->_dbic_connect_attributes->{"LongReadLen"}C= $self->_get_dbh->{"LongReadLen"}
ABCresult
1XX1
01X1
0011
0000
3421 }
3422  
3423 # Determine if a data_type is some type of BLOB
3424 0 ▶sub _is_lob_type {
Subroutine _is_lob_type: not called CC=3 SCAR=24.8
3425 0 my ($self, $data_type) = @_;
3426 0 ▶ $data_type && ($data_type =~ /lob|bfile|text|image|bytea|memo/i
Branch: 1 branch
BranchTrueFalseTotal
$data_type and $data_type =~ /lob|bfile|text|image|bytea|memo/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi 0 0 0
Condition0%0/6
$data_type && ($data_type =~ /lob|bfile|text|image|bytea|memo/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi)
!ll&&!rl&&r
000
$data_type =~ /lob|bfile|text|image|bytea|memo/i or $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi
l!l&&r!l&&!r
000
MC/DC0%0/3
$data_type && ($data_type =~ /lob|bfile|text|image|bytea|memo/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi)
$data_type $data_type =~ /lob|bfile|text|image|bytea|memo/i $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi
Truth table0%0/4
A && B or C
A= $data_typeB= $data_type =~ /lob|bfile|text|image|bytea|memo/iC= $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary |varchar|character\s*varying|nvarchar |national\s*character\s*varying))?\z/xi
ABCresult
0XX0
1000
11X1
1011
3427 || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary
3428 |varchar|character\s*varying|nvarchar
3429 |national\s*character\s*varying))?\z/xi);
3430 }
3431  
3432 0 ▶sub _is_binary_lob_type {
Subroutine _is_binary_lob_type: not called CC=3 SCAR=24.8
3433 0 my ($self, $data_type) = @_;
3434 0 ▶ $data_type && ($data_type =~ /blob|bfile|image|bytea/i
Branch: 1 branch
BranchTrueFalseTotal
$data_type and $data_type =~ /blob|bfile|image|bytea/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi 0 0 0
Condition0%0/6
$data_type && ($data_type =~ /blob|bfile|image|bytea/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi)
!ll&&!rl&&r
000
$data_type =~ /blob|bfile|image|bytea/i or $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi
l!l&&r!l&&!r
000
MC/DC0%0/3
$data_type && ($data_type =~ /blob|bfile|image|bytea/i || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi)
$data_type $data_type =~ /blob|bfile|image|bytea/i $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi
Truth table0%0/4
A && B or C
A= $data_typeB= $data_type =~ /blob|bfile|image|bytea/iC= $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi
ABCresult
0XX0
1000
11X1
1011
3435 || $data_type =~ /^long(?:\s+(?:raw|bit\s*varying|varbit|binary))?\z/xi);
3436 }
3437  
3438 0 ▶sub _is_text_lob_type {
Subroutine _is_text_lob_type: not called CC=3 SCAR=24.8
3439 0 my ($self, $data_type) = @_;
3440 0 ▶ $data_type && ($data_type =~ /^(?:clob|memo)\z/i
Branch: 1 branch
BranchTrueFalseTotal
$data_type and $data_type =~ /^(?:clob|memo)\z/i || $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi 0 0 0
Condition0%0/6
$data_type && ($data_type =~ /^(?:clob|memo)\z/i || $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi)
!ll&&!rl&&r
000
$data_type =~ /^(?:clob|memo)\z/i or $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi
l!l&&r!l&&!r
000
MC/DC0%0/3
$data_type && ($data_type =~ /^(?:clob|memo)\z/i || $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi)
$data_type $data_type =~ /^(?:clob|memo)\z/i $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi
Truth table0%0/4
A && B or C
A= $data_typeB= $data_type =~ /^(?:clob|memo)\z/iC= $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar |national\s*character\s*varying))\z/xi
ABCresult
0XX0
1000
11X1
1011
3441 || $data_type =~ /^long(?:\s+(?:varchar|character\s*varying|nvarchar
3442 |national\s*character\s*varying))\z/xi);
3443 }
3444  
3445 # Determine if a data_type is some type of a binary type
3446 0 ▶sub _is_binary_type {
Subroutine _is_binary_type: not called CC=3 SCAR=24.8
3447 0 my ($self, $data_type) = @_;
3448 0 ▶ $data_type && ($self->_is_binary_lob_type($data_type)
Branch: 1 branch
BranchTrueFalseTotal
$data_type and $self->_is_binary_lob_type($data_type) || $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i 0 0 0
Condition0%0/6
$data_type && ($self->_is_binary_lob_type($data_type) || $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i)
!ll&&!rl&&r
000
$self->_is_binary_lob_type($data_type) or $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i
l!l&&r!l&&!r
000
MC/DC0%0/3
$data_type && ($self->_is_binary_lob_type($data_type) || $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i)
$data_type $self->_is_binary_lob_type($data_type) $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i
Truth table0%0/4
A && B or C
A= $data_typeB= $self->_is_binary_lob_type($data_type)C= $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i
ABCresult
0XX0
1000
11X1
1011
3449 || $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i);
3450 }
3451  
3452 266 1;
3453  
3454 =head1 USAGE NOTES
3455  
3456 =head2 DBIx::Class and AutoCommit
3457  
3458 DBIx::Class can do some wonderful magic with handling exceptions,
3459 disconnections, and transactions when you use C<< AutoCommit => 1 >>
3460 (the default) combined with L<txn_do|DBIx::Class::Storage/txn_do> for
3461 transaction support.
3462  
3463 If you set C<< AutoCommit => 0 >> in your connect info, then you are always
3464 in an assumed transaction between commits, and you're telling us you'd
3465 like to manage that manually. A lot of the magic protections offered by
3466 this module will go away. We can't protect you from exceptions due to database
3467 disconnects because we don't know anything about how to restart your
3468 transactions. You're on your own for handling all sorts of exceptional
3469 cases if you choose the C<< AutoCommit => 0 >> path, just as you would
3470 be with raw DBI.
3471  
3472 =head1 FURTHER QUESTIONS?
3473  
3474 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
3475  
3476 =head1 COPYRIGHT AND LICENSE
3477  
3478 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
3479 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
3480 redistribute it and/or modify it under the same terms as the
3481 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
« DBIx/Class/Storage/DBI/Oracle/Generic.pm ↑ Summary DBIx/Class/Storage/DBI/Sybase/ASE.pm »