| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package FusqlFS::Artifact::Table::Data; | ||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use FusqlFS::Version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = $FusqlFS::Version::VERSION; | |||||||||||||||||||||||||||
| 7 | 2 | ▶ | use parent 'FusqlFS::Artifact'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub init | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | $self->{query_cache} = {}; | |||||||||||||||||||||||||||
| 14 | 3 | $self->{field_quote} = '"'; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub list | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 0 | my ($table) = @_; | |||||||||||||||||||||||||||
| 21 | 0 | my @primary_key = $self->get_key_fields($table); | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | return undef unless @primary_key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | my $sth = $self->cexpr('SELECT %s FROM %s %s', $self->concat(@primary_key), $self->{field_quote}.$table.$self->{field_quote}, $self->limit); | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | return $self->all_col($sth)||[]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->all_col($sth) || []
MC/DC0%0/1
$self->all_col($sth) || []
$self->all_col($sth)
Truth table0%0/2
A
A= $self->all_col($sth)
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub where_clause | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
where_clause: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 0 | my ($table, $name) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | my @binds = $self->asplit($name); | |||||||||||||||||||||||||||
| 33 | 0 | my @primary_key = $self->get_key_fields($table); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return unless @primary_key && $#primary_key == $#binds; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@primary_key and $#primary_key == $#binds
MC/DC0%0/2
@primary_key and $#primary_key == $#binds
@primary_key
$#primary_key == $#binds
Truth table0%0/3
A and B
A= @primary_keyB= $#primary_key == $#binds
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return $self->pairs(' AND ', @primary_key), @binds; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item pairs | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Composes fields into pairs, suitable for UPDATE query or the like. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Input: $glue, @fields. | ||||||||||||||||||||||||||||
| 44 | Output: $sql_clause. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||
| 47 | sub pairs | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
pairs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my ($self, $glue, @fields) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | my $q = $self->{field_quote}; | |||||||||||||||||||||||||||
| 51 | 0 | return join($glue, map { "$q$_$q = ?" } @fields); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub get | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 0 | my ($table, $name) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | my ($where_clause, @binds) = $self->where_clause($table, $name); | |||||||||||||||||||||||||||
| 59 | 0 | my $qtable = $self->{field_quote}.$table.$self->{field_quote}; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | return unless $where_clause || @binds; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$where_clause or @binds
MC/DC0%0/2
$where_clause or @binds
$where_clause
@binds
Truth table0%0/3
A or B
A= $where_clauseB= @binds
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->{query_cache}->{$table} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"query_cache"}{$table} ||= {}
MC/DC0%0/1
$self->{"query_cache"}{$table} ||= {}
$self->{"query_cache"}{$table}
Truth table0%0/2
A
A= $self->{"query_cache"}{$table}
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $self->{query_cache}->{$table}->{$where_clause} ||= $where_clause? | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"query_cache"}{$table}{$where_clause} ||= $where_clause ? $self->expr("SELECT * FROM %s WHERE %s LIMIT 1", $qtable, $where_clause) : $self->expr("SELECT * FROM %s %s", $qtable, $self->limit)
MC/DC0%0/2
$self->{"query_cache"}{$table}{$where_clause} ||= $where_clause ? $self->expr("SELECT * FROM %s WHERE %s LIMIT 1", $qtable, $where_clause) : $self->expr("SELECT * FROM %s %s", $qtable, $self->limit)
$self->{"query_cache"}{$table}{$where_clause}
$where_clause ? $self->expr("SELECT * FROM %s WHERE %s LIMIT 1", $qtable, $where_clause) : $self->expr("SELECT * FROM %s %s", $qtable, $self->limit)
Truth table0%0/3
A ||= B
A= $self->{"query_cache"}{$table}{$where_clause}B= $where_clause ? $self->expr("SELECT * FROM %s WHERE %s LIMIT 1", $qtable, $where_clause) : $self->expr("SELECT * FROM %s %s", $qtable, $self->limit)
| |||||||||||||||||||||||||||||
| 64 | $self->expr('SELECT * FROM %s WHERE %s LIMIT 1', $qtable, $where_clause): | ||||||||||||||||||||||||||||
| 65 | $self->expr('SELECT * FROM %s %s', $qtable, $self->limit); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $sth = $self->{query_cache}->{$table}->{$where_clause}; | |||||||||||||||||||||||||||
| 68 | 0 | my $result = $self->all_row($sth, @binds); | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | return unless $result && @$result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$result and @$result
MC/DC0%0/2
$result and @$result
$result
@$result
Truth table0%0/3
A and B
A= $resultB= @$result
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $result = $result->[0] if scalar(@$result) == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | return $self->dump($result); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub drop | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my ($table, $name) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | my ($where_clause, @binds) = $self->where_clause($table, $name); | |||||||||||||||||||||||||||
| 80 | 0 | my $qtable = $self->{field_quote}.$table.$self->{field_quote}; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | return unless $where_clause; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | $self->cdo('DELETE FROM %s WHERE %s', [$qtable, $where_clause], @binds); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub store | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
store: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 0 | my ($table, $name, $data) = @_; | |||||||||||||||||||||||||||
| 90 | 0 | my ($where_clause, @binds) = $self->where_clause($table, $name); | |||||||||||||||||||||||||||
| 91 | 0 | my $qtable = $self->{field_quote}.$table.$self->{field_quote}; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | return unless $where_clause || @binds; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$where_clause or @binds
MC/DC0%0/2
$where_clause or @binds
$where_clause
@binds
Truth table0%0/3
A or B
A= $where_clauseB= @binds
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $data = $self->load($data); | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | return unless $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $template = $self->pairs(', ', keys %$data); | |||||||||||||||||||||||||||
| 98 | 0 | $self->cdo('UPDATE %s SET %s WHERE %s', [$qtable, $template, $where_clause], values %$data, @binds); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub create | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | 0 | my ($table, $name) = @_; | |||||||||||||||||||||||||||
| 105 | 0 | my @primary_key = $self->get_key_fields($table); | |||||||||||||||||||||||||||
| 106 | 0 | my $qtable = $self->{field_quote}.$table.$self->{field_quote}; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | return unless @primary_key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my $pholders = '?,' x scalar(@primary_key); | |||||||||||||||||||||||||||
| 110 | 0 | chop $pholders; | |||||||||||||||||||||||||||
| 111 | 0 | $self->cdo('INSERT INTO %s (%s) VALUES (%s)', [$qtable, join(', ', @primary_key), $pholders], $self->asplit($name)); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub rename | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | 0 | my ($table, $name, $newname) = @_; | |||||||||||||||||||||||||||
| 118 | 0 | my @primary_key = $self->get_key_fields($table); | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | return unless @primary_key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | my %data = map { shift(@primary_key) => $_ } $self->asplit($newname); | |||||||||||||||||||||||||||
| 122 | 0 | $self->store($table, $name, \%data); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub get_key_fields { | ||||||||||||||||||||||||||
|
Subroutine
get_key_fields: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my @fields = @{$FusqlFS::Artifact::instance->{namemap}->{$_[1]} || []}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$FusqlFS::Artifact::instance->{'namemap'}{$_[1]} || []
MC/DC0%0/1
$FusqlFS::Artifact::instance->{'namemap'}{$_[1]} || []
$FusqlFS::Artifact::instance->{'namemap'}{$_[1]}
Truth table0%0/2
A
A= $FusqlFS::Artifact::instance->{'namemap'}{$_[1]}
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | @fields = $_[0]->get_primary_key($_[1]) unless @fields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | return @fields; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub get_primary_key { } | ||||||||||||||||||||||||||
|
Subroutine
get_primary_key: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | 1; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||