| 1 | ######### | ||||||||||||||||||||||||||||||||
| 2 | # Author: rmp | ||||||||||||||||||||||||||||||||
| 3 | # Created: 2006-10-31 | ||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||
| 5 | package ClearPress::driver::Pg; | ||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base qw(ClearPress::driver); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = q[2026.07.25]; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | Readonly::Scalar our $TYPES => { | |||||||||||||||||||||||||||||||
| 16 | 'primary key' => 'bigint unsigned not null auto_increment primary key', | ||||||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub dbh { | ||||||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 19 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if(!$self->{dbh} || | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"dbh"} and $self->{"dbh"}->ping
MC/DC0%0/2
$self->{"dbh"} and $self->{"dbh"}->ping
$self->{"dbh"}
$self->{"dbh"}->ping
Truth table0%0/3
A and B
A= $self->{"dbh"}B= $self->{"dbh"}->ping
| |||||||||||||||||||||||||||||||||
| 22 | !$self->{dbh}->ping()) { | ||||||||||||||||||||||||||||||||
| 23 | my $dsn = sprintf q(DBI:Pg:database=%s;host=%s;port=%s), | ||||||||||||||||||||||||||||||||
| 24 | $self->{dbname} || q[], | ||||||||||||||||||||||||||||||||
| 25 | $self->{dbhost} || q[localhost], | ||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $self->{dbport} || q[3306]; | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->{'dbname'} || ''
$self->{'dbhost'} || 'localhost'
$self->{'dbport'} || '3306'
MC/DC0%0/1
$self->{'dbname'} || ''
$self->{'dbname'}
MC/DC0%0/1
$self->{'dbhost'} || 'localhost'
$self->{'dbhost'}
MC/DC0%0/1
$self->{'dbport'} || '3306'
$self->{'dbport'}
Truth table0%0/2
A
A= $self->{'dbname'}
Truth table0%0/2
A
A= $self->{'dbhost'}
Truth table0%0/2
A
A= $self->{'dbport'}
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | eval { | ||||||||||||||||||||||||||||||||
| 29 | $self->{dbh} = DBI->connect($dsn, | ||||||||||||||||||||||||||||||||
| 30 | $self->{dbuser} || q[], | ||||||||||||||||||||||||||||||||
| 31 | $self->{dbpass}, | ||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | {RaiseError => 1, | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbuser'} || ''
MC/DC0%0/1
$self->{'dbuser'} || ''
$self->{'dbuser'}
Truth table0%0/2
A
A= $self->{'dbuser'}
| |||||||||||||||||||||||||||||||||
| 33 | AutoCommit => 0}); | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | croak qq[Failed to connect to $dsn using @{[$self->{dbuser}||q['']]}\n$EVAL_ERROR]; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbuser'} || q['']
MC/DC0%0/1
$self->{'dbuser'} || q['']
$self->{'dbuser'}
Truth table0%0/2
A
A= $self->{'dbuser'}
| |||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | ######### | ||||||||||||||||||||||||||||||||
| 40 | # rollback any junk left behind if this is a cached handle | ||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||
| 42 | 0 | $self->{dbh}->rollback(); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->{dbh}; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 49 | 0 | my ($self, $query, @args) = @_; | |||||||||||||||||||||||||||||||
| 50 | 0 | my $dbh = $self->dbh(); | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 0 | $dbh->do($query, {}, @args); | |||||||||||||||||||||||||||||||
| 53 | 0 | my $idref = $dbh->selectall_arrayref('SELECT LAST_INSERT_ID()'); | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | return $idref->[0]->[0]; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub create_table { | ||||||||||||||||||||||||||||||
|
Subroutine
create_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 59 | 0 | my ($self, $table_name, $ref) = @_; | |||||||||||||||||||||||||||||||
| 60 | 0 | return $self->SUPER::create_table($table_name, $ref, { engine=>'InnoDB'}); | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub types { | ||||||||||||||||||||||||||||||
|
Subroutine
types: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 64 | 0 | return $TYPES; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub bounded_select { | ||||||||||||||||||||||||||||||
|
Subroutine
bounded_select: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 68 | 0 | my ($self, $query, $len, $start) = @_; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 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
| |||||||||||||||||||||||||||||||||
| 71 | 0 | $query .= qq[ LIMIT $start, $len]; | |||||||||||||||||||||||||||||||
| 72 | } elsif(defined $len) { | ||||||||||||||||||||||||||||||||
| 73 | 0 | $query .= qq[ LIMIT $len]; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | return $query; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||||||