| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Database Object Interface - ~/lib//mnt/src/perl/DB-Object/lib/DB/Object/SQLite.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Version v1.4.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Created 2017/07/19 | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## Modified 2026/09/23 | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # This is the subclassable module for driver specific ones. | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | package DB::Object::SQLite; | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | warnings::register_categories( 'DB::Object' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use vars qw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $VERSION $CACHE_SIZE $CONNECT_VIA $ERROR $DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $USE_BIND $USE_CACHE $MOD_PERL | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $PLACEHOLDER_REGEXP $DATATYPES_DICT $EXCEPTION_CLASS | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use DBI qw( :sql_types ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | eval { require DBD::SQLite; }; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | die( $@ ) if( $@ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | use parent qw( DB::Object ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | use DateTime::Lite; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | use DateTime::Lite::TimeZone; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | use Module::Generic::File qw( sys_tmpdir ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # <https://metacpan.org/pod/DBD::SQLite::Constants> | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # <https://www.sqlite.org/datatype3.html> | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # <https://metacpan.org/pod/DBD::SQLite::Constants#datatypes-(fundamental_datatypes)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # NULL, INTEGER, REAL, TEXT, BLOB | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Check DBD::SQLite::Constants | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | our $DATATYPES_DICT = | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | blob => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | constant => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | name => 'SQLITE_BLOB', | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | re => qr/^BLOB/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | type => 'blob' | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | bool => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | alias => [qw( boolean date datetime decimal numeric )], | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | constant => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | name => 'SQLITE_NULL', | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | re => qr/^(NUMERIC|DECIMAL\(\d+,\d+\)|BOOLEAN|DATETIME|DATE)/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | type => 'bool' | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | float => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | alias => [qw( double real ), 'double precision', ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | constant => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | name => 'SQLITE_FLOAT', | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | re => qr/^(REAL|DOUBLE|DOUBLE\s+PRECISION|FLOAT)/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | type => 'float' | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | integer => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | alias => [qw( int tinyint smallint mediumint bigint int2 int8 ), 'unsigned big int' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | constant => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | name => 'SQLITE_INTEGER', | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | re => qr/^(INT|INTEGER|TINYINT|SMALLINT|MEDIUMINT|BIGINT|UNSIGNED\s+BIG\s+INT|INT2|INT8)/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | type => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Data type text is only available from version 1.71 onward | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | if( $DBD::SQLite::VERSION >= 1.071 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $DATATYPES_DICT->{text} = | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | alias => [qw( character clob nchar nvarchar varchar ), 'native character', 'varying character' ], | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | constant => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | name => 'SQLITE_TEXT', | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | re => qr/^(CHARACTER\(\d+\)|VARCHAR\(\d+\)|VARYING\s+CHARACTER\(\d+\)|NCHAR\(\d+\)|NATIVE\s+CHARACTER\(\d+\)|NVARCHAR\(\d+\)|TEXT|CLOB)/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | type => 'text' | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | our $PLACEHOLDER_REGEXP = qr/(?:(?<![?\w])\?(?<index>[1-9]\d*)(?!\w))/; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | our $VERSION = 'v1.4.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # require DB::Object::SQLite::Statement; | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # require DB::Object::SQLite::Tables; | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | our $CACHE_SIZE = 10; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | our $USE_BIND = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | our $USE_CACHE = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | our $MOD_PERL = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | if( $INC{ 'Apache/DBI.pm' } && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$INC{"Apache/DBI.pm"} and substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
$ENV{'GATEWAY_INTERFACE'} || ''
MC/DC0%0/2
$INC{"Apache/DBI.pm"} and substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
$INC{"Apache/DBI.pm"}
substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
MC/DC0%0/1
$ENV{'GATEWAY_INTERFACE'} || ''
$ENV{'GATEWAY_INTERFACE'}
Truth table33%1/3
A and B
A= $INC{"Apache/DBI.pm"}B= substr($ENV{"GATEWAY_INTERFACE"} || "", 0, 8) eq "CGI-Perl"
Truth table0%0/2
A
A= $ENV{'GATEWAY_INTERFACE'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | substr( $ENV{GATEWAY_INTERFACE}|| '', 0, 8 ) eq 'CGI-Perl' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $CONNECT_VIA = "Apache::DBI::connect"; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $MOD_PERL++; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Actually the one in DB::Object is used, because DBD::SQLite has no datatype constants of its own | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # our $DATATYPES = {}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | our $PRIVATE_FUNCTIONS = | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ceiling =>[1, \&_ceiling], | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | concat =>[-1, \&_concat], | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | curdate =>[0, \&_curdate], | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | curtime =>[0, \&_curtime], | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | dayname =>[1, \&_dayname], | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | dayofmonth =>[1, \&_dayofmonth], | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | dayofweek =>[1, \&_dayofweek], | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | dayofyear =>[1, \&_dayofyear], | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | distance_miles =>[4, \&_distance_miles], | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # from_days =>[-1, \&_from_days], | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | from_unixtime =>[1, \&_from_unixtime], | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | hour =>[1, \&_hour], | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | lcase =>[1, \&_lcase], | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | left =>[2, \&_left], | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | locate =>[2, \&_locate], | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | log10 =>[1, \&_log10], | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | minute =>[1, \&_minute], | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | month =>[1, \&_month], | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | monthname =>[1, \&_monthname], | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | number_format =>[4, \&_number_format], | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | power =>[2, \&_power], | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | quarter =>[1, \&_quarter], | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | rand =>[0, \&_rand], | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | regexp =>[2, \&_regexp], | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | replace =>[3, \&_replace], | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | right =>[2, \&_right], | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | second =>[1, \&_second], | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | space =>[1, \&_space], | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sprintf =>[-1, \&_sprintf], | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | to_days =>[1, \&_to_days], | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # truncate =>[-1, \&_truncate], | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ucase =>[1, \&_ucase], | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | unix_timestamp =>[1, \&_unix_timestamp], | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | week =>[1, \&_week], | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | weekday =>[1, \&_weekday], | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | year =>[1, \&_year], | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # See compile_options method | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # This is very useful to know which features can be used | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | our $COMPILE_OPTIONS = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | foreach my $type ( keys( %$DATATYPES_DICT ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | ▶ | if( CORE::exists( $DATATYPES_DICT->{ $type }->{alias} ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
exists $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} and ref $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} eq "ARRAY" and scalar @{$DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"};}
exists $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} and ref $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} eq "ARRAY"
MC/DC50%1/2
exists $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} and ref $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} eq "ARRAY" and scalar @{$DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"};}
exists $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"}
ref $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"}B= ref $DB::Object::SQLite::DATATYPES_DICT->{$type}{"alias"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ref( $DATATYPES_DICT->{ $type }->{alias} ) eq 'ARRAY' && | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 16 | scalar( @{$DATATYPES_DICT->{ $type }->{alias}} ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 16 | foreach my $alias ( @{$DATATYPES_DICT->{ $type }->{alias}} ) | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 92 | ▶ | next if( CORE::exists( $DATATYPES_DICT->{ $alias } ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 92 | $DATATYPES_DICT->{ $alias } = $DATATYPES_DICT->{ $type }; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | foreach my $type ( keys( %$DATATYPES_DICT ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 112 | my $c = $DATATYPES_DICT->{ $type }->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 112 | my $code = \&{"DBD::SQLite::Constants::${c}"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | my $val = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 112 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 112 | $code->(); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 112 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | warn( "Datatype \"DBD::SQLite::Constants::${c}\" is not defined in DBD::SQLite version $DBD::SQLite::VERSION: $@" ) if( warnings::enabled( 'DB::Object' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | delete( $DATATYPES_DICT->{ $type } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 112 | $DATATYPES_DICT->{ $type }->{constant} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | $self->{_exception_class} = $EXCEPTION_CLASS; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 5 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | $self->{driver} = 'SQLite'; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | $self->{_func} = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Get/set alias | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # sub alias | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # sub as_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # sub avoid | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub attribute($;$@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | # $h->{AttributeName} = ...; # set/write | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # ... = $h->{AttributeName}; # get/read | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # 1 means that the attribute may be modified | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # 0 mneas that the attribute may only be read | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $name = shift( @_ ) if( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my %arg = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my %attr = | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ActiveKids => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | AutoCommit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | AutoInactiveDestroy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | CachedKids => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ChildHandles => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ChopBlanks => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | CursorName => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | Driver => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | ErrCount => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | Executed => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | FetchHashKeyName => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | HandleError => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | HandleSetErr => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | InactiveDestroy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | Kids => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | NAME => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | NULLABLE => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | NUM_OF_FIELDS => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | NUM_OF_PARAMS => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Current database name | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | Name => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | PRECISION => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | PrintError => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | PrintWarn => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | Profile => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | RaiseError => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | RowCacheSize => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | RowsInCache => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | SCALE => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ShowErrorStatement => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | Statement => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | TYPE => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | Taint => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | TaintIn => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | TaintOut => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | TraceLevel => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | Type => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | Username => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | Warn => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Not used | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # LongReadLen => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # LongTruncOk => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # CompatMode => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # If you set this to true, "do" method will process multiple statements at one go. | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # This may be handy, but with performance penalty. See above for details. | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | sqlite_allow_multiple_statements => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # If you set this to true, DBD::SQLite tries to see if the bind values are number or | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # not, and does not quote if they are numbers. | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sqlite_see_if_its_a_number => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sqlite_unicode => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Returns an unprepared part of the statement you pass to "prepare". Typically this | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # contains nothing but white spaces after a semicolon. | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | sqlite_unprepared_statements => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # If you set this to true, DBD::SQLite tries to issue a "begin immediate transaction" | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # (instead of "begin transaction") when necessary. | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sqlite_use_immediate_transaction => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | sqlite_version => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Only those attribute exist | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # Using an a non existing attribute produce an exception, so we better avoid | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if( $name ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return( $self->{dbh}->{ $name } ) if( exists( $attr{ $name } ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | while( ( $name, $value ) = each( %arg ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # We intend to modifiy the value of an attribute | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # we are allowed to modify this value if it is true | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if( exists( $attr{ $name } ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $attr{$name} and defined $value and $attr{$name}
exists $attr{$name} and defined $value
MC/DC0%0/3
exists $attr{$name} and defined $value and $attr{$name}
exists $attr{$name}
defined $value
$attr{$name}
Truth table0%0/4
A and B and C
A= exists $attr{$name}B= defined $valueC= $attr{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | defined( $value ) && | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $attr{ $name } ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->{dbh}->{ $name } = $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # sub available_drivers(@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sub begin_work($;$@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
begin_work: called CC=6 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | return( $self->{dbh}->begin_work( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return( $self->error( "Error calling begin_work(). Have you forgotten to turn on AutoCommit?: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ▶ | elsif( !$rv && $self->{dbh}->err ) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not $rv and $self->{"dbh"}->err
MC/DC0%0/2
not $rv and $self->{"dbh"}->err
not $rv
$self->{"dbh"}->err
Truth table33%1/3
not(A) and B
A= not $rvB= $self->{"dbh"}->err
| |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return( $self->error({ code => $self->{dbh}->err, message => $self->{dbh}->errstr }) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | if( defined( $rv ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | $self->_transaction_started; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ▶ | return( $rv || 1 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rv || 1
MC/DC0%0/1
$rv || 1
$rv
Truth table50%1/2
A
A= $rv
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # This method is common to DB::Object and DB::Object::Statement | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # sub bind | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # sub cache | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub can_update_delete_limit { return( shift->has_compile_option( 'ENABLE_UPDATE_DELETE_LIMIT' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_update_delete_limit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # sub check_driver(@;$@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | sub commit($;$@) | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return( $self->{dbh}->commit( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | return( $self->error( "Error calling commit(): $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ▶ | elsif( !$rv && $self->{dbh}->err ) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $rv and $self->{"dbh"}->err
MC/DC0%0/2
not $rv and $self->{"dbh"}->err
not $rv
$self->{"dbh"}->err
Truth table0%0/3
not(A) and B
A= not $rvB= $self->{"dbh"}->err
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return( $self->error({ code => $self->{dbh}->err, message => $self->{dbh}->errstr }) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if( defined( $rv ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $self->_transaction_finished; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | return( $rv || 1 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rv || 1
MC/DC0%0/1
$rv || 1
$rv
Truth table0%0/2
A
A= $rv
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | sub compile_options | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_options: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return( [ @$COMPILE_OPTIONS ] ) if( scalar( @$COMPILE_OPTIONS ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $system_tmpdir = sys_tmpdir(); | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $compile_options_cache_file = $system_tmpdir->join( 'sql_sqlite_compile_options.cfg' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my @options = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | # if( -e( $compile_options_cache_file ) && !-z( $compile_options_cache_file ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if( $compile_options_cache_file->exists && !$compile_options_cache_file->is_empty ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$compile_options_cache_file->exists and not $compile_options_cache_file->is_empty
MC/DC0%0/2
$compile_options_cache_file->exists and not $compile_options_cache_file->is_empty
$compile_options_cache_file->exists
not $compile_options_cache_file->is_empty
Truth table0%0/3
A and not(B)
A= $compile_options_cache_file->existsB= not $compile_options_cache_file->is_empty
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # my $fh = IO::File->new( "<$compile_options_cache_file" ) || return( $self->error( "Unable to read the sqlite compile options cache file \"$compile_options_cache_file\": $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my $fh = $compile_options_cache_file->open( '<' ) || return( $self->error( "Unable to read the sqlite compile options cache file \"$compile_options_cache_file\": ", $compile_options_cache_file->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$compile_options_cache_file->open('<') || (return $self->error(qq[Unable to read the sqlite compile options cache file "$compile_options_cache_file": ], $compile_options_cache_file->error))
MC/DC0%0/1
$compile_options_cache_file->open('<') || (return $self->error(qq[Unable to read the sqlite compile options cache file "$compile_options_cache_file": ], $compile_options_cache_file->error))
$compile_options_cache_file->open('<')
Truth table0%0/2
A
A= $compile_options_cache_file->open('<')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my @all = $fh->getlines; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Remove any comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | @options = grep( !/^#/, @all ); | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if( scalar( @options ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $COMPILE_OPTIONS = \@options; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Return a copy only to be safe | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return( [ @options ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # If the cache file does not yet exists or there is no options, we do the query | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | my $dbh = $self->{dbh} || return( $self->error( "No active database handler available. You can only call this method once a database connection has been made." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbh'} || (return $self->error('No active database handler available. You can only call this method once a database connection has been made.'))
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('No active database handler available. You can only call this method once a database connection has been made.'))
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $all = $self->do( "PRAGMA compile_options" )->fetchall_arrayref; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | @options = map( $_->[0], @$all ); | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | # my $fh = IO::File->new( ">$compile_options_cache_file" ) || return( $self->error( "Unable to write to sqlite compile options cache file \"$compile_options_cache_file\": $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my $fh = $compile_options_cache_file->open( '>' ) || return( $self->error( "Unable to write to sqlite compile options cache file \"$compile_options_cache_file\": ", $compile_options_cache_file->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$compile_options_cache_file->open('>') || (return $self->error(qq[Unable to write to sqlite compile options cache file "$compile_options_cache_file": ], $compile_options_cache_file->error))
MC/DC0%0/1
$compile_options_cache_file->open('>') || (return $self->error(qq[Unable to write to sqlite compile options cache file "$compile_options_cache_file": ], $compile_options_cache_file->error))
$compile_options_cache_file->open('>')
Truth table0%0/2
A
A= $compile_options_cache_file->open('>')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $fh->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | $fh->print( join( "\n", @options ), "\n" ) || return( $self->error( "Unable to write to the sqlite compile options cache file \"$compile_options_cache_file\": $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $COMPILE_OPTIONS = \@options; | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return( \@options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # connect() is inherited by DB::Object | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # NOTE: sub constant_to_datatype is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # sub copy | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # sub create_table($;%) | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # See DB::Object | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # sub data_sources($;\%) | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # sub data_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # sub database | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | sub database_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
database_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return( shift->{database_file} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | sub databases | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
databases: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | # return( $self->error( "Not connected to PostgreSQL server yet. Issue $dbh->connect first." ) ) if( !$self->{dbh} ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | my $dbh; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | # If there is no connection yet, then create one using the postgres login. | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # There should not be a live user and database just to check what databases there are. | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | if( !$self->{dbh} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | $dbh = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | $self->connect( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return( $self->error( "Error trying to connect to the SQLite database file: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ▶ | $dbh or return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $dbh = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | my $temp = $dbh->do( 'PRAGMA database_list' )->fetchall_arrayref( {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | my @dbases = map( $_->{name}, @$temp ); | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | return( @dbases ); | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # NOTE: sub datatype_dict is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # NOTE: sub datatype_to_constant is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # NOTE: sub datatypes is in inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | sub func | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $table = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | # e.g. table_attributes to get the detail information on table columns | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $func_name = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | # Returns: | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # NAME attribute name | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # TYPE attribute type | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # SIZE attribute size (-1 for variable size) | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # NULLABLE flag nullable | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # DEFAULT default value | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # CONSTRAINT constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # PRIMARY_KEY flag is_primary_key | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # REMARKS attribute description | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return( $self->{dbh}->func( $table, $func_name ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # <https://metacpan.org/pod/DBD::SQLite::Constants#datatypes-(fundamental_datatypes)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # <https://www.sqlite.org/datatype3.html> | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # In SQLite, there are only 4 types: | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # SQLITE_INTEGER | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # SQLITE_FLOAT | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # SQLITE_BLOB | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # SQLITE_NULL | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | sub get_sql_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_sql_type: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | my $type = shift( @_ ) || return( $self->error( "No sql type was provided to get its constant." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No sql type was provided to get its constant.'))
MC/DC0%0/1
shift @_ || (return $self->error('No sql type was provided to get its constant.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | $type = lc( $type ); | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if( CORE::exists( $DATATYPES_DICT->{ $type } ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $DB::Object::SQLite::DATATYPES_DICT->{$type} and $type ne $DB::Object::SQLite::DATATYPES_DICT->{$type}{"type"}
MC/DC0%0/2
exists $DB::Object::SQLite::DATATYPES_DICT->{$type} and $type ne $DB::Object::SQLite::DATATYPES_DICT->{$type}{"type"}
exists $DB::Object::SQLite::DATATYPES_DICT->{$type}
$type ne $DB::Object::SQLite::DATATYPES_DICT->{$type}{"type"}
Truth table0%0/3
A and B
A= exists $DB::Object::SQLite::DATATYPES_DICT->{$type}B= $type ne $DB::Object::SQLite::DATATYPES_DICT->{$type}{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | $type ne $DATATYPES_DICT->{ $type }->{type} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $type = $DATATYPES_DICT->{ $type }->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $const; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | if( substr( $type, 0, 7 ) eq 'sqlite_' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $const = $self->{dbh}->can( "DBD::SQLite::\U${type}\E" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $const = $self->{dbh}->can( "DBD::SQLite::SQLITE_\U${type}\E" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | return( '' ) if( !defined( $const ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | return( $const->() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | sub having | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
having: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $q = $self->_reset_query; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return( $q->having( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # https://www.sqlite.org/compile.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | sub has_compile_option | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_compile_option: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | my $opt = shift( @_ ) || return( $self->error( "No compile option was provided to check" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No compile option was provided to check'))
MC/DC0%0/1
shift @_ || (return $self->error('No compile option was provided to check'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $opt = uc( $opt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $all = $self->compile_options; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my @found = grep( /^$opt/, @$all ); | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | return( $found[0] ) if( scalar( @found ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return( '' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | sub last_insert_id | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | my $table = shift( @_ ) || $self->{table}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift @_ || $self->{'table'}
MC/DC0%0/2
shift @_ || $self->{'table'}
shift @_
$self->{'table'}
Truth table0%0/3
A || B
A= shift @_B= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return( $self->{dbh}->last_insert_id( undef, undef, $table, undef ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | sub lock { return( shift->error( "Table lock is unsupported in SQLite." ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | sub pragma | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pragma: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $self = shfit( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $key2val = | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | foreign_keys => [ qw( ON OFF ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | journal_mode => [ qw( DELETE TRUNCATE ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | legacy_file_format => [ qw( ON OFF ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | reverse_unordered_selects => [ qw( ON OFF ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | synchronous => [ qw( ON OFF ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # To avoid corruption after BEGIN starts, DBD uses BEGIN IMMEDIATE. Default is TRUE | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | sqlite_use_immediate_transaction => [ qw( 1 0 ) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | cache_size => qr/^\d+$/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | sub query_object { return( shift->_set_get_object( 'query_object', 'DB::Object::SQLite::Query', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # https://www.sqlite.org/lang_replace.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # https://www.sqlite.org/lang_conflict.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # REPLACE is an alias for INSERT OR REPLACE | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # https://www.sqlite.org/lang_insert.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | sub replace | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replace: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | my $data = shift( @_ ) if( @_ == 1 && ref( $_[0] ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0]
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my @arg = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my %arg = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $select = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if( !%arg && $data && $self->_is_hash( $data => 'strict' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
not %arg and $data and $self->_is_hash($data, "strict")
not %arg and $data
MC/DC0%0/3
not %arg and $data and $self->_is_hash($data, "strict")
not %arg
$data
$self->_is_hash($data, "strict")
Truth table0%0/4
not(A) and B and C
A= not %argB= $dataC= $self->_is_hash($data, "strict")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | %arg = %$data; | |||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | ▶ | elsif( $data && ref( $data ) eq 'DB::Object::Statement' ) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$data and ref $data eq "DB::Object::Statement"
MC/DC0%0/2
$data and ref $data eq "DB::Object::Statement"
$data
ref $data eq "DB::Object::Statement"
Truth table0%0/3
A and B
A= $dataB= ref $data eq "DB::Object::Statement"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $select = $data->as_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | %arg = @arg if( @arg ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 557 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | return( $self->error( "No table was provided to replace data." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to replace data.'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to replace data.'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | my $structure = $self->structure || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->structure || (return $self->pass_error)
MC/DC0%0/1
$self->structure || (return $self->pass_error)
$self->structure
Truth table0%0/2
A
A= $self->structure
| |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $null = $self->null(); | |||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my @avoid = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | foreach my $field ( keys( %$structure ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # It is useless to insert a blank data in a field whose default value is NULL. | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # Especially since a test on a NULL field may be made specifically. | ||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | push( @avoid, $field ) if( !CORE::exists( $arg{ $field } ) && $null->{ $field } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not exists $arg{$field} and $null->{$field}
MC/DC0%0/2
not exists $arg{$field} and $null->{$field}
not exists $arg{$field}
$null->{$field}
Truth table0%0/3
not(A) and B
A= not exists $arg{$field}B= $null->{$field}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my $db_data = $self->getdefault({ | |||||||||||||||||||||||||||||||||||||||||||||
| 569 | table => $table, | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | arg => \@arg, | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | avoid => \@avoid | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | my( $fields, $values ) = $db_data->format_statement(); | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->_reset_query(); | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | delete( $self->{query_reset} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $self->{binded_values} = $db_data->{binded_values}; | |||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | my $query = $self->{query} = $select ? "REPLACE INTO $table $select" : "REPLACE INTO $table ($fields) VALUES($values)"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # Everything meaningfull lies within the object | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # If no bind should be done _save_bind does nothing | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->_save_bind(); | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | # Query string should lie within the object | ||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # _cache_this sends back an object no matter what or unde() if an error occurs | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $sth = $self->_cache_this($query); | |||||||||||||||||||||||||||||||||||||||||||||
| 584 | # STOP! No need to go further | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | if( !defined( $sth ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return( $self->error( "Error while preparing query to replace data into table '$table':\n$query", $self->errstr() ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 590 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | return( $self->error( "Error while executing query to replace data to table '$table':\n$query" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | sub register_function | ||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_function: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | return( $self->error( "I was expecting an hash reference of parameters as only argument." ) ) if( !$self->_is_hash( $_[0] => 'strict' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $opts = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | return( $self->error( "Parameter 'code' to register the private function must be a code reference." ) ) if( ref( $opts->{code} ) ne 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | $opts->{flags} = [] if( !CORE::exists( $opts->{flags} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | return( $self->error( "Parameter 'flags' must be an array reference." ) ) if( !$self->_is_array( $opts->{flags} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | $opts->{argc} = -1 if( !CORE::exists( $opts->{argc} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | return( $self->error( "No name was provided for this private function." ) ) if( !CORE::exists( $opts->{name} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my $name = $opts->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | return( $self->error( "Name provided for this private function \"$name\" contains illegal characters. Only alphabetical and numerical characters and underscore allowed with name starting with a letter." ) ) if( $name !~ /^[a-zA-Z][a-zA-Z0-9\_]+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $funcs = $self->{func}; | |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | $funcs->{ lc( $opts->{name} ) } = $opts; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | $self->sql_function_register( $opts ) if( $self->{dbh} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | return( $opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||
| 615 | sub remove_function | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_function: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | my $name = shift( @_ ) || return( $self->error( "No private function was provided to be removed." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No private function was provided to be removed.'))
MC/DC0%0/1
shift @_ || (return $self->error('No private function was provided to be removed.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my $funcs = $self->{func}; | |||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $name = lc( $name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | return( 0 ) if( !CORE::exists( $funcs->{ $name } ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | return( CORE::delete( $funcs->{ $name } ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||
| 625 | sub returning | ||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
returning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | my $q = $self->_reset_query; | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | return( $q->returning( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | sub rollback | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rollback: called CC=6 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 636 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | return( $self->{dbh}->rollback( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 639 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 641 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | return( $self->error( "Error calling rollback: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 644 | ▶ | elsif( !$rv && $self->{dbh}->err ) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not $rv and $self->{"dbh"}->err
MC/DC0%0/2
not $rv and $self->{"dbh"}->err
not $rv
$self->{"dbh"}->err
Truth table33%1/3
not(A) and B
A= not $rvB= $self->{"dbh"}->err
| |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return( $self->error({ code => $self->{dbh}->err, message => $self->{dbh}->errstr }) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | ▶ | if( defined( $rv ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | $self->_transaction_finished; | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | ▶ | return( $rv || 1 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rv || 1
MC/DC0%0/1
$rv || 1
$rv
Truth table50%1/2
A
A= $rv
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | sub sql_function_register | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 102 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_function_register: called CC=6 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 102 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 660 | 102 | ▶ | my $opts = shift( @_ ) || return( $self->error( "No private function hash reference provided." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No private function hash reference provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No private function hash reference provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 102 | ▶ | my $dbh = $self->{dbh} || return( $self->error( "No active database handler available." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'dbh'} || (return $self->error('No active database handler available.'))
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('No active database handler available.'))
$self->{'dbh'}
Truth table50%1/2
A
A= $self->{'dbh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 102 | ▶ | $opts->{flags} = [] if( !exists( $opts->{flags} ) || ref( $opts->{flags} ) ne 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $opts->{"flags"} or ref $opts->{"flags"} ne "ARRAY"
MC/DC0%0/2
not exists $opts->{"flags"} or ref $opts->{"flags"} ne "ARRAY"
not exists $opts->{"flags"}
ref $opts->{"flags"} ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not exists $opts->{"flags"}B= ref $opts->{"flags"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 102 | my $flag; | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | 102 | my $eval = join( '|', @{$opts->{flags}} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 665 | 102 | $flag = eval( $eval ); | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 102 | my $code = $opts->{code}; | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | 102 | ▶ | if( defined( $flag ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | $dbh->sqlite_create_function( $opts->{name}, $opts->{argc}, sub{ my @arg = @_; unshift( @arg, $self ); $code->( @arg ); }, $flag ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 672 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | $dbh->sqlite_create_function( $opts->{name}, $opts->{argc}, sub{ my @arg = @_; unshift( @arg, $self ); $code->( @arg ); } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 102 | $opts->{_registered_on} = time(); | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # http://www.sqlite.org/c3ref/c_status_malloc_count.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | sub stat | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | my $opt = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | my $ref = $opt->{reset} ? DBD::SQLite::sqlite_status( 0 ) : DBD::SQLite::sqlite_status(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if( $opt->{type} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | return( exists( $ref->{ $opt->{type} } ) ? $ref->{ $opt->{type} } : undef() ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | return( wantarray() ? () : undef() ) if( !%$ref ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | return( wantarray() ? %$ref : $ref ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # sub table_exists | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # { | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # my $table = shift( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # return( $self->error( "You must provide a table name to access the table methods." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # my $cache_tables = $self->cache_tables; | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # my $tables_in_cache = $cache_tables->get({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # host => 'localhost', | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # driver => $self->driver, | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # port => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # database => $self->database, | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # foreach my $ref ( @$tables_in_cache ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # { | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # return( 1 ) if( $ref->{name} eq $table ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # # We did not find it, so let's try by checking directly the database | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | # my $def = $self->table_info( $table ) || return; | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | # return(0) if( !scalar( @$def ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # return(1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | sub table_info | ||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_info: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | my $table = shift( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
MC/DC0%0/1
shift @_ || (return $self->error('You must provide a table name to access the table methods.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | return( $self->error( "You must provide a table name to access the table methods." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my $sql = <<'EOT'; | |||||||||||||||||||||||||||||||||||||||||||||
| 724 | SELECT | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | name | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | ,type | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | FROM sqlite_master | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | WHERE type IN ('table', 'view') AND name = ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | my $dbh = $self->{dbh} || return( $self->error( "Could not find database handler." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | my $sth = $dbh->prepare_cached( $sql ) || return( $self->error( "An error occured while preparing query to check if table \"$table\" exists in database \"", $self->database, "\": ", $dbh->errstr ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->prepare_cached($sql) || (return $self->error(qq[An error occured while preparing query to check if table "$table" exists in database "], $self->database, '": ', $dbh->errstr))
MC/DC0%0/1
$dbh->prepare_cached($sql) || (return $self->error(qq[An error occured while preparing query to check if table "$table" exists in database "], $self->database, '": ', $dbh->errstr))
$dbh->prepare_cached($sql)
Truth table0%0/2
A
A= $dbh->prepare_cached($sql)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | $sth->execute( $table ) || return( $self->error( "An error occured while executing query to check if table \"$table\" exists in database \"", $self->database, "\: ", $sth->errstr ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $all = $sth->fetchall_arrayref( {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | return( {} ) if( !scalar( @$all ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | return( $all->[0] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | sub tables | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | my $db = shift( @_ ) || $self->{database}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift @_ || $self->{'database'}
MC/DC0%0/2
shift @_ || $self->{'database'}
shift @_
$self->{'database'}
Truth table0%0/3
A || B
A= shift @_B= $self->{'database'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | my $all = $self->tables_info || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->tables_info || (return)
MC/DC0%0/1
$self->tables_info || (return)
$self->tables_info
Truth table0%0/2
A
A= $self->tables_info
| |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my @tables = map( $_->{name}, @$all ); | |||||||||||||||||||||||||||||||||||||||||||||
| 745 | # return( wantarray() ? () : undef() ) if( !@tables ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # return( wantarray() ? @tables : \@tables ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | return( \@tables ); | |||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||
| 750 | sub tables_info | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables_info: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 753 | 3 | ▶ | my $db = shift( @_ ) || $self->{database}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift @_ || $self->{'database'}
MC/DC0%0/2
shift @_ || $self->{'database'}
shift @_
$self->{'database'}
Truth table33%1/3
A || B
A= shift @_B= $self->{'database'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # Parameters are: ?, schema, table, and type | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # my $sth = $self->{dbh}->table_info( undef, undef, $table, "TABLE,VIEW" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # The original query was fetched by connecting to Postgres with psql -E and executing the command \z | ||||||||||||||||||||||||||||||||||||||||||||||
| 757 | # This revised query will fetch only tables, views, materialised view and foreign tables, but will avoid the mysterious view called sequence_setvals | ||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # https://stackoverflow.com/questions/82875/how-to-list-the-tables-in-a-sqlite-database-file-that-was-opened-with-attach | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | my $query = <<SQL; | |||||||||||||||||||||||||||||||||||||||||||||
| 760 | SELECT name FROM sqlite_master | ||||||||||||||||||||||||||||||||||||||||||||||
| 761 | WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | UNION ALL | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | SELECT name FROM sqlite_temp_master | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | WHERE type IN ('table','view') | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | ORDER BY 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | SQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 3 | ▶ | my $dbh = $self->{dbh} || return( $self->error( "Could not find database handler." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
MC/DC0%0/1
$self->{'dbh'} || (return $self->error('Could not find database handler.'))
$self->{'dbh'}
Truth table50%1/2
A
A= $self->{'dbh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 3 | ▶ | my $sth = $dbh->prepare_cached( $query ) || return( $self->error( sprintf( "Error while preparing query $query: %s", $dbh->errstr ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dbh->prepare_cached($query) || (return $self->error(sprintf("Error while preparing query ${query}: %s", $dbh->errstr)))
MC/DC0%0/1
$dbh->prepare_cached($query) || (return $self->error(sprintf("Error while preparing query ${query}: %s", $dbh->errstr)))
$dbh->prepare_cached($query)
Truth table50%1/2
A
A= $dbh->prepare_cached($query)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 3 | ▶ | $sth->execute() || return( $self->error( sprintf( "Error while executing query $query: %s", $sth->errstr ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 3 | my $all = $sth->fetchall_arrayref( {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 771 | 3 | return( $all ); | |||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | sub trace { return( shift->error( "Trace is unsupported on SQLite." ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | sub unlock { return( shift->error( "unlock() does not work with SQLite." ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||
| 778 | sub variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
variables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return( shift->error( "variables is currently unsupported in Postgres" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # https://www.sqlite.org/versionnumbers.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 784 | sub version | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 787 | # If we already have the information, let's use our cache instead of making a query | ||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | return( $self->{_db_version} ) if( length( $self->{_db_version} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my $sql = 'SELECT sqlite_version()'; | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | my $sth = $self->do( $sql ) || return( $self->error( "Unable to issue the sql statement '$sql' to get the server version: ", $self->errstr ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->do($sql) || (return $self->error("Unable to issue the sql statement '${sql}' to get the server version: ", $self->errstr))
MC/DC0%0/1
$self->do($sql) || (return $self->error("Unable to issue the sql statement '${sql}' to get the server version: ", $self->errstr))
$self->do($sql)
Truth table0%0/2
A
A= $self->do($sql)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | my $ver = $sth->fetchrow; | |||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 793 | # We cache it | ||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $self->{_db_version} = version->parse( $ver ); | |||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | return( $ver ); | |||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||
| 798 | sub _check_connect_param | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_connect_param: called CC=11 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 801 | 3 | my $param = $self->SUPER::_check_connect_param( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 802 | 3 | ▶ | if( !$param->{database_file} && $param->{database} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $param->{"database_file"} and $param->{"database"}
MC/DC0%0/2
not $param->{"database_file"} and $param->{"database"}
not $param->{"database_file"}
$param->{"database"}
Truth table33%1/3
not(A) and B
A= not $param->{"database_file"}B= $param->{"database"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | ▶ | if( $param->{database} eq ':memory:' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 2 | $param->{database_file} = $self->{database_file} = ':memory:'; | |||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 809 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1 | my( $filename, $path, $ext ); | |||||||||||||||||||||||||||||||||||||||||||||
| 811 | 1 | ▶ | my $uri = CORE::exists( $param->{uri} ) ? $param->{uri} : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 1 | ▶ | my $db = $param->{database} ? $param->{database} : ( $uri->path_segments )[-1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 1 | ▶ | $path = $uri ? $uri->path : $db; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # $db = Cwd::abs_path( $uri ? $uri->path : $db ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # $db = File::Spec->rel2abs( $path ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 | $db = $self->new_file( $path ); | |||||||||||||||||||||||||||||||||||||||||||||
| 817 | # If we cannot find the file and it does not end with .sqlite, let's add the extension | ||||||||||||||||||||||||||||||||||||||||||||||
| 818 | # So the user can provide the database parameter just like database => 'test' or database => './test' | ||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 1 | ▶ | $db = $self->new_file( "$db.sqlite" ) if( !$db->exists && $db->extension->lc ne 'sqlite' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $db->exists and $db->extension->lc ne "sqlite"
MC/DC0%0/2
not $db->exists and $db->extension->lc ne "sqlite"
not $db->exists
$db->extension->lc ne "sqlite"
Truth table33%1/3
not(A) and B
A= not $db->existsB= $db->extension->lc ne "sqlite"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 1 | ( $filename, $path, $ext ) = $db->baseinfo( qr/\.[^\.]+$/ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 821 | 1 | $param->{database} = $filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 822 | 1 | $param->{database_file} = $self->{database_file} = $db; | |||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 3 | ▶ | $param->{host} = 'localhost' if( !length( $param->{host} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 3 | ▶ | $param->{port} = 0 if( !CORE::exists( $param->{port} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 3 | return( $param ); | |||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||
| 830 | sub _check_default_option | ||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_default_option: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 833 | 3 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 834 | 3 | ▶ | return( $self->error( "Provided option is not a hash reference." ) ) if( !$self->_is_hash( $opts => 'strict' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 3 | ▶ | $opts->{sqlite_unicode} = 1 if( !CORE::exists( $opts->{sqlite_unicode} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 3 | return( $opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||
| 839 | sub _connection_options | ||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connection_options: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 842 | 3 | my $param = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 843 | 3 | my @sqlite_params = grep( /^sqlite_/, keys( %$param ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 844 | 3 | my $opt = $self->SUPER::_connection_options( $param ); | |||||||||||||||||||||||||||||||||||||||||||||
| 845 | 3 | @$opt{ @sqlite_params } = @$param{ @sqlite_params }; | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | 3 | return( $opt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||
| 849 | sub _connection_params2hash_driver | ||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connection_params2hash_driver: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 852 | 1 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 853 | 1 | ▶ | $opts->{sqlite_unicode} = 1 if( !length( $opts->{sqlite_unicode} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 1 | return( $opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||
| 857 | sub _connection_parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connection_parameters: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 860 | 3 | my $param = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 861 | # Even though login, password, server, host are not used, I was hesitating, but decided to leave them as ok, and ignore them | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # Or maybe should I issue an error when they are provided? | ||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 3 | my $core = $self->new_array( [qw( db login passwd host port driver database server opt uri debug cache_connections cache_dir cache_query cache_table unknown_field use_cache id )] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 864 | 3 | my @sqlite_params = grep( /^sqlite_/, keys( %$param ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 865 | # See DBD::SQLite for the list of valid parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # E.g.: sqlite_open_flags sqlite_busy_timeout sqlite_use_immediate_transaction sqlite_see_if_its_a_number sqlite_allow_multiple_statements sqlite_unprepared_statements sqlite_unicode sqlite_allow_multiple_statements sqlite_use_immediate_transaction | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 3 | $core->push( @sqlite_params ); | |||||||||||||||||||||||||||||||||||||||||||||
| 868 | 3 | ▶ | my $core_fields = $self->{_core_fields} || []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_core_fields'} || []
MC/DC0%0/1
$self->{'_core_fields'} || []
$self->{'_core_fields'}
Truth table50%1/2
A
A= $self->{'_core_fields'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 3 | $core->push( @$core_fields ); | |||||||||||||||||||||||||||||||||||||||||||||
| 870 | 3 | return( $core->unique(1) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||
| 873 | sub _dbi_connect | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbi_connect: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 876 | 3 | my $dbh = $self->{dbh} = $self->SUPER::_dbi_connect( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 877 | # my $func = $self->{_func}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 3 | my $func = $self->{_func}; | |||||||||||||||||||||||||||||||||||||||||||||
| 879 | 3 | foreach my $k ( sort( keys( %$PRIVATE_FUNCTIONS ) ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 880 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 102 | my $this = $PRIVATE_FUNCTIONS->{ $k }; | |||||||||||||||||||||||||||||||||||||||||||||
| 882 | 102 | my $ref = | |||||||||||||||||||||||||||||||||||||||||||||
| 883 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | name => $k, | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | argc => $this->[0], | ||||||||||||||||||||||||||||||||||||||||||||||
| 886 | code => $this->[1], | ||||||||||||||||||||||||||||||||||||||||||||||
| 887 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 102 | $func->{ $k } = $ref; | |||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 3 | foreach my $name ( sort( keys( %$func ) ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 891 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 102 | my $ref = $func->{ $name }; | |||||||||||||||||||||||||||||||||||||||||||||
| 893 | 102 | ▶ | if( $ref->{_registered_on} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 894 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 102 | $self->sql_function_register( $ref ); | |||||||||||||||||||||||||||||||||||||||||||||
| 898 | 102 | $ref->{_registered_on} = time(); | |||||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 3 | return( $dbh ); | |||||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||
| 903 | sub _dsn | ||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dsn: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 906 | 3 | ▶ | my $db = $self->{database_file} || return( $self->error( "No database file was specified." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'database_file'} || (return $self->error('No database file was specified.'))
MC/DC0%0/1
$self->{'database_file'} || (return $self->error('No database file was specified.'))
$self->{'database_file'}
Truth table50%1/2
A
A= $self->{'database_file'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # return( $self->error( "Database file \"$db\" does not exist." ) ) if( !-e( $db ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 3 | ▶ | return( $self->error( "Database file \"$db\" is not writable." ) ) if( -e( $db ) && !-w( $db ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $db and not -w $db
MC/DC0%0/2
-e $db and not -w $db
-e $db
not -w $db
Truth table33%1/3
A and not(B)
A= -e $dbB= not -w $db
| |||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 3 | my @params = ( sprintf( 'dbi:%s:', $self->{driver} ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 910 | 3 | push( @params, sprintf( 'dbname=%s', $db ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 911 | 3 | return( join( ';', @params ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # Private function | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | sub _ceiling | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ceiling: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 918 | 1 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 919 | 1 | return( POSIX::ceil( $args[0] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||
| 922 | sub _concat | ||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_concat: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 925 | 1 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 926 | 1 | return( join( '', @args ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||
| 929 | sub _curdate | ||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_curdate: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||
| 934 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 936 | my $tz = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | return( DateTime::Lite::TimeZone->new( name => 'local' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 939 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 941 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | $tz = DateTime::Lite::TimeZone->new( name => 'UTC' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | my $d = DateTime::Lite->from_epoch( epoch => time(), time_zone => $tz->name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | return( $d->ymd( '-' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||
| 948 | sub _curtime | ||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_curtime: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 952 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 954 | my $tz = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | return( DateTime::Lite::TimeZone->new( name => 'local' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 957 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 959 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $tz = DateTime::Lite::TimeZone->new( name => 'UTC' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | my $d = DateTime::Lite->now( time_zone => $tz->name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | return( $d->hms( ':' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||
| 966 | # e.g. Monday | ||||||||||||||||||||||||||||||||||||||||||||||
| 967 | sub _dayname | ||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dayname: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | return( $dt->day_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # E.g.: 17 | ||||||||||||||||||||||||||||||||||||||||||||||
| 976 | sub _dayofmonth | ||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dayofmonth: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | return( $dt->day ); | |||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # timestamp, [integer] 1 to 7 | ||||||||||||||||||||||||||||||||||||||||||||||
| 985 | sub _dayofweek | ||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dayofweek: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | return( $dt->day_of_week ); | |||||||||||||||||||||||||||||||||||||||||||||
| 991 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||||||
| 993 | # E.g.: 170 | ||||||||||||||||||||||||||||||||||||||||||||||
| 994 | sub _dayofyear | ||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dayofyear: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | return( $dt->day_of_year ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # http://stackoverflow.com/questions/10034636/postgres-longitude-longitude-query | ||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | sub _distance_miles | ||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_distance_miles: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | my( $lat1, $lon1, $lat2, $lon2 ) = @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 0 | my $x = 69.1 * ( $lat2 - $lat1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | my $y = 69.1 * ( $lon2 - $lon1 ) * cos( $lat1 / 57.3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | return( sqrt( $x * $x + $y * $y ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | sub _from_days | ||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_days: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my $from_days = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 1020 | my $tz = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | return( DateTime::Lite::TimeZone->new( name => 'local' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1023 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | $tz = DateTime::Lite::TimeZone->new( name => 'UTC' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | my $origin = DateTime::Lite->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 1029 | year => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | month => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | day => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | hour => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | minute => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | second => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | time_zone => $tz, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | my $epoch = DateTime::Lite->from_epoch( epoch => 0, time_zone => $tz ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # https://stackoverflow.com/questions/821423/how-can-i-calculate-the-number-of-days-between-two-dates-in-perl#7111718 | ||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | my $epoch_days = $epoch->delta_days( $origin )->delta_days(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | my $days_since_epoch = $from_days - int( $epoch_days ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | my $dt = DateTime::Lite->from_epoch( epoch => ( $days_since_epoch * 86400 ), time_zone => $tz ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | return( $dt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | sub _from_unixtime | ||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_unixtime: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | return if( $args[0] !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 1052 | my $tz = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | return( DateTime::Lite::TimeZone->new( name => 'local' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1055 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | $tz = DateTime::Lite::TimeZone->new( name => 'UTC' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | my $dt = DateTime::Lite->from_epoch( epoch => $args[0], time_zone => $tz->name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | return( $dt->strftime( '%Y-%m-%d %T%z' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | sub _hour | ||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hour: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | return( $dt->hour ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | sub _lcase | ||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lcase: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 0 | return( lc( $args[0] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | sub _left | ||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_left: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | ▶ | return( $args[0] ) if( $args[1] !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | return( substr( $args[0], 0, $args[1] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | sub _locate | ||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_locate: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | return( CORE::index( $args[0], $args[1] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | sub _log10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log10: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 0 | return( log( $args[0] ) / log( 10 ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | sub _minute | ||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_minute: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | return( $dt->minute ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | sub _month | ||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_month: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | return( $dt->month ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | sub _monthname | ||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_monthname: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | return( $dt->month_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | sub _number_format | ||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_number_format: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | my( $num, $tho, $dec, $prec ) = @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | ▶ | $self->_load_class( 'Module::Generic::Number' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | my $fmt = Module::Generic::Number->new( $num ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1132 | # 1 means with trailing zeros | ||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | return( $fmt->format( | |||||||||||||||||||||||||||||||||||||||||||||
| 1134 | thousand => $tho, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | decimal => $dec, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | precision => $prec, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | decimal_fill => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | )); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | ▶ | sub _placeholder_regexp { return( $PLACEHOLDER_REGEXP ) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_placeholder_regexp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | sub _power | ||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_power: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | return( CORE::exp( $args[ 1 ] * CORE::log( $args[ 0 ] ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | sub _quarter | ||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quarter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | return( $dt->quarter ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | sub _rand | ||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rand: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | return( CORE::rand() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | sub _regexp | ||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regexp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | my( $re, $what ) = @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | return( $what =~ /$re/ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | sub _replace | ||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replace: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 0 | my( $str, $from, $to ) = @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | $str =~ s/($from)/$to/gs; | |||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | return( $str ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | sub _right | ||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_right: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | return( CORE::substr( $args[0], CORE::length( $args[0] ) - $args[1] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | sub _second | ||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_second: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | return( $dt->second ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | sub _space | ||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_space: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | return( ' ' x CORE::int( $args[0] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | sub _sprintf | ||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sprintf: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | ▶ | for( my $i = 0; $i < scalar( @args ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | $args[$i] =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | my $eval = "CORE::sprintf( '" . join( "', '", @args ) . "' )"; | |||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | my $res = eval( $eval ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1214 | # return( CORE::sprintf( @args ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | return( $res ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | sub _to_days | ||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_days: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 1225 | my $tz = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | return( DateTime::Lite::TimeZone->new( name => 'local' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1228 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | $tz = DateTime::Lite::TimeZone->new( name => 'UTC' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | my $origin = DateTime::Lite->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 1234 | year => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | month => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | day => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | hour => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | minute => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | second => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | time_zone => $tz->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | # https://stackoverflow.com/questions/821423/how-can-i-calculate-the-number-of-days-between-two-dates-in-perl#7111718 | ||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | my $days = $dt->delta_days( $origin )->delta_days(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | return( $days ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | # sub _truncate | ||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | # { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | # my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | # my @args = @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | # return if( $args[1] !~ /^\-?\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | # return( CORE::substr( $args[0], 0, $args[1] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | sub _ucase | ||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ucase: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | return( uc( $args[0] ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1260 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | sub _unix_timestamp | ||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unix_timestamp: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 0 | return( $dt->epoch ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | sub _week | ||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_week: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | return( $dt->week_number ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | sub _weekday | ||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_weekday: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | return( $dt->day_of_week ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1284 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | sub _year | ||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_year: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | ▶ | my $dt = $self->_parse_timestamp( $args[0] ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_parse_timestamp($args[0]) || (return)
MC/DC0%0/1
$self->_parse_timestamp($args[0]) || (return)
$self->_parse_timestamp($args[0])
Truth table0%0/2
A
A= $self->_parse_timestamp($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | return( $dt->year ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | DESTROY | ||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=8 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | # <https://perldoc.perl.org/perlobj#Destructors> | ||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 2 | CORE::local( $., $@, $!, $^E, $? ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 2 | ▶ | CORE::return if( ${^GLOBAL_PHASE} eq 'DESTRUCT' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 2 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 2 | ▶ | CORE::return if( !CORE::defined( $self ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 2 | ▶ | my $class = ref( $self ) || $self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 2 | ▶ | if( $self->{sth} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | # print( STDERR "DESTROY(): Terminating sth '$self' for query:\n$self->{ 'query' }\n" ) if( $DEBUG ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | $self->{sth}->finish(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | # $self->{dbh}->disconnect(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | # if( $DEBUG ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | # { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | # my( $pack, $file, $line, $sub ) = ( caller( 0 ) )[ 0, 1, 2, 3 ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | # my( $pack2, $file2, $line2, $sub2 ) = ( caller( 1 ) ) [ 0, 1, 2, 3 ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | # print( STDERR "DESTROY database handle ($self) [$self->{ 'query' }]\ncalled within sub '$sub' ($sub2) from package '$pack' ($pack2) in file '$file' ($file2) at line '$line' ($line2).\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 2 | $self->disconnect(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | my $locks = $self->{_locks}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | ▶ | if( $locks && $self->_is_array( $locks ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$locks and $self->_is_array($locks)
MC/DC0%0/2
$locks and $self->_is_array($locks)
$locks
$self->_is_array($locks)
Truth table0%0/3
A and B
A= $locksB= $self->_is_array($locks)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | foreach my $name ( @$locks ) | |||||||||||||||||||||||||||||||||||||||||||||
| 1321 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | $self->unlock( $name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||