| 1 | # $Id: Search.pm 82 2020-05-30 06:14:27Z stro $ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package CPAN::SQLite::DBI::Search; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | BEGIN { | ||||||||||||||||||||||||||||
| 9 | 7 | ▶ | our $VERSION = '0.218'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | $CPAN::SQLite::DBI::Search::info::VERSION = $VERSION; | |||||||||||||||||||||||||||
| 11 | 7 | $CPAN::SQLite::DBI::Search::mods::VERSION = $VERSION; | |||||||||||||||||||||||||||
| 12 | 7 | $CPAN::SQLite::DBI::Search::dists::VERSION = $VERSION; | |||||||||||||||||||||||||||
| 13 | 7 | $CPAN::SQLite::DBI::Search::auths::VERSION = $VERSION; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use parent 'CPAN::SQLite::DBI'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use CPAN::SQLite::DBI qw($tables $dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use CPAN::SQLite::Util qw($full_id); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | package CPAN::SQLite::DBI::Search::info; | ||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use parent 'CPAN::SQLite::DBI::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use CPAN::SQLite::DBI qw($dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | package CPAN::SQLite::DBI::Search::mods; | ||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use parent 'CPAN::SQLite::DBI::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use CPAN::SQLite::DBI qw($dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | package CPAN::SQLite::DBI::Search::dists; | ||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use parent 'CPAN::SQLite::DBI::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use CPAN::SQLite::DBI qw($dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | package CPAN::SQLite::DBI::Search::auths; | ||||||||||||||||||||||||||||
| 33 | 7 | ▶ | use parent 'CPAN::SQLite::DBI::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 7 | ▶ | use CPAN::SQLite::DBI qw($dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | package CPAN::SQLite::DBI::Search; | ||||||||||||||||||||||||||||
| 37 | 7 | ▶ | use parent 'CPAN::SQLite::DBI'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | use CPAN::SQLite::DBI qw($tables $dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 7 | ▶ | use CPAN::SQLite::Util qw($full_id download); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub fetch { | ||||||||||||||||||||||||||||
| 42 | 871 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=10 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 871 | my $fields = $args{fields}; | |||||||||||||||||||||||||||
| 44 | 871 | my $search = $args{search}; | |||||||||||||||||||||||||||
| 45 | 871 | ▶ | my @fields = ref($fields) eq 'ARRAY' ? @{$fields} : ($fields); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 871 | ▶ | my $sql = $self->sql_statement(%args) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $self->{error} = 'Error constructing sql statement: ' . $self->{error}; | |||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||
| 50 | 871 | ▶ | my $sth = $dbh->prepare($sql) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->db_error(); | |||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||
| 54 | 871 | ▶ | $sth->execute() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | $self->db_error($sth); | |||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 871 | ▶ | if (not $search->{wantarray}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 646 | my (%results, $results); | |||||||||||||||||||||||||||
| 61 | 646 | @results{@fields} = $sth->fetchrow_array; | |||||||||||||||||||||||||||
| 62 | 646 | ▶ | $results = ($sth->rows == 0) ? undef : \%results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 646 | $sth->finish; | |||||||||||||||||||||||||||
| 64 | 646 | undef $sth; | |||||||||||||||||||||||||||
| 65 | 646 | ▶ | $self->extra_info($results) if $results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 646 | return $results; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 225 | my (%hash, $results); | |||||||||||||||||||||||||||
| 69 | 225 | ▶ | while (@hash{@fields} = $sth->fetchrow_array) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2191 | my %tmp = %hash; | |||||||||||||||||||||||||||
| 71 | 2191 | $self->extra_info(\%tmp); | |||||||||||||||||||||||||||
| 72 | 2191 | push @{$results}, \%tmp; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 225 | ▶ | $results = undef if ($sth->rows == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 225 | $sth->finish; | |||||||||||||||||||||||||||
| 76 | 225 | undef $sth; | |||||||||||||||||||||||||||
| 77 | 225 | return $results; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub fetch_and_set { | ||||||||||||||||||||||||||||
| 82 | 3019 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_and_set: called CC=18 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 3019 | my $fields = $args{fields}; | |||||||||||||||||||||||||||
| 84 | 3019 | my $search = $args{search}; | |||||||||||||||||||||||||||
| 85 | 3019 | my $meta_obj = $args{meta_obj}; | |||||||||||||||||||||||||||
| 86 | 3019 | ▶ | die "Please supply a CPAN::SQLite::Meta::* object" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$meta_obj and ref($meta_obj) =~ /^CPAN::SQLite::META/
MC/DC0%0/2
$meta_obj and ref($meta_obj) =~ /^CPAN::SQLite::META/
$meta_obj
ref($meta_obj) =~ /^CPAN::SQLite::META/
Truth table33%1/3
A and B
A= $meta_objB= ref($meta_obj) =~ /^CPAN::SQLite::META/
| |||||||||||||||||||||||||||||
| 87 | unless ($meta_obj and ref($meta_obj) =~ /^CPAN::SQLite::META/); | ||||||||||||||||||||||||||||
| 88 | 3019 | ▶ | my @fields = ref($fields) eq 'ARRAY' ? @{$fields} : ($fields); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 3019 | ▶ | my $sql = $self->sql_statement(%args) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->{error} = 'Error constructing sql statement: ' . $self->{error}; | |||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||
| 92 | }; | ||||||||||||||||||||||||||||
| 93 | 3019 | ▶ | my $sth = $dbh->prepare($sql) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $self->db_error(); | |||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||
| 97 | 3019 | ▶ | $sth->execute() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | $self->db_error($sth); | |||||||||||||||||||||||||||
| 99 | 0 | return; | |||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3019 | my $want_ids = $args{want_ids}; | |||||||||||||||||||||||||||
| 103 | 3019 | my $set_list = $args{set_list}; | |||||||||||||||||||||||||||
| 104 | 3019 | my $download = $args{download}; | |||||||||||||||||||||||||||
| 105 | 3019 | ▶ | if (not $search->{wantarray}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 352 | my (%results, %meta_results, $results); | |||||||||||||||||||||||||||
| 107 | 352 | @results{@fields} = $sth->fetchrow_array; | |||||||||||||||||||||||||||
| 108 | 352 | ▶ | $results = ($sth->rows == 0) ? undef : \%results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 352 | $sth->finish; | |||||||||||||||||||||||||||
| 110 | 352 | undef $sth; | |||||||||||||||||||||||||||
| 111 | 352 | ▶ | return unless $results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 352 | $self->extra_info($results); | |||||||||||||||||||||||||||
| 113 | 352 | $meta_obj->set_data($results); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 352 | ▶ | if ($want_ids) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 6 | $meta_results{dist_id} = $results{dist_id}; | |||||||||||||||||||||||||||
| 117 | 6 | $meta_results{download} = download($results{cpanid}, $results{dist_file}); | |||||||||||||||||||||||||||
| 118 | 6 | return \%meta_results; | |||||||||||||||||||||||||||
| 119 | } else { | ||||||||||||||||||||||||||||
| 120 | 346 | return 1; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | 2667 | my (%hash, $meta_results); | |||||||||||||||||||||||||||
| 124 | 2667 | ▶ | while (@hash{@fields} = $sth->fetchrow_array) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 95126 | my %tmp = %hash; | |||||||||||||||||||||||||||
| 126 | 95126 | ▶ | if ($set_list) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 76311 | push @{$meta_results}, \%tmp; | |||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||
| 129 | 18815 | $self->extra_info(\%tmp); | |||||||||||||||||||||||||||
| 130 | 18815 | $meta_obj->set_data(\%tmp); | |||||||||||||||||||||||||||
| 131 | 18815 | ▶ | if ($want_ids) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 13960 | my $download = download($tmp{cpanid}, $tmp{dist_file}); | |||||||||||||||||||||||||||
| 133 | 13960 | push @{$meta_results}, | |||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | dist_id => $tmp{dist_id}, | ||||||||||||||||||||||||||||
| 136 | 13960 | download => $download | |||||||||||||||||||||||||||
| 137 | }; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 2667 | ▶ | $meta_results = undef if ($sth->rows == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 2667 | $sth->finish; | |||||||||||||||||||||||||||
| 144 | 2667 | undef $sth; | |||||||||||||||||||||||||||
| 145 | 2667 | ▶ | return unless $meta_results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 2665 | ▶ | $meta_obj->set_list_data($meta_results, $download) if $set_list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 2665 | ▶ | return $want_ids ? $meta_results : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub extra_info { | ||||||||||||||||||||||||||||
| 152 | 21998 | ▶ | my ($self, $results) = @_; | ||||||||||||||||||||||||||
|
Subroutine
extra_info: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 21998 | ▶ | if ($results->{cpanid} and $results->{dist_file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$results->{"cpanid"} and $results->{"dist_file"}
MC/DC100%2/2
$results->{"cpanid"} and $results->{"dist_file"}
$results->{"cpanid"}
$results->{"dist_file"}
Truth table100%3/3
A and B
A= $results->{"cpanid"}B= $results->{"dist_file"}
| |||||||||||||||||||||||||||||
| 154 | 15313 | $results->{download} = download($results->{cpanid}, $results->{dist_file}); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 21998 | return; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | sub sql_statement { | ||||||||||||||||||||||||||||
| 160 | 3890 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sql_statement: called CC=29 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 3890 | my $search = $args{search}; | |||||||||||||||||||||||||||
| 163 | 3890 | ▶ | my $distinct = $search->{distinct} ? 'DISTINCT' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 3890 | my $table = $args{table}; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 3890 | my $fields = $args{fields}; | |||||||||||||||||||||||||||
| 167 | 3890 | ▶ | my @fields = ref($fields) eq 'ARRAY' ? @{$fields} : ($fields); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 3890 | for (@fields) { | |||||||||||||||||||||||||||
| 169 | 15340 | ▶ | $_ = $full_id->{$_} if $full_id->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3890 | my $sql = qq{SELECT $distinct } . join(',', @fields); | |||||||||||||||||||||||||||
| 173 | 3890 | my $where = ''; | |||||||||||||||||||||||||||
| 174 | 3890 | my $type = $search->{type}; | |||||||||||||||||||||||||||
| 175 | QUERY: { | ||||||||||||||||||||||||||||
| 176 | 3890 | ▶ | ($type eq 'query') and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 20 | my $value = $search->{value}; | |||||||||||||||||||||||||||
| 178 | 20 | ▶ | last QUERY if ($value eq '^'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 20 | my $name = $search->{name}; | |||||||||||||||||||||||||||
| 180 | 20 | my $text = $search->{text}; | |||||||||||||||||||||||||||
| 181 | 20 | ▶ | my $use_like = ($value =~ /^\^?[A-Za-z0-9_\\\:\-]+$/) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 20 | my $prepend = '%'; | |||||||||||||||||||||||||||
| 183 | 20 | ▶ | if ($use_like and $value =~ /^\^/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$use_like and $value =~ /^\^/
MC/DC100%2/2
$use_like and $value =~ /^\^/
$use_like
$value =~ /^\^/
Truth table100%3/3
A and B
A= $use_likeB= $value =~ /^\^/
| |||||||||||||||||||||||||||||
| 184 | 2 | $prepend = ''; | |||||||||||||||||||||||||||
| 185 | 2 | $value =~ s/^\^//; | |||||||||||||||||||||||||||
| 186 | 2 | $value =~ s{\\}{}g; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | $where = | ||||||||||||||||||||||||||||
| 189 | 20 | ▶ | $use_like | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | ? qq{$name LIKE '$prepend$value%'} | ||||||||||||||||||||||||||||
| 191 | : qq{$name REGEXP '(?i:$value)'}; | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 20 | ▶ | if ($name eq 'cpanid') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 6 | ▶ | $where .= | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | $use_like | ||||||||||||||||||||||||||||
| 196 | ? qq{ OR $text LIKE '$prepend$value%'} | ||||||||||||||||||||||||||||
| 197 | : qq{ OR $text REGEXP '(?i:$value)'}; | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 20 | last QUERY; | |||||||||||||||||||||||||||
| 200 | }; | ||||||||||||||||||||||||||||
| 201 | 3870 | ▶ | ($type eq 'id') and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 2872 | $where = qq{ $search->{id} = $search->{value} }; | |||||||||||||||||||||||||||
| 203 | 2872 | last QUERY; | |||||||||||||||||||||||||||
| 204 | }; | ||||||||||||||||||||||||||||
| 205 | 998 | ▶ | ($type eq 'name') and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 998 | $where = qq{ $search->{name} = '$search->{value}' }; | |||||||||||||||||||||||||||
| 207 | 998 | last QUERY; | |||||||||||||||||||||||||||
| 208 | }; | ||||||||||||||||||||||||||||
| 209 | 0 | warn qq{Unknown query type}; | |||||||||||||||||||||||||||
| 210 | 0 | return; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 3890 | my $join; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 3890 | $sql .= ' FROM ' . $table; | |||||||||||||||||||||||||||
| 215 | 3890 | ▶ | my $left_join = $args{join} || $args{left_join}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{'join'} || $args{'left_join'}
MC/DC50%1/2
$args{'join'} || $args{'left_join'}
$args{'join'}
$args{'left_join'}
Truth table66%2/3
A || B
A= $args{'join'}B= $args{'left_join'}
| |||||||||||||||||||||||||||||
| 216 | 3890 | ▶ | if ($left_join) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 660 | ▶ | if (ref($left_join) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 660 | foreach my $key (keys %$left_join) { | |||||||||||||||||||||||||||
| 219 | 1216 | my $id = $left_join->{$key}; | |||||||||||||||||||||||||||
| 220 | 1216 | $sql .= " LEFT JOIN $key ON $table.$id=$key.$id "; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 3890 | ▶ | if ($where) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 3890 | $sql .= ' WHERE ( ' . $where . ' )'; | |||||||||||||||||||||||||||
| 227 | 3890 | ▶ | $sql .= ' AND (' . $join . ')' if $join; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | } else { | ||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $sql .= ' WHERE (' . $join . ')' if $join; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 3890 | my $order_by = ''; | |||||||||||||||||||||||||||
| 233 | 3890 | ▶ | if (my $user_order_by = $args{order_by}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 3890 | ▶ | $order_by = $order_by ? "$order_by,$user_order_by" : $user_order_by; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 3890 | ▶ | if ($order_by and $where) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$order_by and $where
MC/DC0%0/2
$order_by and $where
$order_by
$where
Truth table33%1/3
A and B
A= $order_byB= $where
| |||||||||||||||||||||||||||||
| 237 | 3890 | $sql .= qq{ ORDER BY $order_by }; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 3890 | ▶ | if (my $limit = $args{limit}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | my ($min, $max) = | ||||||||||||||||||||||||||||
| 242 | ref($limit) eq 'HASH' | ||||||||||||||||||||||||||||
| 243 | ? ($limit->{min} || 0, $limit->{max}) | ||||||||||||||||||||||||||||
| 244 | 0 | ▶ | : (0, $limit); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$limit->{"min"} or 0
MC/DC0%0/1
$limit->{"min"} or 0
$limit->{"min"}
Truth table0%0/2
A
A= $limit->{"min"}
| |||||||||||||||||||||||||||||
| 245 | 0 | $sql .= qq{ LIMIT $min,$max }; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 3890 | return $sql; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 7 | 1; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =head1 NAME | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | CPAN::SQLite::DBI::Search - DBI information for searching the CPAN::SQLite database | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head1 VERSION | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | version 0.218 | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | This module provides methods for L<CPAN::SQLite::Search> for searching | ||||||||||||||||||||||||||||
| 263 | the C<CPAN::SQLite> database. There are two main methods. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =over | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =item C<fetch> | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | This takes information from C<CPAN::SQLite::Search> and sets up | ||||||||||||||||||||||||||||
| 270 | a query on the database, returning the results found. | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =item C<sql_statement> | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | This is used by the C<fetch> method to construct the appropriate | ||||||||||||||||||||||||||||
| 275 | SQL statement. | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =back | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | L<CPAN::SQLite::Search> | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =cut | ||||||||||||||||||||||||||||