| 1 | package Alzabo::Runtime::Schema; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Alzabo::Exceptions ( abbr => [ qw( logic_exception params_exception ) ] ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Alzabo::Runtime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Alzabo::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Params::Validate qw( :all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | Params::Validate::validation_options( on_fail => sub { params_exception join '', @_ } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use base qw(Alzabo::Schema); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 11 | $VERSION = 2.0; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 11 | 1; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub load_from_file | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
load_from_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $self = $class->_load_from_file(@_); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | $self->prefetch_all_but_blobs; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | return $self; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub _schema_file_type | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_schema_file_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | return 'runtime'; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub user | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return $self->{user}; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub password | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | return $self->{password}; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub host | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | return $self->{host}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub port | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
port: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $self->{port}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub referential_integrity | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
referential_integrity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return defined $self->{maintain_integrity} ? $self->{maintain_integrity} : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub set_db_schema_name | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_db_schema_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $self->{db_schema_name} = shift; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub set_user | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $self->{user} = shift; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub set_password | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $self->{password} = shift; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub set_host | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | $self->{host} = shift; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub set_port | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_port: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | $self->{port} = shift; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub set_referential_integrity | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_referential_integrity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 108 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{maintain_integrity} = $val if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub set_quote_identifiers | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_quote_identifiers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $self->{quote_identifiers} = $val if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub connect | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my %p; | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | $p{user} = $self->user if defined $self->user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $p{password} = $self->password if defined $self->password; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $p{host} = $self->host if defined $self->host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $p{port} = $self->port if defined $self->port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $self->driver->connect( %p, @_ ); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # $self->set_referential_integrity( ! $self->driver->supports_referential_integrity ); | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub disconnect | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $self->driver->disconnect; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub one_row | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
one_row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | # could be replaced with something potentially more efficient | ||||||||||||||||||||||||||||
| 145 | 0 | return shift->join(@_)->next; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 11 | ▶ | use constant JOIN_SPEC => { join => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 149 | optional => 1 }, | ||||||||||||||||||||||||||||
| 150 | tables => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||||
| 151 | optional => 1 }, | ||||||||||||||||||||||||||||
| 152 | select => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||||
| 153 | optional => 1 }, | ||||||||||||||||||||||||||||
| 154 | where => { type => ARRAYREF, | ||||||||||||||||||||||||||||
| 155 | optional => 1 }, | ||||||||||||||||||||||||||||
| 156 | order_by => { type => ARRAYREF | HASHREF | OBJECT, | ||||||||||||||||||||||||||||
| 157 | optional => 1 }, | ||||||||||||||||||||||||||||
| 158 | limit => { type => SCALAR | ARRAYREF, | ||||||||||||||||||||||||||||
| 159 | optional => 1 }, | ||||||||||||||||||||||||||||
| 160 | distinct => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||||
| 161 | optional => 1 }, | ||||||||||||||||||||||||||||
| 162 | quote_identifiers => { type => BOOLEAN, | ||||||||||||||||||||||||||||
| 163 | optional => 1 }, | ||||||||||||||||||||||||||||
| 164 | 11 | }; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | sub join | ||||||||||||||||||||||||||||
| 167 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
join: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 169 | 0 | my %p = validate( @_, JOIN_SPEC ); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $p{join} ||= delete $p{tables}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$p{"join"} ||= delete $p{"tables"}
MC/DC0%0/2
$p{"join"} ||= delete $p{"tables"}
$p{"join"}
delete $p{"tables"}
Truth table0%0/3
A ||= B
A= $p{"join"}B= delete $p{"tables"}
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $p{join} = [ $p{join} ] unless Alzabo::Utils::is_arrayref( $p{join} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my @tables; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ( Alzabo::Utils::is_arrayref( $p{join}->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||
| 178 | # flattens the nested structure and produces a unique set of | ||||||||||||||||||||||||||||
| 179 | # tables | ||||||||||||||||||||||||||||
| 180 | 0 | @tables = values %{ { map { $_ => $_ } | |||||||||||||||||||||||||||
| 181 | 0 | grep { Alzabo::Utils::safe_isa( $_, 'Alzabo::Table' ) } | |||||||||||||||||||||||||||
| 182 | 0 | map { @$_ } @{ $p{join} } } }; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | else | ||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||
| 186 | 0 | @tables = grep { Alzabo::Utils::safe_isa($_, 'Alzabo::Table') } @{ $p{join} }; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( $p{distinct} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||
| 191 | $p{distinct} = | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | Alzabo::Utils::is_arrayref( $p{distinct} ) ? $p{distinct} : [ $p{distinct} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( $p{order_by} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||
| 197 | $p{order_by} = | ||||||||||||||||||||||||||||
| 198 | Alzabo::Utils::is_arrayref( $p{order_by} ) | ||||||||||||||||||||||||||||
| 199 | ? $p{order_by} | ||||||||||||||||||||||||||||
| 200 | : $p{order_by} | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | ? [ $p{order_by} ] | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 202 | : undef; | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # We go in this order: $p{select}, $p{distinct}, @tables | ||||||||||||||||||||||||||||
| 206 | my @select_tables = ( $p{select} ? | ||||||||||||||||||||||||||||
| 207 | ( Alzabo::Utils::is_arrayref( $p{select} ) ? | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | @{ $p{select} } : $p{select} ) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | $p{distinct} ? | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | @{ $p{distinct} } : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 211 | @tables ); | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | my $sql = Alzabo::Runtime::sqlmaker( $self, \%p ); | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | my @select_cols; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ( $p{distinct} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||
| 218 | 0 | my %distinct = map { $_ => 1 } @{ $p{distinct} }; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # hack so distinct is not treated as a function, just a | ||||||||||||||||||||||||||||
| 221 | # bareword in the SQL | ||||||||||||||||||||||||||||
| 222 | @select_cols = ( 'DISTINCT', | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | map { ( $_->primary_key, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | $_->prefetch ? | ||||||||||||||||||||||||||||
| 225 | $_->columns( $_->prefetch ) : | ||||||||||||||||||||||||||||
| 226 | () ) } | ||||||||||||||||||||||||||||
| 227 | 0 | @{ $p{distinct} } | |||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | foreach my $t (@select_tables) | |||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | next if $distinct{$t}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | push @select_cols, $t->primary_key; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | push @select_cols, $t->columns( $t->prefetch ) if $t->prefetch; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( $p{order_by} && $sql->distinct_requires_order_by_in_select ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p{"order_by"} and $sql->distinct_requires_order_by_in_select
MC/DC0%0/2
$p{"order_by"} and $sql->distinct_requires_order_by_in_select
$p{"order_by"}
$sql->distinct_requires_order_by_in_select
Truth table0%0/3
A and B
A= $p{"order_by"}B= $sql->distinct_requires_order_by_in_select
| |||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 0 | my %select_cols = map { $_ => 1 } @select_cols; | |||||||||||||||||||||||||||
| 241 | 0 | push @select_cols, grep { ref } @{ $p{order_by} }; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | @select_tables = ( @{ $p{distinct} }, grep { ! $distinct{$_} } @select_tables ); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | else | ||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||
| 248 | @select_cols = | ||||||||||||||||||||||||||||
| 249 | 0 | ▶ | ( map { ( $_->primary_key, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | $_->prefetch ? | ||||||||||||||||||||||||||||
| 251 | $_->columns( $_->prefetch ) : | ||||||||||||||||||||||||||||
| 252 | () ) } | ||||||||||||||||||||||||||||
| 253 | @select_tables ); | ||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | $sql->select(@select_cols); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | $self->_join_all_tables( sql => $sql, | ||||||||||||||||||||||||||||
| 259 | 0 | join => $p{join} ); | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | ▶ | Alzabo::Runtime::process_where_clause( $sql, $p{where} ) if exists $p{where}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Alzabo::Runtime::process_order_by_clause( $sql, $p{order_by} ) | ||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if $p{order_by}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $sql->limit( ref $p{limit} ? @{ $p{limit} } : $p{limit} ) if $p{limit}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $sql->debug(\*STDERR) if Alzabo::Debug::SQL; | |||||||||||||||||||||||||||
| 269 | 0 | print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | my $statement = $self->driver->statement( sql => $sql->sql, | |||||||||||||||||||||||||||
| 272 | bind => $sql->bind ); | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if (@select_tables == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||
| 276 | 0 | return Alzabo::Runtime::RowCursor->new | |||||||||||||||||||||||||||
| 277 | ( statement => $statement, | ||||||||||||||||||||||||||||
| 278 | table => $select_tables[0]->real_table, | ||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | else | ||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | return Alzabo::Runtime::JoinCursor->new | ||||||||||||||||||||||||||||
| 284 | ( statement => $statement, | ||||||||||||||||||||||||||||
| 285 | 0 | tables => [ map { $_->real_table } @select_tables ], | |||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | sub row_count | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
row_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 292 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 293 | 0 | my %p = @_; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | return $self->function( select => Alzabo::Runtime::sqlmaker( $self, \%p )->COUNT('*'), | |||||||||||||||||||||||||||
| 296 | %p, | ||||||||||||||||||||||||||||
| 297 | ); | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | sub function | ||||||||||||||||||||||||||||
| 301 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
function: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 302 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 303 | 0 | my %p = @_; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | my $sql = $self->_select_sql(%p); | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $method = | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | Alzabo::Utils::is_arrayref( $p{select} ) && @{ $p{select} } > 1 ? 'rows' : 'column'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Alzabo::Utils::is_arrayref($p{"select"}) and @{$p{"select"};} > 1
MC/DC0%0/2
Alzabo::Utils::is_arrayref($p{"select"}) and @{$p{"select"};} > 1
Alzabo::Utils::is_arrayref($p{"select"})
@{$p{"select"};} > 1
Truth table0%0/3
A and B
A= Alzabo::Utils::is_arrayref($p{"select"})B= @{$p{"select"};} > 1
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | $sql->debug(\*STDERR) if Alzabo::Debug::SQL; | |||||||||||||||||||||||||||
| 311 | 0 | print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE; | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | return $self->driver->$method( sql => $sql->sql, | |||||||||||||||||||||||||||
| 314 | bind => $sql->bind ); | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | sub select | ||||||||||||||||||||||||||||
| 318 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
select: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 319 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | my $sql = $self->_select_sql(@_); | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | $sql->debug(\*STDERR) if Alzabo::Debug::SQL; | |||||||||||||||||||||||||||
| 324 | 0 | print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | return $self->driver->statement( sql => $sql->sql, | |||||||||||||||||||||||||||
| 327 | bind => $sql->bind ); | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 11 | ▶ | use constant _SELECT_SQL_SPEC => { join => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 331 | optional => 1 }, | ||||||||||||||||||||||||||||
| 332 | tables => { type => ARRAYREF | OBJECT, | ||||||||||||||||||||||||||||
| 333 | optional => 1 }, | ||||||||||||||||||||||||||||
| 334 | select => { type => SCALAR | ARRAYREF | OBJECT, | ||||||||||||||||||||||||||||
| 335 | optional => 1 }, | ||||||||||||||||||||||||||||
| 336 | where => { type => ARRAYREF, | ||||||||||||||||||||||||||||
| 337 | optional => 1 }, | ||||||||||||||||||||||||||||
| 338 | group_by => { type => ARRAYREF | HASHREF | OBJECT, | ||||||||||||||||||||||||||||
| 339 | optional => 1 }, | ||||||||||||||||||||||||||||
| 340 | order_by => { type => ARRAYREF | HASHREF | OBJECT, | ||||||||||||||||||||||||||||
| 341 | optional => 1 }, | ||||||||||||||||||||||||||||
| 342 | having => { type => ARRAYREF, | ||||||||||||||||||||||||||||
| 343 | optional => 1 }, | ||||||||||||||||||||||||||||
| 344 | limit => { type => SCALAR | ARRAYREF, | ||||||||||||||||||||||||||||
| 345 | optional => 1 }, | ||||||||||||||||||||||||||||
| 346 | quote_identifiers => { type => BOOLEAN, | ||||||||||||||||||||||||||||
| 347 | optional => 1 }, | ||||||||||||||||||||||||||||
| 348 | 11 | }; | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | sub _select_sql | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_select_sql: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 352 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 353 | 0 | my %p = validate( @_, _SELECT_SQL_SPEC ); | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | $p{join} ||= delete $p{tables}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$p{"join"} ||= delete $p{"tables"}
MC/DC0%0/2
$p{"join"} ||= delete $p{"tables"}
$p{"join"}
delete $p{"tables"}
Truth table0%0/3
A ||= B
A= $p{"join"}B= delete $p{"tables"}
| |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $p{join} = [ $p{join} ] unless Alzabo::Utils::is_arrayref( $p{join} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | my @tables; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ( Alzabo::Utils::is_arrayref( $p{join}->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||
| 362 | # flattens the nested structure and produces a unique set of | ||||||||||||||||||||||||||||
| 363 | # tables | ||||||||||||||||||||||||||||
| 364 | 0 | @tables = values %{ { map { $_ => $_ } | |||||||||||||||||||||||||||
| 365 | 0 | grep { Alzabo::Utils::safe_isa( 'Alzabo::Table', $_ ) } | |||||||||||||||||||||||||||
| 366 | 0 | map { @$_ } @{ $p{join} } } }; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | else | ||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||
| 370 | 0 | @tables = grep { Alzabo::Utils::safe_isa( 'Alzabo::Table', $_ ) } @{ $p{join} }; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | my @funcs = Alzabo::Utils::is_arrayref( $p{select} ) ? @{ $p{select} } : $p{select}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | my $sql = ( Alzabo::Runtime::sqlmaker( $self, \%p )-> | |||||||||||||||||||||||||||
| 376 | select(@funcs) ); | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | $self->_join_all_tables( sql => $sql, | ||||||||||||||||||||||||||||
| 379 | 0 | join => $p{join} ); | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | Alzabo::Runtime::process_where_clause( $sql, $p{where} ) | ||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if exists $p{where}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | Alzabo::Runtime::process_group_by_clause( $sql, $p{group_by} ) | ||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if exists $p{group_by}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | Alzabo::Runtime::process_having_clause( $sql, $p{having} ) | ||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if exists $p{having}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | Alzabo::Runtime::process_order_by_clause( $sql, $p{order_by} ) | ||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if exists $p{order_by}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | ▶ | $sql->limit( ref $p{limit} ? @{ $p{limit} } : $p{limit} ) if $p{limit}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | return $sql; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 11 | ▶ | use constant _JOIN_ALL_TABLES_SPEC => { join => { type => ARRAYREF }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 399 | 11 | sql => { isa => 'Alzabo::SQLMaker' } }; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | sub _join_all_tables | ||||||||||||||||||||||||||||
| 402 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_join_all_tables: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 403 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 404 | 0 | my %p = validate( @_, _JOIN_ALL_TABLES_SPEC ); | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | my @from; | |||||||||||||||||||||||||||
| 407 | my @joins; | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # outer join given as only join | ||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $p{join} = [ $p{join} ] unless ref $p{join}->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | # A structure like: | ||||||||||||||||||||||||||||
| 413 | # | ||||||||||||||||||||||||||||
| 414 | # [ [ $t_1 => $t_2 ], | ||||||||||||||||||||||||||||
| 415 | # [ $t_1 => $t_3, $fk ], | ||||||||||||||||||||||||||||
| 416 | # [ left_outer_join => $t_3 => $t_4 ], | ||||||||||||||||||||||||||||
| 417 | # [ left_outer_join => $t_3 => $t_5, undef, [ $where_clause ] ] | ||||||||||||||||||||||||||||
| 418 | # | ||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ( Alzabo::Utils::is_arrayref( $p{join}->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||
| 421 | 0 | my %map; | |||||||||||||||||||||||||||
| 422 | my %tables; | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | foreach my $set ( @{ $p{join} } ) | |||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||
| 426 | # we take some care not to change the contents of $set, | ||||||||||||||||||||||||||||
| 427 | # because the caller may reuse the variable being | ||||||||||||||||||||||||||||
| 428 | # referenced, and changes here could break that. | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | # XXX - improve | ||||||||||||||||||||||||||||
| 431 | 0 | ▶ | params_exception | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 'The table map must contain only two tables per array reference' | ||||||||||||||||||||||||||||
| 433 | if @$set > 5; | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 0 | my @tables; | |||||||||||||||||||||||||||
| 436 | 0 | ▶ | if ( ! ref $set->[0] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||
| 438 | 0 | ▶ | $set->[0] =~ /^(right|left|full)_outer_join$/i | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | or params_exception "Invalid join type: $set->[0]"; | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 0 | @tables = @$set[1,2]; | |||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | push @from, [ $1, @tables, @$set[3, 4] ]; | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | else | ||||||||||||||||||||||||||||
| 446 | { | ||||||||||||||||||||||||||||
| 447 | 0 | @tables = @$set[0,1]; | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 0 | push @from, grep { ! exists $tables{ $_->alias_name } } @tables; | |||||||||||||||||||||||||||
| 450 | 0 | push @joins, [ @tables, $set->[2] ]; | |||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # Track the tables we've seen | ||||||||||||||||||||||||||||
| 454 | 0 | @tables{ $tables[0]->alias_name, $tables[1]->alias_name } = (1, 1); | |||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | # Track their relationships | ||||||||||||||||||||||||||||
| 457 | 0 | push @{ $map{ $tables[0]->alias_name } }, $tables[1]->alias_name; | |||||||||||||||||||||||||||
| 458 | 0 | push @{ $map{ $tables[1]->alias_name } }, $tables[0]->alias_name; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | # just get one key to start with | ||||||||||||||||||||||||||||
| 462 | 0 | my ($key) = (each %tables)[0]; | |||||||||||||||||||||||||||
| 463 | 0 | delete $tables{$key}; | |||||||||||||||||||||||||||
| 464 | 0 | my @t = @{ delete $map{$key} }; | |||||||||||||||||||||||||||
| 465 | 0 | ▶ | while (my $t = shift @t) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | { | ||||||||||||||||||||||||||||
| 467 | 0 | delete $tables{$t}; | |||||||||||||||||||||||||||
| 468 | 0 | ▶ | push @t, @{ delete $map{$t} } if $map{$t}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | logic_exception | ||||||||||||||||||||||||||||
| 472 | 0 | ▶ | "The specified table parameter does not connect all the tables involved in the join" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | if keys %tables; | ||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | # A structure like: | ||||||||||||||||||||||||||||
| 476 | # | ||||||||||||||||||||||||||||
| 477 | # [ $t_1 => $t_2 => $t_3 => $t_4 ] | ||||||||||||||||||||||||||||
| 478 | # | ||||||||||||||||||||||||||||
| 479 | else | ||||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||
| 481 | 0 | ▶ | for (my $x = 0; $x < @{ $p{join} } - 1; $x++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | { | ||||||||||||||||||||||||||||
| 483 | 0 | push @joins, [ $p{join}->[$x], $p{join}->[$x + 1] ]; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 0 | @from = @{ $p{join} }; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 0 | $p{sql}->from(@from); | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return unless @joins; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 0 | foreach my $join (@joins) | |||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||
| 495 | 0 | $self->_join_two_tables( $p{sql}, @$join ); | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 0 | $p{sql}->subgroup_end; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | sub _join_two_tables | ||||||||||||||||||||||||||||
| 502 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_join_two_tables: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 503 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 504 | 0 | my ($sql, $table_1, $table_2, $fk) = @_; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 0 | ▶ | my $op = $sql->last_op eq 'and' || $sql->last_op eq 'condition' ? 'and' : 'where'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sql->last_op eq "and" or $sql->last_op eq "condition"
MC/DC0%0/2
$sql->last_op eq "and" or $sql->last_op eq "condition"
$sql->last_op eq "and"
$sql->last_op eq "condition"
Truth table0%0/3
A or B
A= $sql->last_op eq "and"B= $sql->last_op eq "condition"
| |||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 0 | ▶ | if ($fk) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||
| 510 | 0 | ▶ | unless ( $fk->table_from eq $table_1 && $fk->table_to eq $table_2 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fk->table_from eq $table_1 and $fk->table_to eq $table_2
MC/DC0%0/2
$fk->table_from eq $table_1 and $fk->table_to eq $table_2
$fk->table_from eq $table_1
$fk->table_to eq $table_2
Truth table0%0/3
A and B
A= $fk->table_from eq $table_1B= $fk->table_to eq $table_2
| |||||||||||||||||||||||||||||
| 511 | { | ||||||||||||||||||||||||||||
| 512 | 0 | ▶ | if ( $fk->table_from eq $table_2 && $fk->table_to eq $table_1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fk->table_from eq $table_2 and $fk->table_to eq $table_1
MC/DC0%0/2
$fk->table_from eq $table_2 and $fk->table_to eq $table_1
$fk->table_from eq $table_2
$fk->table_to eq $table_1
Truth table0%0/3
A and B
A= $fk->table_from eq $table_2B= $fk->table_to eq $table_1
| |||||||||||||||||||||||||||||
| 513 | { | ||||||||||||||||||||||||||||
| 514 | 0 | $fk = $fk->reverse; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | else | ||||||||||||||||||||||||||||
| 517 | { | ||||||||||||||||||||||||||||
| 518 | 0 | params_exception | |||||||||||||||||||||||||||
| 519 | ( "The foreign key given to join together " . | ||||||||||||||||||||||||||||
| 520 | $table_1->alias_name . | ||||||||||||||||||||||||||||
| 521 | " and " . $table_2->alias_name . | ||||||||||||||||||||||||||||
| 522 | " does not represent a relationship between those two tables" ); | ||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | else | ||||||||||||||||||||||||||||
| 527 | { | ||||||||||||||||||||||||||||
| 528 | 0 | my @fk = $table_1->foreign_keys_by_table($table_2); | |||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | ▶ | logic_exception | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | ( "The " . $table_1->name . | ||||||||||||||||||||||||||||
| 532 | " table has no foreign keys to the " . | ||||||||||||||||||||||||||||
| 533 | $table_2->name . " table" ) | ||||||||||||||||||||||||||||
| 534 | unless @fk; | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 0 | ▶ | logic_exception | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 537 | ( "The " . $table_1->name . | ||||||||||||||||||||||||||||
| 538 | " table has more than 1 foreign key to the " . | ||||||||||||||||||||||||||||
| 539 | $table_2->name . " table" ) | ||||||||||||||||||||||||||||
| 540 | if @fk > 1; | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 0 | $fk = $fk[0]; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 0 | foreach my $cp ( $fk->column_pair_names ) | |||||||||||||||||||||||||||
| 546 | { | ||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if ( $op eq 'where' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 548 | { | ||||||||||||||||||||||||||||
| 549 | # first time through loop only | ||||||||||||||||||||||||||||
| 550 | 0 | $sql->where; | |||||||||||||||||||||||||||
| 551 | 0 | $sql->subgroup_start; | |||||||||||||||||||||||||||
| 552 | 0 | $sql->condition( $table_1->column( $cp->[0] ), '=', $table_2->column( $cp->[1] ) ); | |||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | else | ||||||||||||||||||||||||||||
| 555 | { | ||||||||||||||||||||||||||||
| 556 | 0 | $sql->$op( $table_1->column( $cp->[0] ), '=', $table_2->column( $cp->[1] ) ); | |||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | 0 | $op = 'and'; | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | sub prefetch_all | ||||||||||||||||||||||||||||
| 563 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prefetch_all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 564 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | 0 | $_->set_prefetch( $_->columns ) for $self->tables; | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | sub prefetch_all_but_blobs | ||||||||||||||||||||||||||||
| 570 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prefetch_all_but_blobs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 571 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | $_->set_prefetch( grep { ! $_->is_blob } $_->columns ) for $self->tables; | |||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | sub prefetch_none | ||||||||||||||||||||||||||||
| 577 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prefetch_none: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 578 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 0 | $_->set_prefetch() for $self->tables; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | __END__ | ||||||||||||||||||||||||||||