SQLite/Introspect/ForeignKeys.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 39 / 39 CC 3 SCAR 6.2
CC
3
Cov
100%
fetch
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« SQLite/Introspect.pm ↑ Summary SQLite/JSON/Op.pm »
1 package DBIO::SQLite::Introspect::ForeignKeys;
2 # ABSTRACT: Introspect SQLite foreign keys
3  
4 252 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 252 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 252 our $VERSION = '0.900004';
8  
9 252 ▶use DBIO::Introspect::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 252 ▶use DBIO::SQLite::Util qw(quote_identifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13  
14 755 ▶sub fetch {
Subroutine fetch: called CC=3 SCAR=11.0
Pod documented
15 755 my ($class, $dbh, $tables) = @_;
16 755 my %fks;
17  
18 755 for my $table_name (sort keys %$tables) {
19 1459 my $list = $dbh->selectall_arrayref(
20 sprintf('PRAGMA foreign_key_list(%s)', quote_identifier($table_name)),
21 { Slice => {} },
22 );
23 1459 ▶ next unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 1199 260 1459
24  
25 260 my $groups = DBIO::Introspect::Base->_aggregate_by_ordered($list, 'id');
26 $fks{$table_name} = [ map {
27 260 my ($id, $rows) = @$_;
28 293 my $first = $rows->[0];
29 293 my @from = map { $_->{from} } sort { $a->{seq} <=> $b->{seq} } @$rows;
30 293 my @to = map { $_->{to} } sort { $a->{seq} <=> $b->{seq} } @$rows;
31 +{
32 fk_id => $id,
33 from_columns => \@from,
34 to_table => $first->{table},
35 to_columns => \@to,
36 on_update => $first->{on_update},
37 on_delete => $first->{on_delete},
38 match => $first->{match},
39 293 };
40 } @$groups ];
41 }
42  
43 755 return \%fks;
44 }
45  
46 252 1;
47  
48 __END__
« SQLite/Introspect.pm ↑ Summary SQLite/JSON/Op.pm »