| 1 | package DBIx::Perlish; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 25 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS $SQL @BIND_VALUES); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 25 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 25 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 25 | ▶ | use Keyword::Pluggable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 25 | $VERSION = '1.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 25 | @EXPORT = qw(sql); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | @EXPORT_OK = qw(union intersect except subselect); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 25 | %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 25 | ▶ | use DBIx::Perlish::Parse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ▶ | sub union (&;$) {} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
union: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ▶ | sub intersect (&;$) {} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intersect: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ▶ | sub except (&;$) {} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
except: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ▶ | sub subselect (&) {} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subselect: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 25 | my $default_object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 25 | my $non_object_quirks = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub optree_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | return 1 if $^V lt 5.22.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optree_version: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub lexify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | ▶ | my ( $text, $insert ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lexify: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 29 | ▶ | $insert .= 'sub ' if $$text =~ /^\s*\{/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 29 | substr($$text, 0, 0, $insert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | sub import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 25 | ▶ | my $pkg = caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=13 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | local @EXPORT_OK = @EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 25 | local %EXPORT_TAGS = %EXPORT_TAGS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 25 | ▶ | if ($pkg && $pkg->can("except")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pkg and $pkg->can("except")
MC/DC0%0/2
$pkg and $pkg->can("except")
$pkg
$pkg->can("except")
Truth table33%1/3
A and B
A= $pkgB= $pkg->can("except")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # XXX maybe check prototype here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | pop @EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 25 | my @shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | ▶ | @shift = (shift()) if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | my %p = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 25 | ▶ | if ($p{prefix} && $p{prefix} =~ /^[a-zA-Z_]\w*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p{"prefix"} and $p{"prefix"} =~ /^[a-zA-Z_]\w*$/u
MC/DC50%1/2
$p{"prefix"} and $p{"prefix"} =~ /^[a-zA-Z_]\w*$/u
$p{"prefix"}
$p{"prefix"} =~ /^[a-zA-Z_]\w*$/u
Truth table66%2/3
A and B
A= $p{"prefix"}B= $p{"prefix"} =~ /^[a-zA-Z_]\w*$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 25 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | if ( $p{dbh} && ref $p{dbh} && (ref $p{dbh} eq "SCALAR" || ref $p{dbh} eq "REF")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$p{"dbh"} and ref $p{"dbh"} and ref $p{"dbh"} eq "SCALAR" || ref $p{"dbh"} eq "REF"
$p{"dbh"} and ref $p{"dbh"}
ref $p{"dbh"} eq "SCALAR" or ref $p{"dbh"} eq "REF"
MC/DC0%0/4
$p{"dbh"} and ref $p{"dbh"} and ref $p{"dbh"} eq "SCALAR" || ref $p{"dbh"} eq "REF"
$p{"dbh"}
ref $p{"dbh"}
ref $p{"dbh"} eq "SCALAR"
ref $p{"dbh"} eq "REF"
Truth table20%1/5
A and B and C or D
A= $p{"dbh"}B= ref $p{"dbh"}C= ref $p{"dbh"} eq "SCALAR"D= ref $p{"dbh"} eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | my $dbhref = $p{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | *{$pkg."::$p{prefix}_fetch"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | *{$pkg."::$p{prefix}_select"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | sub (&) { my $o = DBIx::Perlish->new(dbh => $$dbhref); $o->fetch(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | *{$pkg."::$p{prefix}_update"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub (&) { my $o = DBIx::Perlish->new(dbh => $$dbhref); $o->update(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | *{$pkg."::$p{prefix}_delete"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub (&) { my $o = DBIx::Perlish->new(dbh => $$dbhref); $o->delete(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | *{$pkg."::$p{prefix}_insert"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub { my $o = DBIx::Perlish->new(dbh => $$dbhref); $o->insert(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | ▶ | my $prefix = delete($p{prefix}) // 'db'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $p{"prefix"} // "db"
MC/DC0%0/1
delete $p{"prefix"} // "db"
delete $p{"prefix"}
Truth table50%1/2
A
A= delete $p{"prefix"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | ▶ | my $dbh = delete($p{dbh}) // '$dbh'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $p{"dbh"} // "\$dbh"
MC/DC100%1/1
delete $p{"dbh"} // "\$dbh"
delete $p{"dbh"}
Truth table100%2/2
A
A= delete $p{"dbh"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | my $iprefix = '__' . $dbh . '_execute_perlish'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 23 | $iprefix =~ s/\W//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 23 | for ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | [fetch => " $dbh, q(fetch), "], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | [select => " $dbh, q(fetch), "], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | [update => " $dbh, q(update), "], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | [delete => " $dbh, q(delete), "], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 92 | my ($name, $code) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Keyword::Pluggable::define | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | keyword => $prefix . '_' . $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 29 | ▶ | code => sub { lexify( $_[0], $iprefix.$code ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 92 | expression => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | package => $pkg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Keyword::Pluggable::define | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | keyword => $prefix . '_insert', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | code => $iprefix . "_insert $dbh, ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | expression => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | package => $pkg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 25 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 23 | *{$pkg."::${iprefix}"} = sub ($$&) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ( $dbh, $method, $sub ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $o = DBIx::Perlish->new(dbh => $dbh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $o->$method($sub); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 23 | *{$pkg."::${iprefix}_insert"} = sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $o = DBIx::Perlish->new(dbh => shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $o->insert(@_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 23 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 23 | DBIx::Perlish->export_to_level(1, @shift, %p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub init { warn "DBIx::Perlish::init is deprecated" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my ($class, %p) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | unless (UNIVERSAL::isa($p{dbh}, "DBI::db")) { # XXX maybe relax for other things? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | die "Invalid database handle supplied in the \"dbh\" parameter.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my $me = bless { dbh => $p{dbh}, quirks => {} }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | if ($p{quirks} && ref $p{quirks} eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p{"quirks"} and ref $p{"quirks"} eq "ARRAY"
MC/DC0%0/2
$p{"quirks"} and ref $p{"quirks"} eq "ARRAY"
$p{"quirks"}
ref $p{"quirks"} eq "ARRAY"
Truth table33%1/3
A and B
A= $p{"quirks"}B= ref $p{"quirks"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | for my $q (@{$p{quirks}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $me->quirk(@$q); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | return $me; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | sub quirk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $flavor = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quirk: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $quirks = $non_object_quirks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (ref $flavor) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $quirks = $flavor->{quirks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $flavor = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $flavor = lc $flavor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ($flavor eq "oracle") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $qtype = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($qtype eq "table_func_cast") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my ($func, $cast) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | die "table_func_cast requires a function name and a type name" unless $cast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $quirks->{oracle_table_func_cast}{$func} = $cast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | die "unknown quirk $qtype for $flavor"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | die "there are currently no quirks for $flavor"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub _get_flavor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my ($real_dbh) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_flavor: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $dbh = tied(%$real_dbh) || $real_dbh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
tied %$real_dbh || $real_dbh
MC/DC0%0/2
tied %$real_dbh || $real_dbh
tied %$real_dbh
$real_dbh
Truth table0%0/3
A || B
A= tied %$real_dbhB= $real_dbh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return lc $dbh->{Driver}{Name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub gen_sql_select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my ($moi, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_sql_select: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $dbh = $me->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my @kf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $flavor = _get_flavor($dbh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $kf_convert = sub { return $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ($flavor eq "pg" && $dbh->{FetchHashKeyName}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$flavor eq "pg" and $dbh->{"FetchHashKeyName"}
MC/DC0%0/2
$flavor eq "pg" and $dbh->{"FetchHashKeyName"}
$flavor eq "pg"
$dbh->{"FetchHashKeyName"}
Truth table0%0/3
A and B
A= $flavor eq "pg"B= $dbh->{"FetchHashKeyName"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($dbh->{FetchHashKeyName} eq "NAME_uc") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $kf_convert = sub { return uc $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } elsif ($dbh->{FetchHashKeyName} eq "NAME_lc") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $kf_convert = sub { return lc $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | my ($sql, $bind_values, $nret, %flags) = gen_sql($sub, "select", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | flavor => $flavor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | dbh => $dbh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | quirks => $me->{quirks} || $non_object_quirks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$me->{'quirks'} || $non_object_quirks
MC/DC0%0/2
$me->{'quirks'} || $non_object_quirks
$me->{'quirks'}
$non_object_quirks
Truth table0%0/3
A || B
A= $me->{'quirks'}B= $non_object_quirks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | key_fields => \@kf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | kf_convert => $kf_convert, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $flags{key_fields} = \@kf if @kf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $sql, $bind_values, $nret, %flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub query | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my ($moi, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ( $sql ) = $moi->gen_sql_select($sub); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | sub fetch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my ($moi, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $nret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $dbh = $me->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my %flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ($me->{sql}, $me->{bind_values}, $nret, %flags) = $me->gen_sql_select($sub); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $SQL = $me->{sql}; @BIND_VALUES = @{$me->{bind_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($flags{key_fields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my @kf = @{ $flags{key_fields} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$flags{"key_fields"} // []
MC/DC0%0/1
$flags{"key_fields"} // []
$flags{"key_fields"}
Truth table0%0/2
A
A= $flags{"key_fields"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $kf = @kf == 1 ? $kf[0] : [@kf]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my $r = $dbh->selectall_hashref($me->{sql}, $kf, {}, @{$me->{bind_values}}) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectall_hashref($me->{'sql'}, $kf, {}, @{$$me{'bind_values'};}) || {}
MC/DC0%0/1
$dbh->selectall_hashref($me->{'sql'}, $kf, {}, @{$$me{'bind_values'};}) || {}
$dbh->selectall_hashref($me->{'sql'}, $kf, {}, @{$$me{'bind_values'};})
Truth table0%0/2
A
A= $dbh->selectall_hashref($me->{'sql'}, $kf, {}, @{$$me{'bind_values'};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $postprocess; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($nret - @kf == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Only one field returned apart from the key field, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # change hash reference to simple values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | $postprocess = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my ($h, $level) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($level <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | delete @$_{@kf} for values %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $_ = (values %$_)[0] for values %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | for my $nh (values %$h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $postprocess->($nh, $level-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $postprocess = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my ($h, $level) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ($level <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | delete @$_{@kf} for values %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | for my $nh (values %$h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $postprocess->($nh, $level-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $postprocess->($r, scalar @kf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return wantarray ? %$r : $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($nret > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $r = $dbh->selectall_arrayref($me->{sql}, {Slice=>{}}, @{$me->{bind_values}}) || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectall_arrayref($me->{'sql'}, {'Slice', {}}, @{$$me{'bind_values'};}) || []
MC/DC0%0/1
$dbh->selectall_arrayref($me->{'sql'}, {'Slice', {}}, @{$$me{'bind_values'};}) || []
$dbh->selectall_arrayref($me->{'sql'}, {'Slice', {}}, @{$$me{'bind_values'};})
Truth table0%0/2
A
A= $dbh->selectall_arrayref($me->{'sql'}, {'Slice', {}}, @{$$me{'bind_values'};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return wantarray ? @$r : $r->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | my $r = $dbh->selectcol_arrayref($me->{sql}, {}, @{$me->{bind_values}}) || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectcol_arrayref($me->{'sql'}, {}, @{$$me{'bind_values'};}) || []
MC/DC0%0/1
$dbh->selectcol_arrayref($me->{'sql'}, {}, @{$$me{'bind_values'};}) || []
$dbh->selectcol_arrayref($me->{'sql'}, {}, @{$$me{'bind_values'};})
Truth table0%0/2
A
A= $dbh->selectcol_arrayref($me->{'sql'}, {}, @{$$me{'bind_values'};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return wantarray ? @$r : $r->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # XXX refactor update/delete into a single implemention if possible? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | sub update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my ($moi, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $dbh = $me->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ($me->{sql}, $me->{bind_values}) = gen_sql($sub, "update", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | flavor => _get_flavor($dbh), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | dbh => $dbh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | quirks => $me->{quirks} || $non_object_quirks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$me->{'quirks'} || $non_object_quirks
MC/DC0%0/2
$me->{'quirks'} || $non_object_quirks
$me->{'quirks'}
$non_object_quirks
Truth table0%0/3
A || B
A= $me->{'quirks'}B= $non_object_quirks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $SQL = $me->{sql}; @BIND_VALUES = @{$me->{bind_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $dbh->do($me->{sql}, {}, @{$me->{bind_values}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | sub delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | my ($moi, $sub) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $dbh = $me->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | ($me->{sql}, $me->{bind_values}) = gen_sql($sub, "delete", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | flavor => _get_flavor($dbh), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | dbh => $dbh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | quirks => $me->{quirks} || $non_object_quirks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$me->{'quirks'} || $non_object_quirks
MC/DC0%0/2
$me->{'quirks'} || $non_object_quirks
$me->{'quirks'}
$non_object_quirks
Truth table0%0/3
A || B
A= $me->{'quirks'}B= $non_object_quirks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $SQL = $me->{sql}; @BIND_VALUES = @{$me->{bind_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $dbh->do($me->{sql}, {}, @{$me->{bind_values}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | sub insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my ($moi, $table, @rows) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my $me = ref $moi ? $moi : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $dbh = $me->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my %sth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | for my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my @keys = sort keys %$row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $sql = "insert into $table ("; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $sql .= join ",", @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $sql .= ") values ("; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my (@v, @b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $skip_prepare; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | for my $v (@$row{@keys}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if (ref $v eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | push @v, scalar $v->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $skip_prepare = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | push @v, "?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | push @b, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $sql .= join ",", @v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $sql .= ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($skip_prepare) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | return undef unless defined $dbh->do($sql, {}, @b); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $k = join ";", @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $sth{$k} ||= $dbh->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$sth{$k} ||= $dbh->prepare($sql)
MC/DC0%0/2
$sth{$k} ||= $dbh->prepare($sql)
$sth{$k}
$dbh->prepare($sql)
Truth table0%0/3
A ||= B
A= $sth{$k}B= $dbh->prepare($sql)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | return undef unless defined $sth{$k}->execute(@b); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return scalar @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | sub sql ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (ref $self && $self->isa("DBIx::Perlish")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self and $self->isa("DBIx::Perlish")
MC/DC0%0/2
ref $self and $self->isa("DBIx::Perlish")
ref $self
$self->isa("DBIx::Perlish")
Truth table0%0/3
A and B
A= ref $selfB= $self->isa("DBIx::Perlish")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $self->{sql}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub { $self } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub bind_values { $_[0]->{bind_values} ? @{$_[0]->{bind_values}} : () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_values: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | sub gen_sql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 345 | ▶ | my ($sub, $operation, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_sql: called CC=61 SCAR=41.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 345 | ▶ | $args{quirks} = $non_object_quirks unless $args{quirks}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 345 | ▶ | $args{inline} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"inline"} //= 1
MC/DC100%1/1
$args{"inline"} //= 1
$args{"inline"}
Truth table100%2/2
A
A= $args{"inline"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 345 | my $S = DBIx::Perlish::Parse::init(%args, operation => $operation); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 345 | DBIx::Perlish::Parse::parse_sub($S, $sub); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 288 | my $sql = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 288 | my $next_bit = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 288 | my $nret = 9999; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 288 | my $no_aliases; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | my $dangerous; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 288 | my %flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 288 | ▶ | if ($operation eq "select") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 260 | my $nkf = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 260 | ▶ | if ($S->{key_fields}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | $nkf = @{$S->{key_fields}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | ▶ | push @{$args{key_fields}}, @{$S->{key_fields}} if $args{key_fields}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 260 | $sql = "select "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 260 | ▶ | $sql .= "distinct " if $S->{distinct}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 260 | ▶ | if ($S->{returns}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 80 | $sql .= join ", ", @{$S->{returns}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 80 | $nret = @{$S->{returns}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 80 | for my $ret (@{$S->{returns}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 118 | ▶ | $nret = 9999 if $ret =~ /\*/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | $flags{returns_dont_care} = 1 if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 80 | 1 == @{$S->{returns}} && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | $S->{returns}->[0] =~ /^(.*)\.\*/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 80 | ▶ | $S->{returns_dont_care}->{$1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
1 == @{$S->{"returns"};} and $S->{"returns"}[0] =~ /^(.*)\.\*/u and $S->{"returns_dont_care"}{$1}
1 == @{$S->{"returns"};} and $S->{"returns"}[0] =~ /^(.*)\.\*/u
MC/DC100%3/3
1 == @{$S->{"returns"};} and $S->{"returns"}[0] =~ /^(.*)\.\*/u and $S->{"returns_dont_care"}{$1}
1 == @{$S->{"returns"};}
$S->{"returns"}[0] =~ /^(.*)\.\*/u
$S->{"returns_dont_care"}{$1}
Truth table100%4/4
A and B and C
A= 1 == @{$S->{"returns"};}B= $S->{"returns"}[0] =~ /^(.*)\.\*/uC= $S->{"returns_dont_care"}{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 180 | $sql .= "*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 260 | $next_bit = " from "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 260 | ▶ | die "all returns are key fields, this is nonsensical\n" if $nkf == $nret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } elsif ($operation eq "delete") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | $no_aliases = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | $dangerous = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | $next_bit = "delete from "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } elsif ($operation eq "update") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 26 | $no_aliases = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 26 | $dangerous = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 26 | $next_bit = "update "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | die "unsupported operation: $operation\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 286 | my %tabs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 286 | for my $var (keys %{$S->{vars}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 193 | ▶ | $tabs{$S->{var_alias}->{$var}} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | $no_aliases ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | "$S->{vars}->{$var}" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | "$S->{vars}->{$var} $S->{var_alias}->{$var}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 286 | for my $tab (keys %{$S->{tabs}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 130 | ▶ | $tabs{$S->{tab_alias}->{$tab}} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | $no_aliases ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | "$tab" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | "$tab $S->{tab_alias}->{$tab}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 286 | ▶ | unless (keys %tabs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | ▶ | if ($operation eq "select" && $S->{returns}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$operation eq "select" and $S->{"returns"}
MC/DC100%2/2
$operation eq "select" and $S->{"returns"}
$operation eq "select"
$S->{"returns"}
Truth table100%3/3
A and B
A= $operation eq "select"B= $S->{"returns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 9 | ▶ | if ($args{flavor} && $args{flavor} eq "oracle") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"flavor"} and $args{"flavor"} eq "oracle"
MC/DC50%1/2
$args{"flavor"} and $args{"flavor"} eq "oracle"
$args{"flavor"}
$args{"flavor"} eq "oracle"
Truth table66%2/3
A and B
A= $args{"flavor"}B= $args{"flavor"} eq "oracle"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | $tabs{dual} = "dual"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 6 | $next_bit = " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | die "no tables specified in $operation\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 283 | $sql .= $next_bit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 283 | my %seentab; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 283 | my $joins = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 283 | for my $j ( @{$S->{joins}} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 25 | my ($join, $tab1, $tab2, $condition) = @$j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 25 | ▶ | $condition = ( defined $condition) ? " on $condition" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | die "not sure what to do with repeated tables ($tabs{$tab1} and $tabs{$tab2}) in a join\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 25 | ▶ | if $seentab{$tab1} && $seentab{$tab2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seentab{$tab1} and $seentab{$tab2}
MC/DC100%2/2
$seentab{$tab1} and $seentab{$tab2}
$seentab{$tab1}
$seentab{$tab2}
Truth table100%3/3
A and B
A= $seentab{$tab1}B= $seentab{$tab2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 24 | ▶ | if ($seentab{$tab2}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | ($tab1, $tab2) = ($tab2, $tab1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 2 | ▶ | if ($join eq "left outer") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | $join = "right outer"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } elsif ($join eq "right outer") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $join = "left outer"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 24 | ▶ | if ($seentab{$tab1}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 5 | ▶ | $joins .= " " if $joins; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 5 | $joins .= "$join join $tabs{$tab2}$condition"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 19 | ▶ | $joins .= ", " if $joins; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 19 | $joins .= "$tabs{$tab1} $join join $tabs{$tab2}$condition"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 24 | $seentab{$tab1}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 24 | $seentab{$tab2}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 282 | ▶ | my @joins = $joins ? ($joins) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 282 | $sql .= join ", ", @joins, map { $tabs{$_} } grep { !$seentab{$_} } sort keys %tabs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 282 | my @sets = grep { $_ ne "" } @{$S->{sets}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 282 | my @where = grep { $_ ne "" } @{$S->{where}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 282 | my @having = grep { $_ ne "" } @{$S->{having}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 282 | my @group_by = grep { $_ ne "" } @{$S->{group_by}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 282 | my @order_by = grep { $_ ne "" } @{$S->{order_by}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 282 | ▶ | if ($S->{autogroup_needed} && !$S->{no_autogroup} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$S->{"autogroup_needed"} and not $S->{"no_autogroup"} and not @group_by and @{$S->{"autogroup_by"};}
$S->{"autogroup_needed"} and not $S->{"no_autogroup"} and not @group_by
$S->{"autogroup_needed"} and not $S->{"no_autogroup"}
MC/DC100%4/4
$S->{"autogroup_needed"} and not $S->{"no_autogroup"} and not @group_by and @{$S->{"autogroup_by"};}
$S->{"autogroup_needed"}
not $S->{"no_autogroup"}
not @group_by
@{$S->{"autogroup_by"};}
Truth table100%5/5
A and not(B) and not(C) and D
A= $S->{"autogroup_needed"}B= not $S->{"no_autogroup"}C= not @group_byD= @{$S->{"autogroup_by"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | !@group_by && @{$S->{autogroup_by}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | @group_by = grep { $_ ne "" } @{$S->{autogroup_by}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 282 | ▶ | die "nothing to update\n" if $operation eq "update" && !@sets; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$operation eq "update" and not @sets
MC/DC100%2/2
$operation eq "update" and not @sets
$operation eq "update"
not @sets
Truth table100%3/3
A and not(B)
A= $operation eq "update"B= not @sets
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 281 | ▶ | $sql .= " set " . join ", ", @sets if @sets; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 281 | ▶ | $sql .= " where " . join " and ", @where if @where; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 281 | ▶ | $sql .= " group by " . join ", ", @group_by if @group_by; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 281 | ▶ | $sql .= " having " . join " and ", @having if @having; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 281 | ▶ | $sql .= " order by " . join ", ", @order_by if @order_by; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 281 | ▶ | if ($dangerous && !@where && !$S->{seen_exec}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$dangerous and not @where and not $S->{"seen_exec"}
$dangerous and not @where
MC/DC100%3/3
$dangerous and not @where and not $S->{"seen_exec"}
$dangerous
not @where
not $S->{"seen_exec"}
Truth table100%4/4
A and not(B) and not(C)
A= $dangerousB= not @whereC= not $S->{"seen_exec"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | die "unfiltered $operation is dangerous: use exec if you want it\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 279 | ▶ | my $use_rownum = $args{flavor} && $args{flavor} eq "oracle"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'flavor'} && $args{'flavor'} eq 'oracle'
MC/DC50%1/2
$args{'flavor'} && $args{'flavor'} eq 'oracle'
$args{'flavor'}
$args{'flavor'} eq 'oracle'
Truth table66%2/3
A && B
A= $args{'flavor'}B= $args{'flavor'} eq 'oracle'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 279 | ▶ | unless ($use_rownum) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 267 | ▶ | if ($S->{limit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | $sql .= " limit $S->{limit}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 267 | ▶ | if ($S->{offset}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | $sql .= " offset $S->{offset}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 279 | my $v = $S->{set_values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 279 | push @$v, @{$S->{ret_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 279 | push @$v, @{$S->{join_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 279 | push @$v, @{$S->{values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 279 | for my $add (@{$S->{additions}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 8 | $sql .= " $add->{type} $add->{sql}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 8 | push @$v, @{$add->{vals}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 279 | $sql =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 279 | ▶ | if ( $use_rownum && ( $S->{limit} || $S->{offset} )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$use_rownum and $S->{"limit"} || $S->{"offset"}
$S->{"limit"} or $S->{"offset"}
MC/DC0%0/3
$use_rownum and $S->{"limit"} || $S->{"offset"}
$use_rownum
$S->{"limit"}
$S->{"offset"}
Truth table50%2/4
A and B or C
A= $use_rownumB= $S->{"limit"}C= $S->{"offset"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 2 | my @p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | ▶ | push @p, "ROWNUM > " . $S->{offset} if $S->{offset}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 2 | ▶ | push @p, "ROWNUM <= " . ($S->{limit} + ($S->{offset} // 0)) if $S->{limit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$S->{"offset"} // 0
MC/DC100%1/1
$S->{"offset"} // 0
$S->{"offset"}
Truth table100%2/2
A
A= $S->{"offset"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | $sql = "select * from ($sql) where " . join(' and ', @p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 279 | return ($sql, $v, $nret, %flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||