Sybase/Storage/FreeTDS.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 5 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 86.8% 86 / 99 CC 12 SCAR 8.1
CC
12
Cov
88%
_active_statement_handles
4.1
set_textsize
3.3
_exec_txn_rollback
3.0
CRAP 2.3
« Sybase/Quote.pm ↑ Summary Sybase/Storage/ASE/IdentityRetrieval.pm »
1 package DBIO::Sybase::Storage::FreeTDS;
2 # ABSTRACT: Base class for drivers using DBD::Sybase over FreeTDS.
3  
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 our $VERSION = '0.900007';
8  
9 14 ▶use base qw/DBIO::Sybase::Storage/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 # The subclass storage driver defines _set_autocommit_stmt
16 # for MsSQL it is SET IMPLICIT_TRANSACTIONS ON/OFF
17 # for proper Sybase it's SET CHAINED ON/OFF
18 46 ▶sub _set_autocommit {
Subroutine _set_autocommit: called CC=2 SCAR=7.6
19 46 my $self = shift;
20  
21 46 ▶ if ($self->_dbh_autocommit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dbh_autocommit) { } 46 0 46
22 46 $self->_dbh->do($self->_set_autocommit_stmt(1));
23 } else {
24 0 $self->_dbh->do($self->_set_autocommit_stmt(0));
25 }
26 }
27  
28 # Handle AutoCommit and SET TEXTSIZE because LongReadLen doesn't work.
29 #
30 46 ▶sub _run_connection_actions {
Subroutine _run_connection_actions: called CC=1 SCAR=0.0
31 46 my $self = shift;
32  
33 # based on LongReadLen in connect_info
34 46 $self->set_textsize;
35  
36 46 $self->_set_autocommit;
37  
38 46 $self->next::method(@_);
39 }
40  
41  
42 46 ▶sub set_textsize {
Subroutine set_textsize: called CC=3 SCAR=12.0
Pod documented
43 46 my $self = shift;
44 my $text_size =
45 shift
46 ||
47 46 ▶ try { $self->_dbio_connect_attributes->{LongReadLen} }
Subroutine __ANON__: called CC=1 SCAR=0.0
48 ||
49 46 ▶ 32768; # the DBD::Sybase default
Condition40%2/5
shift() || &try(sub { $self->_dbio_connect_attributes->{'LongReadLen'}; } ) || 32768
l!l
046
shift() or &try(sub { $self->_dbio_connect_attributes->{"LongReadLen"}; } )
l!l&&r!l&&!r
0046
MC/DC0%0/2
shift() || &try(sub { $self->_dbio_connect_attributes->{'LongReadLen'}; } ) || 32768
shift() &try(sub { $self->_dbio_connect_attributes->{"LongReadLen"}; } )
Truth table33%1/3
A or B
A= shift()B= &try(sub { $self->_dbio_connect_attributes->{"LongReadLen"}; } )
ABresult
1X1
011
000
50  
51 46 $self->_dbh->do("SET TEXTSIZE $text_size");
52 }
53  
54 # The statement handles of $dbh that are still active. DBD::Sybase sends a
55 # statement on a database handle with an active statement handle over a
56 # connection of its own, so BEGIN TRAN, COMMIT and ROLLBACK sent with
57 # $dbh->do would land on a session that is not the transaction's (karr k65).
58 106 ▶sub _active_statement_handles {
Subroutine _active_statement_handles: called CC=4 SCAR=14.0
59 106 my ($self, $dbh) = @_;
60  
61 106 ▶ return () unless $dbh->{ActiveKids};
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->{"ActiveKids"} 102 4 106
62  
63 4 ▶ return grep { $_ && $_->{Active} } @{ $dbh->{ChildHandles} || [] };
Condition60%3/5
$_ && $_->{'Active'}
!ll&&!rl&&r
015
$dbh->{'ChildHandles'} || []
l!l
40
MC/DC50%1/2
$_ && $_->{'Active'}
$_ $_->{'Active'}
MC/DC0%0/1
$dbh->{'ChildHandles'} || []
$dbh->{'ChildHandles'}
Truth table66%2/3
A && B
A= $_B= $_->{'Active'}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $dbh->{'ChildHandles'}
Aresult
11
00
64 }
65  
66 103 ▶sub _refuse_with_open_cursor {
Subroutine _refuse_with_open_cursor: called CC=2 SCAR=6.9
67 103 my ($self, $what, $dbh) = @_;
68  
69 103 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if $self->_active_statement_handles($dbh) 2 101 103
70 "Cannot $what while a statement handle of the connection is still "
71 . 'active (an open cursor): DBD::Sybase over FreeTDS would send it on a '
72 . 'second connection, outside the transaction. Read the cursor to its end '
73 . 'or finish it first'
74 ) if $self->_active_statement_handles($dbh);
75 }
76  
77 53 ▶sub _exec_txn_begin {
Subroutine _exec_txn_begin: called CC=2 SCAR=6.9
78 53 my $self = shift;
79  
80 53 ▶ if ($self->{_in_do_block}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_in_do_block'}) { } 4 49 53
81 4 my $dbh = $self->_dbh;
82 4 $self->_refuse_with_open_cursor('BEGIN TRAN', $dbh);
83 4 $dbh->do('BEGIN TRAN');
84 }
85 else {
86 49 ▶ $self->dbh_do(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 49 $_[0]->_refuse_with_open_cursor('BEGIN TRAN', $_[1]);
88 48 $_[1]->do('BEGIN TRAN');
89 49 });
90 }
91 }
92  
93 50 ▶sub _exec_txn_commit {
Subroutine _exec_txn_commit: called CC=2 SCAR=7.0
94 50 my $self = shift;
95  
96 50 ▶ my $dbh = $self->_dbh
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->_dbh or $self->throw_exception("cannot COMMIT on a disconnected handle") 50 0 50
97 or $self->throw_exception('cannot COMMIT on a disconnected handle');
98  
99 50 $self->_refuse_with_open_cursor('COMMIT', $dbh);
100  
101 49 $dbh->do('COMMIT');
102 }
103  
104 3 ▶sub _exec_txn_rollback {
Subroutine _exec_txn_rollback: called CC=3 SCAR=11.1
105 3 my $self = shift;
106  
107 3 ▶ my $dbh = $self->_dbh
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->_dbh or $self->throw_exception("cannot ROLLBACK on a disconnected handle") 3 0 3
108 or $self->throw_exception('cannot ROLLBACK on a disconnected handle');
109  
110 # an open cursor is ended, so that the ROLLBACK goes out on the session of
111 # the transaction
112 3 $_->finish for $self->_active_statement_handles($dbh);
113  
114 3 $dbh->do('ROLLBACK');
115 }
116  
117  
118 14 1;
119  
120 __END__
« Sybase/Quote.pm ↑ Summary Sybase/Storage/ASE/IdentityRetrieval.pm »