Store/SQLite3.pm

filter: Statementstmt 95.0% 57 / 60 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 72.7% 80 / 110 CC 14 SCAR 19.2
CC
14
Cov
80%
_connection
14.5
update
4.1
connection
3.0
CRAP 6.8
↑ Summary SQLite3.pm »
1 package Apache::Session::Store::SQLite3;
2 1 $Apache::Session::Store::SQLite3::VERSION = '0.03';
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Apache::Session::Store::DBI';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($TableName $DataSource $UserName $Password);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use DBI qw(:sql_types);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Apache::Session::Store::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶sub connection {
Subroutine connection: called CC=3 SCAR=11.0
Pod undocumented
12 3 my $self = shift;
13 3 my $session = shift;
14  
15 3 ▶ $self->_connection($session) unless defined $self->{dbh};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dbh"} 2 1 3
16  
17 my $tables = $self->{dbh}->selectall_arrayref(qq[
18 SELECT name
19 FROM sqlite_master
20 WHERE type = 'table'
21 AND name = ?
22 3 ], {}, $self->{table_name});
23  
24 3 ▶ $self->{dbh}->do(qq[
Branch: 1 branch
BranchTrueFalseTotal
if not @$tables 1 2 3
25 CREATE TABLE $self->{table_name} (
26 id char(32) NOT NULL,
27 a_session LONGBLOB,
28 LastUpdated TIMESTAMP,
29 PRIMARY KEY (id)
30 );
31 ]) if !@$tables;
32 }
33  
34 2 ▶sub _connection {
Subroutine _connection: called CC=8 SCAR=26.7
35 2 my $self = shift;
36 2 my $session = shift;
37  
38 $self->{'table_name'} = $session->{args}->{TableName}
39 2 ▶ || $TableName
Condition33%2/6
$session->{'args'}{'TableName'} || $Apache::Session::Store::SQLite3::TableName || $Apache::Session::Store::DBI::TableName
l!l&&r!l&&!r
020
$session->{"args"}{"TableName"} or $Apache::Session::Store::SQLite3::TableName
l!l&&r!l&&!r
002
MC/DC0%0/3
$session->{'args'}{'TableName'} || $Apache::Session::Store::SQLite3::TableName || $Apache::Session::Store::DBI::TableName
$session->{"args"}{"TableName"} $Apache::Session::Store::SQLite3::TableName $Apache::Session::Store::DBI::TableName
Truth table25%1/4
A or B || C
A= $session->{"args"}{"TableName"}B= $Apache::Session::Store::SQLite3::TableNameC= $Apache::Session::Store::DBI::TableName
ABCresult
1XX1
01X1
0011
0000
40 || $Apache::Session::Store::DBI::TableName;
41  
42 2 ▶ if (exists $session->{args}->{Handle}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $session->{"args"}{"Handle"}) 0 2 2
43 0 $self->{dbh} = $session->{args}->{Handle};
44 0 return;
45 }
46  
47 2 ▶ my $datasource = $session->{args}->{DataSource} || $DataSource;
Condition33%1/3
$session->{'args'}{'DataSource'} || $Apache::Session::Store::SQLite3::DataSource
l!l&&r!l&&!r
200
MC/DC0%0/2
$session->{'args'}{'DataSource'} || $Apache::Session::Store::SQLite3::DataSource
$session->{'args'}{'DataSource'} $Apache::Session::Store::SQLite3::DataSource
Truth table33%1/3
A || B
A= $session->{'args'}{'DataSource'}B= $Apache::Session::Store::SQLite3::DataSource
ABresult
1X1
011
000
48 2 ▶ my $username = $session->{args}->{UserName} || $UserName;
Condition33%1/3
$session->{'args'}{'UserName'} || $Apache::Session::Store::SQLite3::UserName
l!l&&r!l&&!r
002
MC/DC0%0/2
$session->{'args'}{'UserName'} || $Apache::Session::Store::SQLite3::UserName
$session->{'args'}{'UserName'} $Apache::Session::Store::SQLite3::UserName
Truth table33%1/3
A || B
A= $session->{'args'}{'UserName'}B= $Apache::Session::Store::SQLite3::UserName
ABresult
1X1
011
000
49 2 ▶ my $password = $session->{args}->{Password} || $Password;
Condition33%1/3
$session->{'args'}{'Password'} || $Apache::Session::Store::SQLite3::Password
l!l&&r!l&&!r
002
MC/DC0%0/2
$session->{'args'}{'Password'} || $Apache::Session::Store::SQLite3::Password
$session->{'args'}{'Password'} $Apache::Session::Store::SQLite3::Password
Truth table33%1/3
A || B
A= $session->{'args'}{'Password'}B= $Apache::Session::Store::SQLite3::Password
ABresult
1X1
011
000
50
51 2 ▶ $self->{dbh} = DBI->connect(
Branch: 1 branch
BranchTrueFalseTotal
$self->{"dbh"} = "DBI"->connect($datasource, $username, $password, {"RaiseError", 1, "AutoCommit", 1}) or die $DBI::errstr 2 0 2
52 $datasource,
53 $username,
54 $password,
55 { RaiseError => 1, AutoCommit => 1 }
56 ) or die $DBI::errstr;
57
58 2 $self->{disconnect} = 1;
59 }
60  
61 1 ▶sub insert {
Subroutine insert: called CC=2 SCAR=6.9
Pod undocumented
62 1 my $self = shift;
63 1 my $session = shift;
64
65 1 $self->connection($session);
66  
67 1 local $self->{dbh}->{RaiseError} = 1;
68  
69 1 ▶ if (!defined $self->{insert_sth}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"insert_sth"}) 1 0 1
70 1 $self->{insert_sth} = $self->{dbh}->prepare_cached(qq[
71 INSERT INTO $self->{'table_name'} (id, a_session, LastUpdated)
72 VALUES (?, ?, ?)
73 ]);
74 }
75  
76 1 $self->{insert_sth}->bind_param(1, $session->{data}->{_session_id}, SQL_CHAR);
77 1 $self->{insert_sth}->bind_param(2, $session->{serialized}, SQL_BLOB);
78 1 $self->{insert_sth}->bind_param(3, time, SQL_INTEGER);
79  
80 1 $self->{insert_sth}->execute;
81 1 $self->{insert_sth}->finish;
82 }
83  
84 1 ▶sub update {
Subroutine update: called CC=4 SCAR=14.0
Pod undocumented
85 1 my $self = shift;
86 1 my $session = shift;
87
88 1 $self->connection($session);
89  
90 1 local $self->{dbh}->{RaiseError} = 1;
91  
92 1 ▶ if (!defined $self->{update_sth}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"update_sth"}) 1 0 1
93 1 $self->{update_sth} = $self->{dbh}->prepare_cached(qq[
94 UPDATE $self->{'table_name'}
95 SET a_session = ?, LastUpdated = ?
96 WHERE id = ?
97 ]);
98 }
99  
100 1 $self->{update_sth}->bind_param(1, $session->{serialized}, SQL_BLOB);
101 1 $self->{update_sth}->bind_param(2, time, SQL_INTEGER);
102 1 $self->{update_sth}->bind_param(3, $session->{data}->{_session_id}, SQL_CHAR);
103  
104 1 foreach my $count (1..600) {
105 1 local $@;
106 1 ▶ eval { $self->{update_sth}->execute; 1 } and last;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->{"update_sth"}->execute; 1 } } and last 1 0 1
107 0 sleep 1;
108 }
109 1 $self->{update_sth}->finish;
110 }
111  
112 1 1;
↑ Summary SQLite3.pm »