| 1 | package DBD::Mock::db; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | our $imp_data_size = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sub ping { | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | my ($dbh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | return $dbh->{mock_can_connect}; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub last_insert_id { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 14 | ▶ | my ($dbh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 14 | return $dbh->{mock_last_insert_id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub get_info { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | my ( $dbh, $attr ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_info: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | $dbh->{mock_get_info} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dbh->{"mock_get_info"} ||= {}
MC/DC0%0/1
$dbh->{"mock_get_info"} ||= {}
$dbh->{"mock_get_info"}
Truth table50%1/2
A
A= $dbh->{"mock_get_info"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | return $dbh->{mock_get_info}{$attr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub table_info { | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | my ( $dbh, @params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_info: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | my ($cataloge, $schema, $table, $type) = map { $_ || '' } @params[0..4]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | $dbh->{mock_table_info} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$dbh->{"mock_table_info"} ||= {}
MC/DC100%1/1
$dbh->{"mock_table_info"} ||= {}
$dbh->{"mock_table_info"}
Truth table100%2/2
A
A= $dbh->{"mock_table_info"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | my @tables = @{ $dbh->{mock_table_info}->{ $cataloge }->{ $schema }->{ $table }->{ $type } || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | my ($fieldNames, @rows) = map { [ @$_ ] } @tables; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | $fieldNames ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fieldNames ||= []
MC/DC100%1/1
$fieldNames ||= []
$fieldNames
Truth table100%2/2
A
A= $fieldNames
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | my $sponge = DBI->connect('dbi:Sponge:', '', '' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | my $sth = $sponge->prepare("table_info", { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | rows => \@rows, | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | NUM_OF_FIELDS => scalar @$fieldNames, | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | NAME => $fieldNames | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | }) or return $dbh->DBI::set_err( $sponge->err(), $sponge->errstr() ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | return $sth; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub prepare { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 146 | ▶ | my ( $dbh, $statement ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=20 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 146 | ▶ | unless ( $dbh->{mock_can_connect} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 144 | ▶ | unless ( $dbh->{mock_can_prepare} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | $dbh->set_err( 1, "Cannot prepare" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 142 | ▶ | $dbh->{mock_can_prepare}++ if $dbh->{mock_can_prepare} < 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 142 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 142 | foreach my $parser ( @{ $dbh->{mock_parser} } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ( ref($parser) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | $parser->($statement); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | $parser->parse($statement); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 142 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my $parser_error = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | chomp $parser_error; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | $dbh->set_err( 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | "Failed to parse statement. Error: ${parser_error}. Statement: ${statement}" | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 140 | my $sth = DBI::_new_sth( $dbh, { Statement => $statement } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 140 | $sth->trace_msg( "Preparing statement '${statement}'\n", 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 140 | my %track_params = ( statement => $statement ); | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 140 | ▶ | if ( my $session = $dbh->{mock_session} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 46 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 46 | my $rs = $session->results_for($statement); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 41 | ▶ | if ( ref($rs) eq 'ARRAY' && scalar( @{$rs} ) > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $rs eq "ARRAY" and scalar @{$rs;} > 0
MC/DC50%1/2
ref $rs eq "ARRAY" and scalar @{$rs;} > 0
ref $rs eq "ARRAY"
scalar @{$rs;} > 0
Truth table66%2/3
A and B
A= ref $rs eq "ARRAY"B= scalar @{$rs;} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 29 | my $fields = @{$rs}[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 29 | $track_params{return_data} = $rs; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 29 | $track_params{fields} = $fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 29 | $sth->STORE( NAME => $fields ); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 29 | $sth->STORE( NUM_OF_FIELDS => scalar @{$fields} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 12 | $sth->trace_msg( "No return data set in DBH\n", 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 46 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | $dbh->DBI::set_err( 1, "Session Error: $@. Statement: $statement" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # If we have available resultsets seed the tracker with one | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 94 | my ($rs, $callback, $failure); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 94 | ▶ | if ( my $all_rs = $dbh->{mock_rs} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 55 | ▶ | if ( my $by_name = defined $all_rs->{named}{$statement} ? $all_rs->{named}{$statement} : first { $statement =~ m/$_->{regexp}/ } @{ $all_rs->{matching} } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # We want to copy this, because it is meant to be reusable | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 44 | $rs = [ @{ $by_name->{results} } ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 44 | $callback = $by_name->{callback}; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 44 | $failure = $by_name->{failure}; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | $rs = shift @{ $all_rs->{ordered} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 11 | ▶ | if (ref($rs) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | $callback = $rs->{callback}; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $failure = $rs->{failure}; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | $rs = [ @{ $rs->{results} } ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 94 | ▶ | if ( ref($rs) eq 'ARRAY' && ( scalar( @{$rs} ) > 0 || $callback ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $rs eq "ARRAY" and scalar @{$rs;} > 0 || $callback
scalar @{$rs;} > 0 or $callback
MC/DC33%1/3
ref $rs eq "ARRAY" and scalar @{$rs;} > 0 || $callback
ref $rs eq "ARRAY"
scalar @{$rs;} > 0
$callback
Truth table75%3/4
A and B or C
A= ref $rs eq "ARRAY"B= scalar @{$rs;} > 0C= $callback
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 52 | my $fields = shift @{$rs}; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 52 | $track_params{return_data} = $rs; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 52 | $track_params{fields} = $fields; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 52 | $track_params{callback} = $callback; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 52 | $track_params{failure} = $failure; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 52 | ▶ | if( $fields ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 48 | $sth->STORE( NAME => $fields ); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 48 | $sth->STORE( NUM_OF_FIELDS => scalar @{$fields}); | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 42 | $sth->trace_msg( "No return data set in DBH\n", 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # do not allow a statement handle to be created if there is no | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # connection present. | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 140 | ▶ | unless ( $dbh->FETCH('Active') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $dbh->set_err( 1, "No connection present" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # This history object will track everything done to the statement | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 140 | my $history = DBD::Mock::StatementTrack->new(%track_params); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 140 | $sth->STORE( mock_my_history => $history ); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # ...now associate the history object with the database handle so | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # people can browse the entire history at once, even for | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # statements opened and closed in a black box | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 140 | my $all_history = $dbh->FETCH('mock_statement_history'); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 140 | push @{$all_history}, $history; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 140 | return $sth; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 40 | *prepare_cached = \&prepare; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 40 | my $begin_work_commit; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | sub begin_work { | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | ▶ | my $dbh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
begin_work: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | ▶ | if ( $dbh->FETCH('AutoCommit') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | $dbh->STORE( 'AutoCommit', 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | $begin_work_commit = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | ▶ | my $sth = $dbh->prepare('BEGIN WORK') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | ▶ | my $rc = $sth->execute() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | return $dbh->set_err( 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 'AutoCommit is off, you are already within a transaction' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | sub commit { | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | my $dbh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | if ( $dbh->FETCH('AutoCommit') && $dbh->FETCH('Warn') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dbh->FETCH("AutoCommit") and $dbh->FETCH("Warn")
MC/DC50%1/2
$dbh->FETCH("AutoCommit") and $dbh->FETCH("Warn")
$dbh->FETCH("AutoCommit")
$dbh->FETCH("Warn")
Truth table66%2/3
A and B
A= $dbh->FETCH("AutoCommit")B= $dbh->FETCH("Warn")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | return $dbh->set_err( 1, "commit ineffective with AutoCommit" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | ▶ | my $sth = $dbh->prepare('COMMIT') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | ▶ | my $rc = $sth->execute() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | if ($begin_work_commit) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | $dbh->STORE( 'AutoCommit', 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $begin_work_commit = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | sub rollback { | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | ▶ | my $dbh = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rollback: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | if ( $dbh->FETCH('AutoCommit') && $dbh->FETCH('Warn') ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dbh->FETCH("AutoCommit") and $dbh->FETCH("Warn")
MC/DC50%1/2
$dbh->FETCH("AutoCommit") and $dbh->FETCH("Warn")
$dbh->FETCH("AutoCommit")
$dbh->FETCH("Warn")
Truth table66%2/3
A and B
A= $dbh->FETCH("AutoCommit")B= $dbh->FETCH("Warn")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return $dbh->set_err( 1, "rollback ineffective with AutoCommit" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | my $sth = $dbh->prepare('ROLLBACK') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | ▶ | my $rc = $sth->execute() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | or return $dbh->set_err( 1, $DBI::errstr ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | if ($begin_work_commit) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | $dbh->STORE( 'AutoCommit', 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $begin_work_commit = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | return $rc; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # NOTE: | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # this method should work in most cases, however it does | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # not exactly follow the DBI spec in the case of error | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # handling. I am not sure if that level of detail is | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # really nessecary since it is a weird error conditon | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # which causes it to fail anyway. However if you find you do need it, | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # then please email me about it. I think it would be possible | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # to mimic it by accessing the DBD::Mock::StatementTrack | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # object directly. | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 40 | sub selectcol_arrayref { | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | my ( $dbh, $query, $attrib, @bindvalues ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectcol_arrayref: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # get all the columns ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | my $a_ref = $dbh->selectall_arrayref( $query, $attrib, @bindvalues ); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # if we get nothing back, or dont get an | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # ARRAY ref back, then we can assume | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # something went wrong, and so return undef. | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | return undef unless defined $a_ref || ref($a_ref) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $a_ref or ref $a_ref ne "ARRAY"
MC/DC0%0/2
defined $a_ref or ref $a_ref ne "ARRAY"
defined $a_ref
ref $a_ref ne "ARRAY"
Truth table33%1/3
A or B
A= defined $a_refB= ref $a_ref ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my @cols = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | if ( ref $attrib->{Columns} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | @cols = map { $_ - 1 } @{ $attrib->{Columns} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # if we do get something then we | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # grab all the columns out of it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | return [ map { @$_[@cols] } @{$a_ref} ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | sub FETCH { | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 223 | ▶ | my ( $dbh, $attrib, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 223 | $dbh->trace_msg("Fetching DB attrib '$attrib'\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 223 | ▶ | if ( $attrib eq 'Active' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 148 | return $dbh->{mock_can_connect}; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | elsif ( $attrib eq 'mock_all_history' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 12 | return $dbh->{mock_statement_history}; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif ( $attrib eq 'mock_all_history_iterator' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | return DBD::Mock::StatementTrack::Iterator->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | $dbh->{mock_statement_history} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | elsif ( $attrib =~ /^mock/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 6 | return $dbh->{$attrib}; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | elsif ( $attrib =~ /^(private_|dbi_|dbd_|[A-Z])/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 50 | $dbh->trace_msg( | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | "... fetching non-driver attribute ($attrib) that DBI handles\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 50 | return $dbh->SUPER::FETCH($attrib); | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | ▶ | if ( $dbh->{mock_attribute_aliases} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 6 | ▶ | if ( exists ${ $dbh->{mock_attribute_aliases}->{db} }{$attrib} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | my $mock_attrib = | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 6 | $dbh->{mock_attribute_aliases}->{db}->{$attrib}; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 6 | ▶ | if ( ref($mock_attrib) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return $mock_attrib->($dbh); | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | return $dbh->FETCH($mock_attrib); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | $dbh->trace_msg( | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | "... fetching non-driver attribute ($attrib) that DBI doesn't handle\n" | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return $dbh->{$attrib}; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | sub STORE { | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 966 | ▶ | my ( $dbh, $attrib, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=39 SCAR=37.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 966 | ▶ | my $printed_value = $value || 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$value || 'undef'
MC/DC100%1/1
$value || 'undef'
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 966 | $dbh->trace_msg("Storing DB attribute '$attrib' with '$printed_value'\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 966 | ▶ | if ( $attrib eq 'AutoCommit' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # These are magic DBI values that say we can handle AutoCommit | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # internally as well | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 95 | ▶ | $value = ($value) ? -901 : -900; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 966 | ▶ | if ( $attrib eq 'mock_clear_history' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | $dbh->{mock_statement_history} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | return []; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | elsif ( $attrib eq 'mock_add_parser' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 6 | my $parser_type = ref($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 6 | my $is_valid_parser; | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 6 | ▶ | if ( $parser_type eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $is_valid_parser++; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ▶ | elsif ( $parser_type && $parser_type !~ /^(ARRAY|HASH|SCALAR)$/ ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$parser_type and not $parser_type =~ /^(ARRAY|HASH|SCALAR)$/
MC/DC100%2/2
$parser_type and not $parser_type =~ /^(ARRAY|HASH|SCALAR)$/
$parser_type
not $parser_type =~ /^(ARRAY|HASH|SCALAR)$/
Truth table100%3/3
A and not(B)
A= $parser_typeB= not $parser_type =~ /^(ARRAY|HASH|SCALAR)$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $is_valid_parser = eval { $parser_type->can('parse') }; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | unless ($is_valid_parser) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | my $error = | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | "Parser must be a code reference or object with 'parse()' " | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | . "method (Given type: '$parser_type')"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | $dbh->set_err( 1, $error ); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | push @{ $dbh->{mock_parser} }, $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | elsif ( $attrib eq 'mock_add_resultset' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 30 | my @copied_values; | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $dbh->{mock_rs} ||= { | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 30 | ▶ | named => {}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$dbh->{"mock_rs"} ||= {"named", {}, "ordered", [], "matching", []}
MC/DC100%1/1
$dbh->{"mock_rs"} ||= {"named", {}, "ordered", [], "matching", []}
$dbh->{"mock_rs"}
Truth table100%2/2
A
A= $dbh->{"mock_rs"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ordered => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | matching => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 30 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 7 | @copied_values = @{$value}; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 7 | push @{ $dbh->{mock_rs}{ordered} }, \@copied_values; | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | elsif ( ref $value eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 23 | my $name = $value->{sql}; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 23 | ▶ | @copied_values = @{ $value->{results} ? $value->{results} : [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 23 | ▶ | if (not defined $name) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | push @{ $dbh->{mock_rs}{ordered} }, { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | results => \@copied_values, | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | callback => $value->{callback}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | failure => ref($value->{failure}) ? [ @{ $value->{failure} } ] : undef, | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | elsif ( ref $name eq "Regexp" ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | my $matching = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | regexp => $name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | results => \@copied_values, | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | callback => $value->{callback}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 4 | ▶ | failure => ref($value->{failure}) ? [ @{ $value->{failure} } ] : undef, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # either replace existing match or push | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | ▶ | grep { $_->{regexp} eq $name && ($_ = $matching) } @{ $dbh->{mock_rs}{matching} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 4 | ▶ | or push @{ $dbh->{mock_rs}{matching} }, $matching; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | $dbh->{mock_rs}{named}{$name} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | results => \@copied_values, | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | callback => $value->{callback}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 18 | ▶ | failure => ref($value->{failure}) ? [ @{ $value->{failure} } ] : undef, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | die "Must provide an arrayref or hashref when adding ", | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | "resultset via 'mock_add_resultset'.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 30 | return \@copied_values; | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | elsif ( $attrib eq 'mock_start_insert_id' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 3 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $dbh->{mock_last_insert_ids} = {} | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | ▶ | unless $dbh->{mock_last_insert_ids}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 3 | $dbh->{mock_last_insert_ids}{ $value->[0] } = $value->[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # we start at one minus the start id | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # so that the increment works | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $dbh->{mock_last_insert_id} = $value - 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif ( $attrib eq 'mock_session' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 31 | ▶ | ( ref($value) && UNIVERSAL::isa( $value, 'DBD::Mock::Session' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
defined $value && (ref $value && UNIVERSAL::isa($value, 'DBD::Mock::Session') || die("Only DBD::Mock::Session objects can be placed into the 'mock_session' slot\n"))
ref $value and UNIVERSAL::isa($value, "DBD::Mock::Session") or die "Only DBD::Mock::Session objects can be placed into the 'mock_session' slot\n"
ref $value and UNIVERSAL::isa($value, "DBD::Mock::Session")
MC/DC0%0/3
defined $value && (ref $value && UNIVERSAL::isa($value, 'DBD::Mock::Session') || die("Only DBD::Mock::Session objects can be placed into the 'mock_session' slot\n"))
defined $value
ref $value
UNIVERSAL::isa($value, "DBD::Mock::Session")
Truth table0%0/4
A && B and C
A= defined $valueB= ref $valueC= UNIVERSAL::isa($value, "DBD::Mock::Session")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | || die | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | "Only DBD::Mock::Session objects can be placed into the 'mock_session' slot\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | if defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 31 | $dbh->{mock_session} = $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | elsif ( $attrib =~ /^mock_(add_)?data_sources/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | $dbh->{Driver}->STORE( $attrib, $value ); | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | elsif ( $attrib =~ /^mock_add_table_info$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | $dbh->{mock_table_info} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dbh->{"mock_table_info"} ||= {}
MC/DC0%0/1
$dbh->{"mock_table_info"} ||= {}
$dbh->{"mock_table_info"}
Truth table50%1/2
A
A= $dbh->{"mock_table_info"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | ▶ | if ( ref $value ne "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | die "mock_add_table_info needs a hash reference" | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | ▶ | my ( $cataloge, $schema, $table, $type ) = map { defined $_ ? $_ : '' } @$value{qw( cataloge schema table type )}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | $dbh->{mock_table_info}->{ $cataloge }->{ $schema }->{ $table }->{ $type } = $value->{table_info}; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | elsif ( $attrib =~ /^mock_clear_table_info$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | ▶ | if ( $value ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | $dbh->{mock_table_info} = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | return {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | elsif ( $attrib =~ /^mock/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 501 | return $dbh->{$attrib} = $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | elsif ( $attrib =~ /^(private_|dbi_|dbd_|[A-Z])/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 382 | $dbh->trace_msg( | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | "... storing non-driver attribute ($attrib) with value ($printed_value) that DBI handles\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 382 | return $dbh->SUPER::STORE( $attrib, $value ); | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 2 | $dbh->trace_msg( | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | "... storing non-driver attribute ($attrib) with value ($printed_value) that DBI won't handle\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | return $dbh->{$attrib} = $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 75 | ▶ | my ($dbh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 75 | ▶ | if ( my $session = $dbh->{mock_session} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 13 | ▶ | if ( $session->has_states_left ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | die "DBH->finish called when session still has states left\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 11 | ▶ | my ($dbh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 11 | ▶ | if ( my $session = $dbh->{mock_session} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | if ( $session->has_states_left ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | die "DBH->finish called when session still has states left\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||