| 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
| |||||||||||||||||||||||||||||||||
| 23 | my $dsn = sprintf q(DBI:SQLite:dbname=%s), | ||||||||||||||||||||||||||||||||
| 24 | 29 | ▶ | $self->{dbname} || q[]; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'dbname'} || ''
MC/DC0%0/1
$self->{'dbname'} || ''
$self->{'dbname'}
Truth table50%1/2
A
A= $self->{'dbname'}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $start and defined $len
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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||