« RDF/RDB2RDF/DirectMapping/Store/Mixin/SuperGetPattern.pm
↑ Summary
RDF/RDB2RDF/DatatypeMapper.pm »
| 1 | package RDF::RDB2RDF::DirectMapping; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Carp qw[carp croak]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Data::UUID; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use MIME::Base64 qw[]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use RDF::Trine qw[iri blank literal statement]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use RDF::Trine::Namespace qw[RDF RDFS OWL XSD]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Scalar::Util qw[refaddr blessed]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use URI::Escape::Optimistic qw[uri_escape_optimistic]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use match::simple qw[match]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use base qw[ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | RDF::RDB2RDF | ||||||||||||||||||||||||||||||||||||||||||
| 20 | RDF::RDB2RDF::DatatypeMapper | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ]; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | our $VERSION = '0.008'; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $args{prefix} = '' unless defined $args{prefix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $args{rdfs} = 0 unless defined $args{rdfs}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $args{warn_sql} = 0 unless defined $args{warn_sql}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $args{ignore_tables} = [] unless defined $args{ignore_tables}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $args{unique} = Data::UUID->new->create_str; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub prefix :lvalue { $_[0]->{prefix} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefix: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub rdfs :lvalue { $_[0]->{rdfs} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rdfs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub ignore_tables :lvalue { $_[0]->{ignore_tables} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ignore_tables: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub warn_sql :lvalue { $_[0]->{warn_sql} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn_sql: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub _unquote_identifier | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote_identifier: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $i = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return $1 if $i =~ /^\"(.+)\"$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $i; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | sub rowmap (&$) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rowmap: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($coderef, $iter) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my @results = (); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | ref($iter) or return @results; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | while ($_ = $iter->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | push @results, $coderef->($coderef, $iter, $_, ++$i); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | wantarray ? @results : scalar(@results); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub layout | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
layout: not called CC=20 SCAR=59.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $dbh, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | unless ($self->{layout}{refaddr($dbh).'|'.$schema}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | carp sprintf('READ SCHEMA "%s"', $schema||'%') if $self->warn_sql; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$schema || '%'
MC/DC0%0/1
$schema || '%'
$schema
Truth table0%0/2
A
A= $schema
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $rv = {}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my @tables = rowmap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | _unquote_identifier($_->{TABLE_NAME}) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | } $dbh->table_info(undef, $schema, undef, undef); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | foreach my $table (@tables) | |||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i
MC/DC0%0/2
$table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i
$table =~ /^sqlite_/
$dbh->get_info(17) =~ /sqlite/i
Truth table0%0/3
A and B
A= $table =~ /^sqlite_/B= $dbh->get_info(17) =~ /sqlite/i
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $rv->{$table}{columns} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rv->{$table}{"columns"} ||= []
MC/DC0%0/1
$rv->{$table}{"columns"} ||= []
$rv->{$table}{"columns"}
Truth table0%0/2
A
A= $rv->{$table}{"columns"}
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $rv->{$table}{keys} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rv->{$table}{"keys"} ||= {}
MC/DC0%0/1
$rv->{$table}{"keys"} ||= {}
$rv->{$table}{"keys"}
Truth table0%0/2
A
A= $rv->{$table}{"keys"}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $rv->{$table}{refs} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rv->{$table}{"refs"} ||= {}
MC/DC0%0/1
$rv->{$table}{"refs"} ||= {}
$rv->{$table}{"refs"}
Truth table0%0/2
A
A= $rv->{$table}{"refs"}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | $rv->{$table}{columns} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} } | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | rowmap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | my $type = ($_->{TYPE_NAME} =~ /^char$/i and defined $_->{COLUMN_SIZE}) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ? sprintf('%s(%d)', $_->{TYPE_NAME}, $_->{COLUMN_SIZE}) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | : $_->{TYPE_NAME}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->{"TYPE_NAME"} =~ /^char$/i and defined $_->{"COLUMN_SIZE"}
MC/DC0%0/2
$_->{"TYPE_NAME"} =~ /^char$/i and defined $_->{"COLUMN_SIZE"}
$_->{"TYPE_NAME"} =~ /^char$/i
defined $_->{"COLUMN_SIZE"}
Truth table0%0/3
A and B
A= $_->{"TYPE_NAME"} =~ /^char$/iB= defined $_->{"COLUMN_SIZE"}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | +{ | ||||||||||||||||||||||||||||||||||||||||||
| 100 | column => _unquote_identifier($_->{COLUMN_NAME}), | ||||||||||||||||||||||||||||||||||||||||||
| 101 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | order => $_->{ORDINAL_POSITION}, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | nullable => $_->{NULLABLE}, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $dbh->column_info(undef, $schema, $table, undef) | |||||||||||||||||||||||||||||||||||||||||
| 107 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $pkey_name; | |||||||||||||||||||||||||||||||||||||||||
| 110 | my @pkey_cols = | ||||||||||||||||||||||||||||||||||||||||||
| 111 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $pkey_name = _unquote_identifier($_->{PK_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | _unquote_identifier($_->{COLUMN_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | sort { $a->{KEY_SEQ} <=> $b->{KEY_SEQ} } | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | rowmap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | +{ %$_ }; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $dbh->primary_key_info(undef, $schema, $table, undef); | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $rv->{$table}{keys}{$pkey_name} = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | name => $pkey_name, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | columns => \@pkey_cols, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | primary => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } if @pkey_cols; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $sth = $dbh->foreign_key_info(undef, $schema, undef, undef, $schema, $table); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($sth) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | while (my $result = $sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | push @r, $result; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | @r = sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} } @r; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | foreach my $f (@r) | |||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | push @{ $rv->{$table}{refs}{ $f->{FK_NAME} }{columns} }, _unquote_identifier($f->{FK_COLUMN_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | push @{ $rv->{$table}{refs}{ $f->{FK_NAME} }{target_columns} }, _unquote_identifier($f->{UK_COLUMN_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $rv->{$table}{refs}{ $f->{FK_NAME} }{target_table} = _unquote_identifier($f->{UK_TABLE_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $sth = $dbh->statistics_info(undef, $schema, $table, 1, 0); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($sth) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | while (my $result = $sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | next if $result->{FILTER_CONDITION}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | next if $result->{NON_UNIQUE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | next if $rv->{$table}{keys}{ _unquote_identifier($result->{INDEX_NAME}) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | push @r, $result; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | @r = sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} } @r; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | foreach my $f (@r) | |||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | push @{ $rv->{$table}{keys}{ $f->{INDEX_NAME} }{columns} }, _unquote_identifier($f->{COLUMN_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $rv->{$table}{keys}{ $f->{INDEX_NAME} }{name} = _unquote_identifier($f->{INDEX_NAME}); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{layout}{refaddr($dbh).'|'.$schema} = $rv; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->{layout}{refaddr($dbh).'|'.$schema}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | sub process | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my ($self, $dbh, $model) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | my $callback = (ref $model eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ? $model | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | : sub{ $model->add_statement(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $schema; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $layout = $self->layout($dbh, $schema); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | foreach my $table (keys %$layout) | |||||||||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $table =~ s/^"(.+)"$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $self->handle_table([$dbh, $schema], $callback, $table); | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return $model; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | sub handle_table | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_table: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my ($self, $dbh, $model, $table, $where, $cols) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | return if match $table, $self->ignore_tables; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $schema; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $cols = [$cols] if (defined $cols and !ref $cols and length $cols); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $cols and not ref $cols and length $cols
defined $cols and not ref $cols
MC/DC0%0/3
defined $cols and not ref $cols and length $cols
defined $cols
not ref $cols
length $cols
Truth table0%0/4
A and not(B) and C
A= defined $colsB= not ref $colsC= length $cols
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $layout = $self->layout($dbh, $schema); | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (ref $cols eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($pkey) = grep { $_->{primary} } values %{ $layout->{$table}{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my %cols = map { $_ => 1 } (@{ $pkey->{columns} }, @$cols); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $cols = join ',', map { $dbh->quote_identifier($_) } sort keys %cols; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | else | ||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $cols = '*'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $self->handle_table_rdfs([$dbh, $schema], $callback, $table) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cols eq "*" and not defined $where
MC/DC0%0/2
$cols eq "*" and not defined $where
$cols eq "*"
not defined $where
Truth table0%0/3
A and not(B)
A= $cols eq "*"B= not defined $where
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | if ($cols eq '*' and !defined $where); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $sql = $schema | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | ? sprintf('SELECT %s FROM %s.%s', $cols, $dbh->quote_identifier($schema), $dbh->quote_identifier($table)) | ||||||||||||||||||||||||||||||||||||||||||
| 220 | : sprintf('SELECT %s FROM %s', $cols, $dbh->quote_identifier($table)); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ($where) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my @w; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | while (my ($k,$v) = each %$where) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | push @w, sprintf('%s = ?', $dbh->quote_identifier($k)); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | push @values, $v; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $sql .= ' WHERE ' . (join ' AND ', @w); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | carp($sql) if $self->warn_sql; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $sth->execute(@values); | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # print Dumper($layout, $row, $table); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | my ($pkey_uri) = | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | map { $self->make_key_uri($table, $_->{columns}, $row); } | |||||||||||||||||||||||||||||||||||||||||
| 244 | sort { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | $b->{primary} <=> $a->{primary} | ||||||||||||||||||||||||||||||||||||||||||
| 246 | or $a->{name} cmp $b->{name} | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
MC/DC0%0/2
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}
$RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
Truth table0%0/3
A || B
A= $RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}B= $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | values %{ $layout->{$table}{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $subject = $pkey_uri ? iri($pkey_uri) : blank(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | # rdf:type | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $callback->(statement($subject, $RDF->type, iri($self->prefix.$table))); | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # owl:sameAs | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($cols eq '*') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | $callback->(statement($subject, $OWL->sameAs, $_)) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | foreach | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | grep { not $subject->equal($_) } | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | map { iri $_ } # don't combine with previous step, as make_key_uri can return empty list | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | map { $self->make_key_uri($table, $_->{columns}, $row) } | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | values %{ $layout->{$table}{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # p-o for columns | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | foreach my $column (@{ $layout->{$table}{columns} }) | |||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | next unless defined $row->{ $column->{column} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $predicate = iri($self->prefix.$table.'#'.$column->{column}); | |||||||||||||||||||||||||||||||||||||||||
| 271 | my $object = $self->datatyped_literal( | ||||||||||||||||||||||||||||||||||||||||||
| 272 | $row->{ $column->{column} }, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | $column->{type}, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $callback->(statement($subject, $predicate, $object)); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # foreign keys | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | foreach my $ref (values %{ $layout->{$table}{refs} }) | |||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $predicate = iri($self->make_ref_uri($table, $ref)); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $object = iri($self->make_ref_dest_uri($table, $ref, $row, [$dbh, $schema])); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $callback->(statement($subject, $predicate, $object)); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | sub handle_table_rdfs | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_table_rdfs: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my ($self, $dbh, $model, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return if match $table, $self->ignore_tables; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $schema; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $layout = $self->layout($dbh, $schema); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($self->rdfs) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $callback->(statement(iri($self->prefix.$table), $RDF->type, $OWL->Class)); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $callback->(statement(iri($self->prefix.$table), $RDFS->label, literal($table))); | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | foreach my $column (@{ $layout->{$table}{columns} }) | |||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $predicate = iri($self->prefix.$table.'#'.$column->{column}); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $dummy = $self->datatyped_literal('DUMMY', $column->{type}); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | my $datatype = $dummy->has_datatype ? iri($dummy->literal_datatype) : $RDFS->Literal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $callback->(statement($predicate, $RDF->type, $OWL->DatatypeProperty)); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $callback->(statement($predicate, $RDFS->label, literal($column->{column}))); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $callback->(statement($predicate, $RDFS->domain, iri($self->prefix.$table))); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $callback->(statement($predicate, $RDFS->range, $datatype)) if $datatype; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | foreach my $ref (values %{ $layout->{$table}{refs} }) | |||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $predicate = iri($self->make_ref_uri($table, $ref)); | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $callback->(statement($predicate, $RDF->type, $OWL->ObjectProperty)); | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $callback->(statement($predicate, $RDFS->domain, iri($self->prefix.$table))); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $callback->(statement($predicate, $RDFS->range, iri($self->prefix.$ref->{target_table}))); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub process_turtle | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_turtle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return $self->SUPER::process_turtle(@args, base_uri=>$self->prefix); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | sub make_key_uri | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_key_uri: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($self, $table, $columns, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return if grep { !defined $data->{$_} } @$columns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | return $self->prefix . | ||||||||||||||||||||||||||||||||||||||||||
| 340 | uri_escape_optimistic($table) . "/" . | ||||||||||||||||||||||||||||||||||||||||||
| 341 | (join ';', map | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | { sprintf('%s=%s', uri_escape_optimistic($_), uri_escape_optimistic($data->{$_})); } | |||||||||||||||||||||||||||||||||||||||||
| 343 | @$columns); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | sub make_ref_uri | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_ref_uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ($self, $table, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | return $self->prefix . | ||||||||||||||||||||||||||||||||||||||||||
| 351 | uri_escape_optimistic($table) . "#ref-" . | ||||||||||||||||||||||||||||||||||||||||||
| 352 | (join ';', map | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | { uri_escape_optimistic($_); } | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | @{$ref->{columns}}); | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | sub make_ref_dest_uri_OLD | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_ref_dest_uri_OLD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ($self, $table, $ref, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $map; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | for (my $i = 0; exists $ref->{columns}[$i]; $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $map->{ $ref->{target_columns}[$i] } = $ref->{columns}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | return $self->prefix . | ||||||||||||||||||||||||||||||||||||||||||
| 368 | uri_escape_optimistic($ref->{target_table}) . "/" . | ||||||||||||||||||||||||||||||||||||||||||
| 369 | (join ';', map | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | { sprintf('%s=%s', uri_escape_optimistic($_), uri_escape_optimistic($data->{$map->{$_}})); } | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | @{$ref->{target_columns}}); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | sub make_ref_dest_uri | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_ref_dest_uri: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my ($self, $table, $ref, $data, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $schema; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | ($dbh, $schema) = @$dbh if ref $dbh eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $layout = $self->layout($dbh, $schema); | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | my %cols = | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | map { @{ $_->{columns} } } | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | values %{ $layout->{ $ref->{target_table} }{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 386 | my $cols = | ||||||||||||||||||||||||||||||||||||||||||
| 387 | join q[, ], | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | map { $dbh->quote_identifier($_) } | |||||||||||||||||||||||||||||||||||||||||
| 389 | sort keys %cols; | ||||||||||||||||||||||||||||||||||||||||||
| 390 | my $sql = $schema | ||||||||||||||||||||||||||||||||||||||||||
| 391 | ? sprintf('SELECT %s FROM %s.%s', $cols, $dbh->quote_identifier($schema), $dbh->quote_identifier($ref->{target_table})) | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | : sprintf('SELECT %s FROM %s', $cols, $dbh->quote_identifier($ref->{target_table})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 395 | my @where; | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | foreach my $i (0 .. @{$ref->{target_columns}}-1) | |||||||||||||||||||||||||||||||||||||||||
| 397 | { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if (defined $data->{ $ref->{columns}[$i] }) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | push @where, sprintf('%s = ?', $dbh->quote_identifier($ref->{target_columns}[$i])); | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | push @values, $data->{ $ref->{columns}[$i] }; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | else | ||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | push @where, sprintf('%s IS NULL', $dbh->quote_identifier($ref->{target_columns}[$i])); | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $sql .= ' WHERE ' . (join ' AND ', @where); | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | carp($sql) if $self->warn_sql; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $sth->execute(@values); | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if (my $row = $sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | my ($pkey_uri) = | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | map { $self->make_key_uri($ref->{target_table}, $_->{columns}, $row); } | |||||||||||||||||||||||||||||||||||||||||
| 418 | sort { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | $b->{primary} <=> $a->{primary} | ||||||||||||||||||||||||||||||||||||||||||
| 420 | or $a->{name} cmp $b->{name} | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
MC/DC0%0/2
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}
$RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
Truth table0%0/3
A || B
A= $RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}B= $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | values %{ $layout->{$ref->{target_table}}{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | return $pkey_uri if $pkey_uri; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $self->make_ref_dest_uri_OLD($table, $ref, $data); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | __END__ | ||||||||||||||||||||||||||||||||||||||||||