| 1 | package DBIO::SQLite::Introspect::ForeignKeys; | ||||||||||
| 2 | # ABSTRACT: Introspect SQLite foreign keys | ||||||||||
| 3 | |||||||||||
| 4 | 193 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 193 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 193 | our $VERSION = '0.900007'; | |||||||||
| 8 | |||||||||||
| 9 | 193 | ▶ | use DBIO::Introspect::Base (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 193 | ▶ | use DBIO::SQLite::Util qw(quote_identifier selectall_hashrefs); | ||||||||
|
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 = selectall_hashrefs($dbh, | |||||||||
| 20 | sprintf('PRAGMA foreign_key_list(%s)', quote_identifier($table_name))); | ||||||||||
| 21 | 1459 | ▶ | next unless @$list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 260 | my $groups = DBIO::Introspect::Base->_aggregate_by_ordered($list, 'id'); | |||||||||
| 24 | $fks{$table_name} = [ map { | ||||||||||
| 25 | 260 | my ($id, $rows) = @$_; | |||||||||
| 26 | 293 | my $first = $rows->[0]; | |||||||||
| 27 | 293 | my @from = map { $_->{from} } sort { $a->{seq} <=> $b->{seq} } @$rows; | |||||||||
| 28 | 293 | my @to = map { $_->{to} } sort { $a->{seq} <=> $b->{seq} } @$rows; | |||||||||
| 29 | +{ | ||||||||||
| 30 | fk_id => $id, | ||||||||||
| 31 | from_columns => \@from, | ||||||||||
| 32 | to_table => $first->{table}, | ||||||||||
| 33 | to_columns => \@to, | ||||||||||
| 34 | on_update => $first->{on_update}, | ||||||||||
| 35 | on_delete => $first->{on_delete}, | ||||||||||
| 36 | match => $first->{match}, | ||||||||||
| 37 | 293 | }; | |||||||||
| 38 | } @$groups ]; | ||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 755 | return \%fks; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 193 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||