blib/lib/ClearPress/driver/SQLite.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 37.5% 3 / 8 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 73.6% 53 / 72 CC 7 SCAR 18.8
CC
7
Cov
73%
bounded_select
20.0
dbh
4.2
BEGIN
1.0
CRAP 6.5
« blib/lib/ClearPress/model.pm ↑ Summary blib/lib/ClearPress/util.pm »
1 #########
2 # Author: rmp
3 # Created: 2006-10-31
4 #
5 package ClearPress::driver::SQLite;
6 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use base qw(ClearPress::driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 15 our $VERSION = q[2026.07.25];
14  
15 15 Readonly::Scalar our $TYPES => {
16 'primary key' => 'integer primary key autoincrement',
17 'char(128)' => 'text',
18 };
19 487 ▶sub dbh {
Subroutine dbh: called CC=4 SCAR=14.2
Pod documented
20 487 my $self = shift;
21  
22 487 ▶ if(!$self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}) 29 458 487
23 my $dsn = sprintf q(DBI:SQLite:dbname=%s),
24 29 ▶ $self->{dbname} || q[];
Condition50%1/2
$self->{'dbname'} || ''
l!l
290
MC/DC0%0/1
$self->{'dbname'} || ''
$self->{'dbname'}
Truth table50%1/2
A
A= $self->{'dbname'}
Aresult
11
00
25  
26 eval {
27 29 $self->{dbh} = DBI->connect($dsn, q[], q[],
28 {RaiseError => 1,
29 AutoCommit => 0});
30 29 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->{"dbh"} = "DBI"->connect($dsn, "", "", {"RaiseError", 1, "AutoCommit", 0}) } } or do { croak("Failed to connect to ${dsn}:\n$ClearPress::driver::SQLite::EVAL_ERROR") } 29 0 29
31 0 croak qq[Failed to connect to $dsn:\n$EVAL_ERROR];
32 };
33  
34 #########
35 # rollback any junk left behind if this is a cached handle
36 #
37 29 $self->{dbh}->rollback();
38 }
39  
40 487 return $self->{dbh};
41 }
42  
43  
44 17 ▶sub create {
Subroutine create: called CC=1 SCAR=0.0
Pod documented
45 17 my ($self, $query, @args) = @_;
46 17 my $dbh = $self->dbh();
47  
48 17 $dbh->do($query, {}, @args);
49  
50 17 my ($table) = $query =~ /INTO\s+([[:lower:][:digit:]_]+)/smix;
51 17 my $sequence = q[SELECT seq FROM sqlite_sequence WHERE name=?];
52 17 my $idref = $dbh->selectall_arrayref($sequence, {}, $table);
53  
54 17 return $idref->[0]->[0];
55 }
56  
57 428 ▶sub types {
Subroutine types: called CC=1 SCAR=0.0
Pod documented
58 428 return $TYPES;
59 }
60  
61 0 ▶sub bounded_select {
Subroutine bounded_select: not called CC=4 SCAR=30.0
Pod documented
62 0 my ($self, $query, $len, $start) = @_;
63  
64 0 ▶ if(defined $start && defined $len) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $start and defined $len) { } 0 0 0
elsif (defined $len) { } 0 0 0
Condition0%0/3
defined $start and defined $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and defined $len
defined $start defined $len
Truth table0%0/3
A and B
A= defined $startB= defined $len
ABresult
0X0
100
111
65 0 $query .= qq[ LIMIT $start, $len];
66 } elsif(defined $len) {
67 0 $query .= qq[ LIMIT $len];
68 }
69  
70 0 return $query;
71 }
72  
73 15 1;
74 __END__
« blib/lib/ClearPress/model.pm ↑ Summary blib/lib/ClearPress/util.pm »