DB2/DDL.pm

filter: Statementstmt 98.4% 432 / 439 Branchbran 83.8% 213 / 254 Conditioncond 70.6% 130 / 184 MC/DCmcdc 49.0% 51 / 104 Subroutinesub 100% 38 / 38 Podpod 100% 6 / 6 totaltotal 84.8% 870 / 1025 CC 214 SCAR 32.4
CC
214
Cov
88%
_view_reads_q
52.8
install_ddl
50.3
_topo_sort_sources
20.6
CRAP 25.5
« DB2/Diff/Index.pm ↑ Summary DB2/Type.pm »
1 package DBIO::DB2::DDL;
2 # ABSTRACT: Generate DB2 DDL from DBIO Result classes
3  
4 51 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 51 our $VERSION = '0.900007';
8  
9 51 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 51 ▶use DBIO::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 51 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 51 ▶use DBIO::DB2::Type qw(_db2_column_type _db2_mapped_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 51 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 51 our @EXPORT_OK = qw(
19 _fk_constraint_clause _db2_quote_ident _db2_default_literal
20 _db2_identity_clause _unique_constraint_clause _table_unique_constraints
21 _refuse_nullable_unique _index_is_duplicate
22 _db2_quote_table _split_table_name
23 );
24  
25 # DB2-specific identifier quoter: ALWAYS quotes (unlike
26 # DBIO::SQL::Util::_quote_ident, which is the PostgreSQL-correct helper that
27 # leaves simple names bare -- correct there because unquoted folds to
28 # lowercase, wrong on DB2 where unquoted folds to UPPERCASE). The driver is a
29 # quote-everything driver (sql_quote_char '"', pinned in
30 # t/50-results-exist.t), so every name this driver emits -- tables, columns,
31 # indexes, FK targets, constraint names -- must be wrapped in double-quotes,
32 # otherwise the installed schema lives on as ARTIST while the SQLMaker queries
33 # "artist" -> SQL0204N (karr k28, followup to karr k26). Embedded `"` is
34 # escaped as `""` per the SQL standard.
35 810 ▶sub _db2_quote_ident {
Subroutine _db2_quote_ident: called CC=3 SCAR=11.0
36 810 my ($name) = @_;
37 # undef (e.g. constraint_name from an incomplete FK hash) would silently
38 # emit a warning-level empty "" -- croak early instead (karr k32).
39 810 ▶ croak 'DBIO::DB2::DDL::_db2_quote_ident: undef identifier (caller: '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 809 810
Condition50%1/2
caller 1 || '?'
l!l
10
MC/DC0%0/1
caller 1 || '?'
caller 1
Truth table50%1/2
A
A= caller 1
Aresult
11
00
40 . (caller(1) || '?') . ')' unless defined $name;
41 809 $name =~ s/"/""/g;
42 809 return qq{"$name"};
43 }
44  
45 # A table name written "schema.table" (karr k57, maintainer decision) is the table
46 # in that schema, not one table with a dot in its name: split at the dot. Db2
47 # makes a schema that is missing when the first table of it is created (implicit
48 # schema creation). The compare deploy of the diff reads one schema and leaves a
49 # qualified table out (DBIO::DB2::Deploy::_split_qualify_ddl).
50 420 ▶sub _split_table_name {
Subroutine _split_table_name: called CC=2 SCAR=6.9
51 420 my ($name) = @_;
52 420 ▶ return $name =~ /\A([^."]+)\.([^."]+)\z/ ? ($1, $2) : (undef, $name);
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\A([^."]+)\.([^."]+)\z/ ? : 31 389 420
53 }
54  
55 262 ▶sub _db2_quote_table {
Subroutine _db2_quote_table: called CC=2 SCAR=6.9
56 262 my ($schema, $table) = _split_table_name($_[0]);
57 262 ▶ return defined $schema
Branch: 1 branch
BranchTrueFalseTotal
defined $schema ? : 11 251 262
58 ? _db2_quote_ident($schema) . '.' . _db2_quote_ident($table)
59 : _db2_quote_ident($table);
60 }
61  
62 # Default-value renderer for install_ddl: turns the default_value of a RESULT
63 # CLASS -- a Perl value -- into the SQL text of a DEFAULT clause (karr k32).
64 # install_ddl used to write every non-ref default as an unescaped string
65 # literal: an apostrophe broke out of the quotes, a semicolon inside it cut the
66 # statement in two at the splitter, DEFAULT '13' on an INTEGER column was rejected with
67 # SQL0574N.
68 #
69 # It is NOT for the diff op classes, which called it too until karr k41. Their
70 # default_value comes out of SYSCAT.COLUMNS.DEFAULT and is the SQL text
71 # already -- 'new' with its quotes, 'it''s' with the apostrophe doubled -- so
72 # running it through here quoted it a second time: DEFAULT '''it''''s'''. The
73 # server took that, the column's default was then the text 'it''s' itself, and
74 # every later diff asked to set it again. DBIO::DB2::Diff::Table and
75 # DBIO::DB2::Diff::Column write the catalog text as it is. Rules:
76 # * SCALAR ref -> raw SQL expression (DBIC idiom \'CURRENT TIMESTAMP'),
77 # emitted bare -- the user opted out of literal rendering.
78 # * the column's type is a character type (CHAR, VARCHAR, CLOB, GRAPHIC,
79 # VARGRAPHIC, DBCLOB, LONG VARCHAR, ... and the aliases the type map
80 # resolves to them, text, json) -> single-quoted string literal,
81 # whatever the value looks like: '00000' on a CHAR(5) keeps its zeros,
82 # 'USER' and 'NULL' are text, not the register and not NULL (karr k46).
83 # * numeric -> bare literal (DEFAULT 13, not DEFAULT '13').
84 # * NULL and the DB2 special registers (CURRENT DATE, CURRENT TIMESTAMP,
85 # ...) -> bare function calls.
86 # * everything else -> single-quoted string literal, embedded single-quotes
87 # doubled ('').
88 39 ▶sub _db2_default_literal {
Subroutine _db2_default_literal: called CC=5 SCAR=16.1
89 39 my ($value, $data_type) = @_;
90 39 ▶ return $$value if ref $value eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "SCALAR" 6 33 39
91 33 ▶ return _db2_quote_string($value) if _db2_is_character_type($data_type);
Branch: 1 branch
BranchTrueFalseTotal
if _db2_is_character_type($data_type) 16 17 33
92 17 ▶ return $value if $value =~ /\A[+-]?\d+(?:\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A[+-]?\d+(?:\.\d+)?\z/ 7 10 17
93 10 ▶ return $value if $value =~ /\A(?:NULL|CURRENT[\s_]+\w+|(?:SESSION|SYSTEM)_USER|USER)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A(?:NULL|CURRENT[\s_]+\w+|(?:SESSION|SYSTEM)_USER|USER)\z/i 5 5 10
94 5 return _db2_quote_string($value);
95 }
96  
97 21 ▶sub _db2_quote_string {
Subroutine _db2_quote_string: called CC=1 SCAR=0.0
98 21 my ($value) = @_;
99 21 $value =~ s/'/''/g;
100 21 return "'$value'";
101 }
102  
103 # True when the data_type of a result class column is a character type, by the
104 # name _db2_column_type maps it to ('text' -> VARCHAR). No type (undef) is
105 # not a character type: the caller did not say.
106 36 ▶sub _db2_is_character_type {
Subroutine _db2_is_character_type: called CC=4 SCAR=13.9
107 36 my ($data_type) = @_;
108 36 ▶ return 0 unless defined $data_type && length $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type and length $data_type 10 26 36
Condition66%2/3
defined $data_type and length $data_type
!ll&&!rl&&r
10026
MC/DC50%1/2
defined $data_type and length $data_type
defined $data_type length $data_type
Truth table66%2/3
A and B
A= defined $data_typeB= length $data_type
ABresult
0X0
100
111
109 26 my $mapped = uc _db2_mapped_type($data_type);
110 26 $mapped =~ s/\s*\(.*\z//s;
111 26 ▶ return $mapped =~ /\A(?:CHAR|CHARACTER|VARCHAR|CHAR VARYING|CHARACTER VARYING|LONG VARCHAR|CLOB|CHARACTER LARGE OBJECT|GRAPHIC|VARGRAPHIC|LONG VARGRAPHIC|DBCLOB|NCHAR|NVARCHAR|NCLOB)\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mapped =~ /\A(?:CHAR|CHARACTER|VARCHAR|CHAR VARYING|CHARACTER VARYING|LONG VARCHAR|CLOB|CHARACTER LARGE OBJECT|GRAPHIC|VARGRAPHIC|LONG VARGRAPHIC|DBCLOB|NCHAR|NVARCHAR|NCLOB)\z/ ? : 19 7 26
112 }
113  
114 # The identity clause of an auto-increment column, in one place for the two
115 # producers of a CREATE TABLE: install_ddl and DBIO::DB2::Diff::Table. The
116 # second one left it out, so a table created by upgrade had a plain NOT NULL
117 # primary key and refused every insert that did not bring its own id
118 # (SQL0407N, karr k41).
119 24 ▶sub _db2_identity_clause {
Subroutine _db2_identity_clause: called CC=1 SCAR=0.0
120 24 return 'GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)';
121 }
122  
123  
124  
125  
126 37 ▶sub current_schema {
Subroutine current_schema: called CC=2 SCAR=6.9
Pod documented
127 37 my ($dbh) = @_;
128 37 my ($current_schema) = $dbh->selectrow_array('VALUES CURRENT SCHEMA');
129 37 ▶ $current_schema =~ s/\s+$// if defined $current_schema;
Branch: 1 branch
BranchTrueFalseTotal
if defined $current_schema 35 2 37
130 37 return $current_schema;
131 }
132  
133 # The CURRENT SCHEMA of a schema object's connection, undef where there is none (a
134 # class, a storage that cannot connect, a handle that gives no answer). A schema connected
135 # but not used yet connects here.
136 19 ▶sub _connection_schema {
Subroutine _connection_schema: called CC=5 SCAR=16.2
137 19 my ($schema) = @_;
138 19 ▶ return undef unless Scalar::Util::blessed($schema);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($schema) 13 6 19
139 6 my $name = eval {
140 6 my $storage = $schema->storage;
141 6 ▶ $storage ? current_schema($storage->dbh) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$storage ? : 6 0 6
142 };
143 6 ▶ return (defined $name && length $name) ? $name : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $name && length $name ? : 2 4 6
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
402
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
144 }
145  
146  
147 2 ▶sub qualified_tables {
Subroutine qualified_tables: called CC=5 SCAR=16.1
Pod documented
148 2 my ($class, $schema) = @_;
149 2 my @pairs;
150 2 for my $moniker (sort $schema->sources) {
151 6 my $source = $schema->source($moniker);
152 6 ▶ next if $source->isa('DBIO::ResultSource::View');
Branch: 1 branch
BranchTrueFalseTotal
if $source->isa("DBIO::ResultSource::View") 1 5 6
153 5 my $name = _resolve_table_name($source->name);
154 5 ▶ next unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 5 5
155 5 my ($s) = _split_table_name($name);
156 5 ▶ push @pairs, [ $name, $s ] if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 2 3 5
157 }
158 2 my %seen;
159 2 return sort { $a->[0] cmp $b->[0] } grep { !$seen{ $_->[0] }++ } @pairs;
160 }
161  
162 31 ▶sub install_ddl {
Subroutine install_ddl: called CC=45 SCAR=39.2
Pod documented
163 31 my ($class, $schema, $view_schema, $opt) = @_;
164 31 ▶ $opt //= {};
Condition100%2/2
$opt //= {}
l!l
427
MC/DC100%1/1
$opt //= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
165 # The compare deploy of the diff reads one schema at a time (karr k57):
166 # local_only leaves out the tables named schema.table, only_schema => S keeps
167 # the tables of S, under their own names (no qualifier, the key targets in S
168 # bare), and no view.
169 31 ▶ $view_schema //= _connection_schema($schema);
Condition100%3/3
$view_schema //= _connection_schema($schema)
l!l&&r!l&&!r
12217
MC/DC100%2/2
$view_schema //= _connection_schema($schema)
$view_schema _connection_schema($schema)
Truth table100%3/3
A //= B
A= $view_schemaB= _connection_schema($schema)
ABresult
1X1
011
000
170  
171 31 my @stmts;
172 my %seen_table;
173 31 my %view_def;
174  
175 31 for my $source_name (_topo_sort_sources($schema)) {
176 58 my $source = $schema->source($source_name);
177 58 my $result_class = $source->result_class;
178 # Views: emit CREATE VIEW after all tables; skip virtual views.
179 58 ▶ if ($source->isa('DBIO::ResultSource::View')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->isa("DBIO::ResultSource::View")) 24 34 58
180 24 ▶ next if defined $opt->{only_schema};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"only_schema"} 0 24 24
181 24 ▶ next if $source->can('is_virtual') && $source->is_virtual;
Branch: 1 branch
BranchTrueFalseTotal
if $source->can("is_virtual") and $source->is_virtual 0 24 24
Condition33%1/3
$source->can("is_virtual") and $source->is_virtual
!ll&&!rl&&r
0240
MC/DC0%0/2
$source->can("is_virtual") and $source->is_virtual
$source->can("is_virtual") $source->is_virtual
Truth table33%1/3
A and B
A= $source->can("is_virtual")B= $source->is_virtual
ABresult
0X0
100
111
182 24 my $vname = _resolve_table_name($source->name);
183 24 ▶ next if !defined $vname || exists $view_def{$vname};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $vname or exists $view_def{$vname} 0 24 24
Condition33%1/3
not defined $vname or exists $view_def{$vname}
l!l&&r!l&&!r
0024
MC/DC0%0/2
not defined $vname or exists $view_def{$vname}
not defined $vname exists $view_def{$vname}
Truth table33%1/3
not(A) or B
A= not defined $vnameB= exists $view_def{$vname}
ABresult
1X1
011
000
184 24 ▶ my $def = $source->can('view_definition') ? $source->view_definition : undef;
Branch: 1 branch
BranchTrueFalseTotal
$source->can('view_definition') ? : 24 0 24
185 24 ▶ next unless defined $def && length $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def and length $def 0 24 24
Condition33%1/3
defined $def and length $def
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $def and length $def
defined $def length $def
Truth table33%1/3
A and B
A= defined $defB= length $def
ABresult
0X0
100
111
186 24 $view_def{$vname} = $def;
187 24 next;
188 }
189  
190 34 my $table_name = _resolve_table_name($source->name);
191  
192 34 ▶ next unless defined $table_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table_name 0 34 34
193 34 ▶ next if $seen_table{$table_name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_table{$table_name}++ 0 34 34
194 34 my ($qualifier, $bare) = _split_table_name($table_name);
195 34 ▶ next if $opt->{local_only} && defined $qualifier;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"local_only"} and defined $qualifier 2 32 34
Condition100%3/3
$opt->{"local_only"} and defined $qualifier
!ll&&!rl&&r
2752
MC/DC100%2/2
$opt->{"local_only"} and defined $qualifier
$opt->{"local_only"} defined $qualifier
Truth table100%3/3
A and B
A= $opt->{"local_only"}B= defined $qualifier
ABresult
0X0
100
111
196 32 ▶ if (defined $opt->{only_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"only_schema"}) 3 29 32
197 3 ▶ next unless defined $qualifier && $qualifier eq $opt->{only_schema};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qualifier and $qualifier eq $opt->{"only_schema"} 1 2 3
Condition66%2/3
defined $qualifier and $qualifier eq $opt->{"only_schema"}
!ll&&!rl&&r
102
MC/DC50%1/2
defined $qualifier and $qualifier eq $opt->{"only_schema"}
defined $qualifier $qualifier eq $opt->{"only_schema"}
Truth table66%2/3
A and B
A= defined $qualifierB= $qualifier eq $opt->{"only_schema"}
ABresult
0X0
100
111
198 2 $table_name = $bare;
199 }
200  
201 31 my ($table_schema) = _split_table_name($table_name);
202 31 my @col_defs;
203 my %is_pk;
204 31 my @pk_cols = $source->primary_columns;
205 31 @is_pk{@pk_cols} = (1) x @pk_cols;
206  
207 31 for my $col_name ($source->columns) {
208 78 my $info = $source->column_info($col_name);
209 78 my $type = _db2_column_type($info, undef, "$table_name.$col_name");
210  
211 77 my $def = sprintf ' %s %s', _db2_quote_ident($col_name), $type;
212  
213 # Absent is_nullable means NOT NULL: core's canonical_column reads a
214 # missing key as not_null => 1 (ADR 0043), so a bare `defined && !`
215 # guard would deploy such columns as nullable.
216 77 ▶ $def .= ' NOT NULL' if !$info->{is_nullable};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"is_nullable"} 62 15 77
217  
218 77 ▶ if ($info->{is_auto_increment}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info->{'is_auto_increment'}) { } 20 57 77
elsif (defined $info->{'default_value'}) { } 9 48 57
219 # DB2 uses GENERATED ALWAYS AS IDENTITY for auto-increment
220 20 $def .= ' ' . _db2_identity_clause();
221 }
222 elsif (defined $info->{default_value}) {
223 9 $def .= ' DEFAULT ' . _db2_default_literal($info->{default_value}, $info->{data_type});
224 }
225  
226 77 push @col_defs, $def;
227 }
228  
229 30 ▶ if (@pk_cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pk_cols) 30 0 30
230 push @col_defs, sprintf ' PRIMARY KEY (%s)',
231 30 join(', ', map { _db2_quote_ident($_) } @pk_cols);
232 }
233  
234 # Named inline UNIQUE constraints of the source (karr k39, ADR 0009). Db2
235 # makes an index of the same name behind each; the introspector reads the
236 # pair as the constraint, so the diff neither drops nor doubles the index.
237 30 for my $uc (_table_unique_constraints($source, $table_name)) {
238 3 push @col_defs, ' ' . _unique_constraint_clause(@$uc);
239 }
240  
241 # Named inline foreign keys derived from belongs_to relationships. DB2
242 # enforces RI, so the install DDL must carry them; the deterministic name
243 # (fk_<table>_<from_cols>) makes the constraint round-trip with a stable
244 # identity for the name-based diff in DBIO::DB2::Diff::ForeignKey.
245 29 for my $fk (_table_foreign_keys($schema, $source)) {
246 8 ▶ if (defined $opt->{only_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"only_schema"}) 1 7 8
247 1 my ($fq, $fbare) = _split_table_name($fk->{to_table});
248 1 ▶ $fk = { %$fk, to_table => $fbare } if defined $fq && $fq eq $opt->{only_schema};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fq and $fq eq $opt->{"only_schema"} 1 0 1
Condition33%1/3
defined $fq and $fq eq $opt->{"only_schema"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $fq and $fq eq $opt->{"only_schema"}
defined $fq $fq eq $opt->{"only_schema"}
Truth table33%1/3
A and B
A= defined $fqB= $fq eq $opt->{"only_schema"}
ABresult
0X0
100
111
249 }
250 8 push @col_defs, ' ' . _fk_constraint_clause($fk);
251 }
252  
253 29 push @stmts, sprintf "CREATE TABLE %s (\n%s\n);",
254 _db2_quote_table($table_name), join(",\n", @col_defs);
255  
256 # Standalone indexes. Db2 does not create an index on a column sequence that
257 # an index already covers (SQL0605W, state 42S11, no object made), so such an
258 # entry is not written (karr k47, ADR 0010). What covers it, in the order the
259 # server meets it: the primary key, the UNIQUE constraints, then the
260 # indexes of this loop in name order.
261 # Two sources of indexes: the db2_indexes hash written by hand, and the
262 # canonical declarations of the result source (Cake idx, add_index_declaration;
263 # ADR 0061 in core, karr k57). A canonical declaration of the same name wins.
264 29 my %indexes;
265 29 ▶ if ($result_class->can('db2_indexes')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_class->can("db2_indexes")) 7 22 29
266 7 my $hand = $result_class->db2_indexes;
267 7 $indexes{$_} = $hand->{$_} for keys %$hand;
268 }
269 # index_declarations_for refuses an entry that carries only another driver's
270 # block, and an unknown key in the db2 block (this driver has none). What core
271 # can express and Db2 cannot is refused here, never written as a plainer index.
272 29 for my $decl ($source->index_declarations_for('db2', [])) {
273 my $where = sprintf "DBIO::DB2::DDL: table '%s': index '%s' (%s) is refused",
274 6 ▶ $table_name, $decl->{name}, join(', ', @{ $decl->{columns} // [] });
Condition50%1/2
$decl->{"columns"} // []
l!l
60
MC/DC0%0/1
$decl->{"columns"} // []
$decl->{"columns"}
Truth table50%1/2
A
A= $decl->{"columns"}
Aresult
11
00
275 DBIO::Exception->throw("$where: type '$decl->{type}' has no Db2 counterpart and is not written as a plainer index")
276 6 ▶ if defined $decl->{type} && $decl->{type} !~ /\Aunique\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $decl->{"type"} and not $decl->{"type"} =~ /\Aunique\z/i 1 5 6
Condition66%2/3
defined $decl->{"type"} and not $decl->{"type"} =~ /\Aunique\z/i
!ll&&!rl&&r
501
MC/DC50%1/2
defined $decl->{"type"} and not $decl->{"type"} =~ /\Aunique\z/i
defined $decl->{"type"} not $decl->{"type"} =~ /\Aunique\z/i
Truth table66%2/3
A and not(B)
A= defined $decl->{"type"}B= not $decl->{"type"} =~ /\Aunique\z/i
ABresult
0X0
100
111
277 DBIO::Exception->throw("$where: options are not supported by the Db2 DDL and are not dropped silently")
278 5 ▶ if defined $decl->{options};
Branch: 1 branch
BranchTrueFalseTotal
if defined $decl->{"options"} 1 4 5
279 4 $indexes{ $decl->{name} } = { columns => $decl->{columns}, unique => $decl->{unique} };
280 }
281 26 ▶ if (%indexes) {
Branch: 1 branch
BranchTrueFalseTotal
if (%indexes) 7 19 26
282 7 my @existing;
283 7 ▶ push @existing, [ [ @pk_cols ], 1 ] if @pk_cols;
Branch: 1 branch
BranchTrueFalseTotal
if @pk_cols 7 0 7
284 7 push @existing, map { [ $_->[1], 1 ] }
285 _table_unique_constraints($source, $table_name);
286 7 for my $idx_name (sort keys %indexes) {
287 23 my $idx = $indexes{$idx_name};
288 23 ▶ my @cols = @{ $idx->{columns} // [] };
Condition50%1/2
$idx->{"columns"} // []
l!l
230
MC/DC0%0/1
$idx->{"columns"} // []
$idx->{"columns"}
Truth table50%1/2
A
A= $idx->{"columns"}
Aresult
11
00
289 23 ▶ next if _index_is_duplicate(\@cols, $idx->{unique}, \@existing);
Branch: 1 branch
BranchTrueFalseTotal
if _index_is_duplicate(\@cols, $idx->{"unique"}, \@existing) 7 16 23
290 16 ▶ push @existing, [ \@cols, $idx->{unique} ? 1 : 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$idx->{'unique'} ? : 5 11 16
291 16 ▶ my $unique = $idx->{unique} ? 'UNIQUE ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$idx->{'unique'} ? : 5 11 16
292 16 my $columns = join ', ', map { _db2_quote_ident($_) } @cols;
293 16 ▶ my $sql = sprintf 'CREATE %sINDEX %s ON %s (%s)',
Branch: 1 branch
BranchTrueFalseTotal
defined $table_schema ? : 1 15 16
294 $unique,
295 (defined $table_schema ? _db2_quote_ident($table_schema) . '.' : '') . _db2_quote_ident($idx_name),
296 _db2_quote_table($table_name), $columns;
297 16 push @stmts, "$sql;";
298 }
299 }
300 }
301  
302 # The views go in the order of what they read (karr k54), as the diff creates
303 # them; a cycle throws before the script is returned.
304 26 my @view_stmts = map { sprintf 'CREATE VIEW %s AS %s;', _db2_quote_ident($_), $view_def{$_} }
305 order_views(\%view_def, $view_schema);
306  
307 22 return join "
308  
309 ", @stmts, @view_stmts;
310 }
311  
312  
313 51 my %CLAUSE_END = map { $_ => 1 } qw(
314 SELECT WHERE GROUP HAVING ORDER FETCH LIMIT OFFSET UNION INTERSECT EXCEPT WINDOW FOR WITH OPTIMIZE
315 );
316  
317 142 ▶sub _view_tokens {
Subroutine _view_tokens: called CC=10 SCAR=23.0
318 142 my ($text) = @_;
319 142 my @tok;
320 142 pos($text) = 0;
321 142 ▶ while (pos($text) < length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $text < length $text) 1857 142 1999
322 1857 ▶ if ($text =~ /\G\s+/gc) { }
Branch: 8 branches
BranchTrueFalseTotal
if ($text =~ /\G\s+/cg) { } 771 1086 1857
elsif ($text =~ m[\G/\*.*?\*/]cgs) { } 1 1085 1086
elsif ($text =~ /\G--[^\n]*/cg) { } 1 1084 1085
elsif ($text =~ /\G"((?:[^"]|"")*)"/cg) { } 222 862 1084
elsif ($text =~ /\G'(?:[^']|'')*'/cgs) { } 1 861 862
elsif ($text =~ /\G([\w\$#@]+)/cg) { } 689 172 861
elsif ($text =~ /\G([().,])/cg) { } 111 61 172
elsif ($text =~ /\G./cgs) { } 61 0 61
323 elsif ($text =~ m{\G/\*.*?\*/}gcs) { }
324 elsif ($text =~ /\G--[^\n]*/gc) { }
325 elsif ($text =~ /\G"((?:[^"]|"")*)"/gc) {
326 222 (my $n = $1) =~ s/""/"/g;
327 222 push @tok, [ id => $n ];
328 }
329 1 elsif ($text =~ /\G'(?:[^']|'')*'/gcs) { push @tok, [ str => '' ] }
330 689 elsif ($text =~ /\G([\w\$#@]+)/gc) { push @tok, [ word => $1 ] }
331 111 elsif ($text =~ /\G([().,])/gc) { push @tok, [ p => $1 ] }
332 61 elsif ($text =~ /\G./gcs) { push @tok, [ other => '' ] }
333 }
334 142 return @tok;
335 }
336  
337 68 ▶sub _tok_is_name { return $_[0] && ($_[0][0] eq 'id' || $_[0][0] eq 'word') }
Subroutine _tok_is_name: called CC=3 SCAR=13.1
Condition50%3/6
$_[0] && ($_[0][0] eq 'id' || $_[0][0] eq 'word')
!ll&&!rl&&r
0068
$_[0][0] eq "id" or $_[0][0] eq "word"
l!l&&r!l&&!r
17510
MC/DC0%0/3
$_[0] && ($_[0][0] eq 'id' || $_[0][0] eq 'word')
$_[0] $_[0][0] eq "id" $_[0][0] eq "word"
Truth table50%2/4
A && B or C
A= $_[0]B= $_[0][0] eq "id"C= $_[0][0] eq "word"
ABCresult
0XX0
1000
11X1
1011
338 187 ▶sub _tok_is_p { return $_[0] && $_[0][0] eq 'p' && $_[0][1] eq $_[1] }
Subroutine _tok_is_p: called CC=3 SCAR=11.1
Condition83%5/6
$_[0] && $_[0][0] eq 'p' && $_[0][1] eq $_[1]
!ll&&!rl&&r
764566
$_[0] and $_[0][0] eq "p"
!ll&&!rl&&r
076111
MC/DC66%2/3
$_[0] && $_[0][0] eq 'p' && $_[0][1] eq $_[1]
$_[0] $_[0][0] eq "p" $_[0][1] eq $_[1]
Truth table75%3/4
A and B && C
A= $_[0]B= $_[0][0] eq "p"C= $_[0][1] eq $_[1]
ABCresult
0XX0
10X0
1100
1111
339 222 ▶sub _tok_name { return $_[0][0] eq 'word' ? uc $_[0][1] : $_[0][1] }
Subroutine _tok_name: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0][0] eq 'word' ? : 83 139 222
340  
341 # The header of one CTE, $i at its name: name, optional column list, AS, and the
342 # opening parenthesis of the body. Returns ($name, $index_of_that_parenthesis), or
343 # the empty list when it does not read that way.
344 16 ▶sub _cte_header {
Subroutine _cte_header: called CC=11 SCAR=24.5
345 16 my ($tok, $i) = @_;
346 16 ▶ return unless _tok_is_name($tok->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless _tok_is_name($tok->[$i]) 0 16 16
347 16 my $name = _tok_name($tok->[$i++]);
348 16 ▶ if (_tok_is_p($tok->[$i], '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_tok_is_p($tok->[$i], "(")) 4 12 16
349 4 my $depth = 0;
350 4 ▶ while ($i < @$tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$tok) 14 0 14
351 14 my $x = $tok->[$i++];
352 14 ▶ $depth++ if _tok_is_p($x, '(');
Branch: 1 branch
BranchTrueFalseTotal
if _tok_is_p($x, "(") 4 10 14
353 14 ▶ last if _tok_is_p($x, ')') && !--$depth;
Branch: 1 branch
BranchTrueFalseTotal
if _tok_is_p($x, ")") and not --$depth 4 10 14
Condition66%2/3
_tok_is_p($x, ")") and not --$depth
!ll&&!rl&&r
1004
MC/DC50%1/2
_tok_is_p($x, ")") and not --$depth
_tok_is_p($x, ")") not --$depth
Truth table66%2/3
A and not(B)
A= _tok_is_p($x, ")")B= not --$depth
ABresult
0X0
100
111
354 }
355 }
356 16 ▶ return unless $tok->[$i] && $tok->[$i][0] eq 'word' && uc $tok->[$i][1] eq 'AS';
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->[$i] and $tok->[$i][0] eq "word" and uc $tok->[$i][1] eq "AS" 2 14 16
Condition50%3/6
$tok->[$i] and $tok->[$i][0] eq "word" and uc $tok->[$i][1] eq "AS"
!ll&&!rl&&r
0214
$tok->[$i] and $tok->[$i][0] eq "word"
!ll&&!rl&&r
0016
MC/DC33%1/3
$tok->[$i] and $tok->[$i][0] eq "word" and uc $tok->[$i][1] eq "AS"
$tok->[$i] $tok->[$i][0] eq "word" uc $tok->[$i][1] eq "AS"
Truth table50%2/4
A and B and C
A= $tok->[$i]B= $tok->[$i][0] eq "word"C= uc $tok->[$i][1] eq "AS"
ABCresult
0XX0
10X0
1100
1111
357 14 ▶ return unless _tok_is_p($tok->[$i + 1], '(');
Branch: 1 branch
BranchTrueFalseTotal
unless _tok_is_p($$tok[$i + 1], "(") 1 13 14
358 13 return ($name, $i + 1);
359 }
360  
361 # The reads of a definition as [ $qualifier_or_undef, $name ] pairs, in order of
362 # appearance, without repeats, the names of CTEs left out (see view_reads).
363 145 ▶sub _view_reads_q {
Subroutine _view_reads_q: called CC=52 SCAR=39.7
364 145 my ($def) = @_;
365 145 ▶ return () unless defined $def && length $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def and length $def 3 142 145
Condition66%2/3
defined $def and length $def
!ll&&!rl&&r
30142
MC/DC50%1/2
defined $def and length $def
defined $def length $def
Truth table66%2/3
A and B
A= defined $defB= length $def
ABresult
0X0
100
111
366 142 my @tok = _view_tokens($def);
367 142 my (@reads, %seen);
368  
369 # One frame per pair of parentheses. expect: the next token stands where a
370 # table is named; from: a comma does the same; select: this frame holds a
371 # SELECT, so its FROM is a table list (a FROM inside TRIM(...) is not); cte: the
372 # CTE names this frame's WITH clauses define; cte_body: the next parenthesis is
373 # the body of a CTE; cte_pending: a CTE body has just closed, a comma may bring
374 # the next one.
375 142 my @frames = ({ expect => 0, from => 0, select => 1, cte => {} });
376 142 ▶ my $is_cte = sub { my ($n) = @_; return scalar grep { $_->{cte}{$n} } @frames };
Subroutine __ANON__: called CC=1 SCAR=0.0
377 142 my $i = 0;
378 142 ▶ while ($i < @tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tok) 958 139 1097
379 958 my ($type, $val) = @{ $tok[$i] };
380 958 my $f = $frames[-1];
381 958 ▶ delete $f->{cte_pending} if $f->{cte_pending} && !($type eq 'p' && $val eq ',');
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"cte_pending"} and not $type eq "p" && $val eq "," 10 948 958
Condition83%5/6
$f->{"cte_pending"} and not $type eq "p" && $val eq ","
!ll&&!rl&&r
945310
$type eq 'p' && $val eq ','
!ll&&!rl&&r
1003
MC/DC66%2/3
$f->{"cte_pending"} and not $type eq "p" && $val eq ","
$f->{"cte_pending"} $type eq 'p' $val eq ','
Truth table75%3/4
A and not(B && C)
A= $f->{"cte_pending"}B= $type eq 'p'C= $val eq ','
ABCresult
0XX0
1110
10X1
1101
382 958 ▶ if ($type eq 'p' && $val eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq "(") 18 940 958
Condition100%3/3
$type eq "p" and $val eq "("
!ll&&!rl&&r
8934718
MC/DC100%2/2
$type eq "p" and $val eq "("
$type eq "p" $val eq "("
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq "("
ABresult
0X0
100
111
383 push @frames, {
384 expect => $f->{expect}, from => $f->{expect}, select => 0, cte => {},
385 18 ▶ ($f->{cte_body} ? (cte_parent => $f) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$f->{'cte_body'} ? : 13 5 18
386 };
387 18 delete $f->{cte_body};
388 18 $f->{expect} = 0;
389 18 $i++;
390 18 next;
391 }
392 940 ▶ if ($type eq 'p' && $val eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq ")") 18 922 940
Condition100%3/3
$type eq "p" and $val eq ")"
!ll&&!rl&&r
8932918
MC/DC100%2/2
$type eq "p" and $val eq ")"
$type eq "p" $val eq ")"
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq ")"
ABresult
0X0
100
111
393 18 ▶ if (@frames > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@frames > 1) 18 0 18
394 18 my $done = pop @frames;
395 18 ▶ $frames[-1]{cte_pending} = 1 if $done->{cte_parent};
Branch: 1 branch
BranchTrueFalseTotal
if $done->{"cte_parent"} 13 5 18
396 }
397 18 $i++;
398 18 next;
399 }
400 922 ▶ if ($type eq 'p' && $val eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p" and $val eq ",") 17 905 922
Condition100%3/3
$type eq "p" and $val eq ","
!ll&&!rl&&r
8931217
MC/DC100%2/2
$type eq "p" and $val eq ","
$type eq "p" $val eq ","
Truth table100%3/3
A and B
A= $type eq "p"B= $val eq ","
ABresult
0X0
100
111
401 17 ▶ if ($f->{cte_pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"cte_pending"}) 3 14 17
402 3 delete $f->{cte_pending};
403 3 my ($name, $open) = _cte_header(\@tok, $i + 1);
404 3 ▶ DBIO::Exception->throw('DBIO::DB2::DDL: a comma after a WITH clause body is not followed by '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 2 3
405 . 'a readable common table expression (name, optional column list, AS, body); the view '
406 . 'cannot be ordered by what it reads') unless defined $name;
407 2 $f->{cte}{$name} = 1;
408 2 $f->{cte_body} = 1;
409 2 $i = $open;
410 2 next;
411 }
412 14 ▶ $f->{expect} = $f->{from} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$f->{'from'} ? : 6 8 14
413 14 $i++;
414 14 next;
415 }
416 905 ▶ if ($type eq 'word') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "word") 627 278 905
417 627 my $kw = uc $val;
418 627 ▶ if ($kw eq 'WITH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "WITH") 15 612 627
419 15 my $n = $i + 1;
420 15 ▶ $n++ if $tok[$n] && $tok[$n][0] eq 'word' && uc $tok[$n][1] eq 'RECURSIVE';
Branch: 1 branch
BranchTrueFalseTotal
if $tok[$n] and $tok[$n][0] eq "word" and uc $tok[$n][1] eq "RECURSIVE" 0 15 15
Condition66%4/6
$tok[$n] and $tok[$n][0] eq "word" and uc $tok[$n][1] eq "RECURSIVE"
!ll&&!rl&&r
1140
$tok[$n] and $tok[$n][0] eq "word"
!ll&&!rl&&r
0114
MC/DC0%0/3
$tok[$n] and $tok[$n][0] eq "word" and uc $tok[$n][1] eq "RECURSIVE"
$tok[$n] $tok[$n][0] eq "word" uc $tok[$n][1] eq "RECURSIVE"
Truth table50%2/4
A and B and C
A= $tok[$n]B= $tok[$n][0] eq "word"C= uc $tok[$n][1] eq "RECURSIVE"
ABCresult
0XX0
10X0
1100
1111
421 15 ▶ if (_tok_is_name($tok[$n]) && $tok[$n + 1]
Branch: 1 branch
BranchTrueFalseTotal
if (_tok_is_name($tok[$n]) and $tok[$n + 1] and _tok_is_p($tok[$n + 1], "(") || $tok[$n + 1][0] eq "word" && uc $tok[$n + 1][1] eq "AS") 13 2 15
Condition83%10/12
_tok_is_name($tok[$n]) and $tok[$n + 1] and _tok_is_p($tok[$n + 1], "(") || $tok[$n + 1][0] eq "word" && uc $tok[$n + 1][1] eq "AS"
!ll&&!rl&&r
1113
_tok_is_name($tok[$n]) and $tok[$n + 1]
!ll&&!rl&&r
0114
_tok_is_p($tok[$n + 1], "(") or $tok[$n + 1][0] eq "word" and uc $tok[$n + 1][1] eq "AS"
l!l&&r!l&&!r
3101
$tok[$n + 1][0] eq "word" and uc $tok[$n + 1][1] eq "AS"
!ll&&!rl&&r
0110
MC/DC60%3/5
_tok_is_name($tok[$n]) and $tok[$n + 1] and _tok_is_p($tok[$n + 1], "(") || $tok[$n + 1][0] eq "word" && uc $tok[$n + 1][1] eq "AS"
_tok_is_name($tok[$n]) $tok[$n + 1] _tok_is_p($tok[$n + 1], "(") $tok[$n + 1][0] eq "word" uc $tok[$n + 1][1] eq "AS"
Truth table66%4/6
A and B and C or D and E
A= _tok_is_name($tok[$n])B= $tok[$n + 1]C= _tok_is_p($tok[$n + 1], "(")D= $tok[$n + 1][0] eq "word"E= uc $tok[$n + 1][1] eq "AS"
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
422 && (_tok_is_p($tok[$n + 1], '(') || ($tok[$n + 1][0] eq 'word' && uc $tok[$n + 1][1] eq 'AS'))) {
423 13 my ($name, $open) = _cte_header(\@tok, $n);
424 13 ▶ DBIO::Exception->throw(sprintf 'DBIO::DB2::DDL: the WITH clause names "%s" but is not a readable '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 11 13
425 . 'common table expression (name, optional column list, AS, body); the view cannot be '
426 . 'ordered by what it reads', _tok_name($tok[$n])) unless defined $name;
427 11 $f->{cte}{$name} = 1;
428 11 $f->{cte_body} = 1;
429 11 @$f{qw(from expect)} = (0, 0);
430 11 $i = $open;
431 11 next;
432 }
433 }
434 614 ▶ if ($kw eq 'FROM' && $f->{select}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "FROM" and $f->{"select"}) 156 458 614
Condition100%3/3
$kw eq "FROM" and $f->{"select"}
!ll&&!rl&&r
4571156
MC/DC100%2/2
$kw eq "FROM" and $f->{"select"}
$kw eq "FROM" $f->{"select"}
Truth table100%3/3
A and B
A= $kw eq "FROM"B= $f->{"select"}
ABresult
0X0
100
111
435 156 ▶ my $prev = $i && $tok[$i - 1][0] eq 'word' ? uc $tok[$i - 1][1] : '';
Branch: 1 branch
BranchTrueFalseTotal
$i && $tok[$i - 1][0] eq 'word' ? : 55 101 156
Condition66%2/3
$i and $tok[$i - 1][0] eq "word"
!ll&&!rl&&r
010155
MC/DC50%1/2
$i and $tok[$i - 1][0] eq "word"
$i $tok[$i - 1][0] eq "word"
Truth table66%2/3
A and B
A= $iB= $tok[$i - 1][0] eq "word"
ABresult
0X0
100
111
436 156 ▶ @$f{qw(from expect)} = (1, 1) unless $prev eq 'DISTINCT';
Branch: 1 branch
BranchTrueFalseTotal
unless $prev eq "DISTINCT" 155 1 156
437 156 $i++;
438 156 next;
439 }
440 458 ▶ if ($kw eq 'JOIN' && $f->{from}) { $f->{expect} = 1; $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "JOIN" and $f->{"from"}) 8 450 458
Condition66%2/3
$kw eq "JOIN" and $f->{"from"}
!ll&&!rl&&r
45008
MC/DC50%1/2
$kw eq "JOIN" and $f->{"from"}
$kw eq "JOIN" $f->{"from"}
Truth table66%2/3
A and B
A= $kw eq "JOIN"B= $f->{"from"}
ABresult
0X0
100
111
441 450 ▶ if ($CLAUSE_END{$kw}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CLAUSE_END{$kw}) 160 290 450
442 160 ▶ $f->{select} = 1 if $kw eq 'SELECT';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "SELECT" 155 5 160
443 160 @$f{qw(from expect)} = (0, 0);
444 160 $i++;
445 160 next;
446 }
447 }
448 568 ▶ if ($f->{expect} && ($type eq 'id' || $type eq 'word')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"expect"} and $type eq "id" || $type eq "word") 167 401 568
Condition66%4/6
$f->{"expect"} and $type eq "id" || $type eq "word"
!ll&&!rl&&r
4010167
$type eq "id" or $type eq "word"
l!l&&r!l&&!r
123440
MC/DC33%1/3
$f->{"expect"} and $type eq "id" || $type eq "word"
$f->{"expect"} $type eq "id" $type eq "word"
Truth table75%3/4
A and B or C
A= $f->{"expect"}B= $type eq "id"C= $type eq "word"
ABCresult
0XX0
1000
11X1
1011
449 # a (possibly qualified) name; the last part is the table, the one before it
450 # the schema
451 167 my @part = (_tok_name($tok[$i]));
452 167 $i++;
453 167 ▶ while ($i + 1 < @tok && _tok_is_p($tok[$i], '.') && _tok_is_name($tok[$i + 1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < @tok and _tok_is_p($tok[$i], ".") and _tok_is_name($tok[$i + 1])) 37 167 204
Condition83%5/6
$i + 1 < @tok and _tok_is_p($tok[$i], ".") and _tok_is_name($tok[$i + 1])
!ll&&!rl&&r
167037
$i + 1 < @tok and _tok_is_p($tok[$i], ".")
!ll&&!rl&&r
1283937
MC/DC66%2/3
$i + 1 < @tok and _tok_is_p($tok[$i], ".") and _tok_is_name($tok[$i + 1])
$i + 1 < @tok _tok_is_p($tok[$i], ".") _tok_is_name($tok[$i + 1])
Truth table75%3/4
A and B and C
A= $i + 1 < @tokB= _tok_is_p($tok[$i], ".")C= _tok_is_name($tok[$i + 1])
ABCresult
0XX0
10X0
1100
1111
454 37 push @part, _tok_name($tok[$i + 1]);
455 37 $i += 2;
456 }
457 167 my $name = pop @part;
458 167 ▶ my $qual = @part ? $part[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@part ? : 37 130 167
459 167 ▶ my $call = $i < @tok && _tok_is_p($tok[$i], '(');
Condition100%3/3
$i < @tok && _tok_is_p($tok[$i], '(')
!ll&&!rl&&r
128381
MC/DC100%2/2
$i < @tok && _tok_is_p($tok[$i], '(')
$i < @tok _tok_is_p($tok[$i], '(')
Truth table100%3/3
A && B
A= $i < @tokB= _tok_is_p($tok[$i], '(')
ABresult
0X0
100
111
460 167 ▶ unless ($call || (!defined $qual && $is_cte->($name)) || $seen{ ($qual // '') . "\0" . $name }++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($call or not defined $qual and &$is_cte($name) or $seen{($qual // "") . "\000" . $name}++) 154 13 167
Condition90%10/11
$call or not defined $qual and &$is_cte($name) or $seen{($qual // "") . "\000" . $name}++
l!l&&r!l&&!r
130154
$call or not defined $qual and &$is_cte($name)
l!l&&r!l&&!r
112154
not defined $qual and &$is_cte($name)
!ll&&!rl&&r
3711712
$qual // ""
l!l
37117
MC/DC75%3/4
$call or not defined $qual and &$is_cte($name) or $seen{($qual // "") . "\000" . $name}++
$call not defined $qual &$is_cte($name) $seen{($qual // "") . "\000" . $name}++
MC/DC100%1/1
$qual // ""
$qual
Truth table66%4/6
A or not(B) and C or D
A= $callB= not defined $qualC= &$is_cte($name)D= $seen{($qual // "") . "\000" . $name}++
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
Truth table100%2/2
A
A= $qual
Aresult
11
00
461 154 push @reads, [ $qual, $name ];
462 }
463 167 $f->{expect} = 0;
464 167 next;
465 }
466 401 $f->{expect} = 0;
467 401 $i++;
468 }
469 139 return @reads;
470 }
471  
472 24 ▶sub view_reads {
Subroutine view_reads: called CC=6 SCAR=18.0
Pod documented
473 24 my ($def, $schema) = @_;
474 24 my (@names, %seen);
475 24 for my $r (_view_reads_q($def)) {
476 31 my ($qual, $name) = @$r;
477 31 ▶ next if defined $schema && defined $qual && $qual ne $schema;
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and defined $qual and $qual ne $schema 1 30 31
Condition83%5/6
defined $schema and defined $qual and $qual ne $schema
!ll&&!rl&&r
2911
defined $schema and defined $qual
!ll&&!rl&&r
2902
MC/DC66%2/3
defined $schema and defined $qual and $qual ne $schema
defined $schema defined $qual $qual ne $schema
Truth table75%3/4
A and B and C
A= defined $schemaB= defined $qualC= $qual ne $schema
ABCresult
0XX0
10X0
1100
1111
478 30 ▶ push @names, $name unless $seen{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$name}++ 30 0 30
479 }
480 21 return @names;
481 }
482  
483  
484 121 ▶sub view_dependencies {
Subroutine view_dependencies: called CC=13 SCAR=25.6
Pod documented
485 121 my ($set, $name, $def, $schema) = @_;
486 121 my %in = map { $_ => 1 } @$set;
487 121 my %by_fold;
488 121 push @{ $by_fold{ lc $_ } }, $_ for @$set;
489  
490 121 my %dep;
491 121 for my $r (_view_reads_q($def)) {
492 122 my ($qual, $read) = @$r;
493 my $to = $in{$read} ? $read
494 122 ▶ : (@{ $by_fold{ lc $read } // [] } == 1 ? $by_fold{ lc $read }[0] : undef);
Branch: 2 branches
BranchTrueFalseTotal
$in{$read} ? : 54 68 122
@{$by_fold{lc $read} // [];} == 1 ? : 11 57 68
Condition100%2/2
$by_fold{lc $read} // []
l!l
1157
MC/DC100%1/1
$by_fold{lc $read} // []
$by_fold{lc $read}
Truth table100%2/2
A
A= $by_fold{lc $read}
Aresult
11
00
495 122 ▶ if (defined $qual) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qual) 31 91 122
496 31 ▶ if (defined $schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema) { } 22 9 31
497 22 ▶ next unless $qual eq $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $qual eq $schema 13 9 22
498 }
499 else {
500 9 ▶ DBIO::Exception->throw(sprintf
Branch: 1 branch
BranchTrueFalseTotal
if defined $to and $to ne $name 7 2 9
Condition100%3/3
defined $to and $to ne $name
!ll&&!rl&&r
117
MC/DC100%2/2
defined $to and $to ne $name
defined $to $to ne $name
Truth table100%3/3
A and B
A= defined $toB= $to ne $name
ABresult
0X0
100
111
501 'DBIO::DB2::DDL: the view %s reads %s.%s, and %s is a view of the same set; without the '
502 . 'schema the views are created in (not known here) it cannot be decided whether that is '
503 . 'this view or one of another schema, so no order is given. Write the read without the '
504 . 'qualifier, or give the schema',
505 _db2_quote_ident($name), _db2_quote_ident($qual), _db2_quote_ident($read), _db2_quote_ident($to))
506 if defined $to && $to ne $name;
507 2 next;
508 }
509 }
510 100 ▶ $dep{$to} = 1 if defined $to && $to ne $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $to and $to ne $name 48 52 100
Condition100%3/3
defined $to and $to ne $name
!ll&&!rl&&r
51148
MC/DC100%2/2
defined $to and $to ne $name
defined $to $to ne $name
Truth table100%3/3
A and B
A= defined $toB= $to ne $name
ABresult
0X0
100
111
511 }
512 114 return sort keys %dep;
513 }
514  
515  
516 376 ▶sub order_views {
Subroutine order_views: called CC=7 SCAR=19.5
Pod documented
517 376 my ($defs, $schema) = @_;
518 376 my @names = sort keys %$defs;
519  
520 376 my %reads;
521 376 for my $v (@names) {
522 99 $reads{$v} = [ view_dependencies(\@names, $v, $defs->{$v}, $schema) ];
523 }
524  
525 369 my (%out, @order);
526 369 my @todo = @names;
527 369 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 88 365 453
528 88 my ($pick) = grep { my $v = $_; !grep { !$out{$_} } @{ $reads{$v} } } @todo;
529 88 ▶ unless (defined $pick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pick) 4 84 88
530 my @cycle = grep {
531 4 my $v = $_;
532 8 my (%seen, @walk);
533 8 @walk = @{ $reads{$v} };
534 8 my $found;
535 8 ▶ while (defined(my $n = shift @walk)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $n = shift @walk)) 16 0 16
536 16 ▶ if ($n eq $v) { $found = 1; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq $v) 8 8 16
537 8 ▶ next if $seen{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$n}++ 0 8 8
538 8 push @walk, @{ $reads{$n} };
539 }
540 8 $found;
541 } @todo;
542 DBIO::Exception->throw(sprintf
543 'DBIO::DB2::DDL: the views %s read each other in a cycle (%s), no order creates them',
544 8 join(', ', map { _db2_quote_ident($_) } @cycle),
545 4 join('; ', map { my $v = $_; sprintf '%s reads %s', _db2_quote_ident($v),
546 8 join(', ', map { _db2_quote_ident($_) } grep { my $r = $_; grep { $_ eq $r } @cycle } @{ $reads{$v} }) } @cycle));
547 }
548 84 @todo = grep { $_ ne $pick } @todo;
549 84 $out{$pick} = 1;
550 84 push @order, $pick;
551 }
552 365 return @order;
553 }
554  
555 # True when Db2 would answer CREATE [UNIQUE] INDEX over @$columns with SQL0605W
556 # instead of making the index: an index of the same columns in the same order is
557 # already there ($existing = [ [ \@columns, $is_unique ], ... ] -- primary key,
558 # UNIQUE constraints and indexes alike). Measured live (Db2 12.1.5): a
559 # non-unique index is a duplicate of any such index, a UNIQUE one only of a
560 # unique one -- CREATE UNIQUE INDEX over the columns of a non-unique index is
561 # made, beside it. A different order or a longer/shorter sequence is no duplicate.
562 67 ▶sub _index_is_duplicate {
Subroutine _index_is_duplicate: called CC=8 SCAR=20.8
563 67 my ($columns, $unique, $existing) = @_;
564 67 ▶ return 0 unless @{ $columns || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$columns or [];} 1 66 67
Condition50%1/2
$columns || []
l!l
670
MC/DC0%0/1
$columns || []
$columns
Truth table50%1/2
A
A= $columns
Aresult
11
00
565 66 my $key = join "\0", @$columns;
566 66 ▶ for my $e (@{ $existing || [] }) {
Condition50%1/2
$existing || []
l!l
660
MC/DC0%0/1
$existing || []
$existing
Truth table50%1/2
A
A= $existing
Aresult
11
00
567 99 ▶ next unless join("\0", @{ $e->[0] }) eq $key;
Branch: 1 branch
BranchTrueFalseTotal
unless join("\0", @{$e->[0];}) eq $key 75 24 99
568 24 ▶ return 1 if $e->[1] || !$unique;
Branch: 1 branch
BranchTrueFalseTotal
if $e->[1] or not $unique 19 5 24
Condition100%3/3
$e->[1] or not $unique
l!l&&r!l&&!r
1365
MC/DC100%2/2
$e->[1] or not $unique
$e->[1] not $unique
Truth table100%3/3
A or not(B)
A= $e->[1]B= not $unique
ABresult
1X1
011
000
569 }
570 47 return 0;
571 }
572  
573 # The unique constraints of a source as [ $name, \@columns ] pairs in name
574 # order, 'primary' (set_primary_key's, already PRIMARY KEY) left out. Db2 refuses
575 # a UNIQUE constraint over a nullable column (SQL0542N), so one is refused here
576 # with table and column named, before any statement runs. A column without
577 # is_nullable is NOT NULL (ADR 0043), as in the column loop of install_ddl.
578 37 ▶sub _table_unique_constraints {
Subroutine _table_unique_constraints: called CC=4 SCAR=13.9
579 37 my ($source, $table_name) = @_;
580 37 ▶ return unless $source->can('unique_constraints');
Branch: 1 branch
BranchTrueFalseTotal
unless $source->can("unique_constraints") 0 37 37
581 37 my %uniques = $source->unique_constraints;
582 37 my @out;
583 37 for my $name (sort keys %uniques) {
584 41 ▶ next if $name eq 'primary';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "primary" 36 5 41
585 5 my @cols = @{ $uniques{$name} };
586 _refuse_nullable_unique($table_name, $name,
587 5 [ grep { $source->column_info($_)->{is_nullable} } @cols ]);
588 4 push @out, [ $name, \@cols ];
589 }
590 36 return @out;
591 }
592  
593 # Croaks naming table, constraint and the nullable columns, when there are any.
594 8 ▶sub _refuse_nullable_unique {
Subroutine _refuse_nullable_unique: called CC=3 SCAR=11.0
595 8 my ($table, $name, $nullable) = @_;
596 8 ▶ return unless @$nullable;
Branch: 1 branch
BranchTrueFalseTotal
unless @$nullable 6 2 8
597 croak sprintf
598 'DBIO::DB2::DDL: UNIQUE constraint "%s" on table "%s" includes nullable column%s %s; '
599 . 'Db2 refuses it (SQL0542N). Declare the column NOT NULL (leave is_nullable out), '
600 . 'or use a unique db2_indexes entry instead',
601 $name, $table, (@$nullable > 1 ? 's' : ''),
602 2 ▶ join(', ', map { qq{"$_"} } @$nullable);
Branch: 1 branch
BranchTrueFalseTotal
@$nullable > 1 ? : 0 2 2
603 }
604  
605 # CONSTRAINT <name> UNIQUE (<cols>) -- the one clause shape, for install_ddl and
606 # DBIO::DB2::Diff::Table (inline, indented there) and
607 # DBIO::DB2::Diff::UniqueConstraint (ALTER TABLE ... ADD <clause>).
608 8 ▶sub _unique_constraint_clause {
Subroutine _unique_constraint_clause: called CC=1 SCAR=0.0
609 8 my ($name, $columns) = @_;
610 return sprintf 'CONSTRAINT %s UNIQUE (%s)', _db2_quote_ident($name),
611 8 join(', ', map { _db2_quote_ident($_) } @$columns);
612 }
613  
614 235 ▶sub _resolve_table_name {
Subroutine _resolve_table_name: called CC=5 SCAR=28.8
615 235 my ($name) = @_;
616 235 ▶ return $name unless ref $name;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $name 235 0 235
617 0 ▶ return undef unless ref $name eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $name eq "SCALAR" 0 0 0
618 0 my $v = $$name;
619 0 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
620 0 ▶ return $v if $v =~ /\A\w+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A\w+\z/ 0 0 0
621 0 return undef;
622 }
623  
624 # Deterministic constraint name for an FK, derived from the owning table and
625 # its local columns: fk_<table>_<col1>_<col2>. Stable across the live DB and
626 # the throwaway compare schema (both built from this same DDL), which is what
627 # makes the name-based FK diff sound (ADR 0005).
628 10 ▶sub _fk_constraint_name {
Subroutine _fk_constraint_name: called CC=1 SCAR=0.0
629 10 my ($table, $from_cols) = @_;
630 10 return join '_', 'fk', $table, @$from_cols;
631 }
632  
633 # Single source of truth for the inline foreign-key clause shape (ADR 0005):
634 # CONSTRAINT <name> FOREIGN KEY (<from>) REFERENCES <to>(<to_cols>)
635 # [ON DELETE <rule>] [ON UPDATE <rule>]
636 # Returned WITHOUT leading indent and WITHOUT an ALTER TABLE ... ADD prefix, so
637 # install_ddl (inline, indented), DBIO::DB2::Diff::Table (inline, indented) and
638 # DBIO::DB2::Diff::ForeignKey (ALTER TABLE ... ADD <clause>) all render the same
639 # body. NO ACTION rules are suppressed (DB2's implicit default). The name comes
640 # straight from the model -- callers must NOT regenerate it.
641 20 ▶sub _fk_constraint_clause {
Subroutine _fk_constraint_clause: called CC=5 SCAR=16.2
642 20 my ($fk) = @_;
643 my $sql = sprintf 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)',
644 _db2_quote_ident($fk->{constraint_name}),
645 20 join(', ', map { _db2_quote_ident($_) } @{ $fk->{from_columns} }),
646 _db2_quote_table($fk->{to_table}),
647 20 join(', ', map { _db2_quote_ident($_) } @{ $fk->{to_columns} });
648 $sql .= " ON DELETE $fk->{on_delete}"
649 20 ▶ if $fk->{on_delete} && $fk->{on_delete} ne 'NO ACTION';
Branch: 1 branch
BranchTrueFalseTotal
if $fk->{"on_delete"} and $fk->{"on_delete"} ne "NO ACTION" 8 12 20
Condition100%3/3
$fk->{"on_delete"} and $fk->{"on_delete"} ne "NO ACTION"
!ll&&!rl&&r
758
MC/DC100%2/2
$fk->{"on_delete"} and $fk->{"on_delete"} ne "NO ACTION"
$fk->{"on_delete"} $fk->{"on_delete"} ne "NO ACTION"
Truth table100%3/3
A and B
A= $fk->{"on_delete"}B= $fk->{"on_delete"} ne "NO ACTION"
ABresult
0X0
100
111
650 $sql .= " ON UPDATE $fk->{on_update}"
651 20 ▶ if $fk->{on_update} && $fk->{on_update} ne 'NO ACTION';
Branch: 1 branch
BranchTrueFalseTotal
if $fk->{"on_update"} and $fk->{"on_update"} ne "NO ACTION" 0 20 20
Condition66%2/3
$fk->{"on_update"} and $fk->{"on_update"} ne "NO ACTION"
!ll&&!rl&&r
8120
MC/DC0%0/2
$fk->{"on_update"} and $fk->{"on_update"} ne "NO ACTION"
$fk->{"on_update"} $fk->{"on_update"} ne "NO ACTION"
Truth table66%2/3
A and B
A= $fk->{"on_update"}B= $fk->{"on_update"} ne "NO ACTION"
ABresult
0X0
100
111
652 20 return $sql;
653 }
654  
655 # Collect the named foreign keys for one source, derived from its belongs_to
656 # relationships. Mirrors the column extraction in DBIO::MySQL::DDL: a FK cond
657 # is { "foreign.<refcol>" => "self.<localcol>" }.
658 33 ▶sub _table_foreign_keys {
Subroutine _table_foreign_keys: called CC=13 SCAR=27.1
659 33 my ($schema, $source) = @_;
660  
661 33 my $table_name = _resolve_table_name($source->name);
662 33 my @fks;
663 my %seen_name;
664  
665 33 for my $rel ($source->relationships) {
666 15 my $info = $source->relationship_info($rel);
667 next unless $info && $info->{attrs}
668 15 ▶ && $info->{attrs}{is_foreign_key_constraint};
Branch: 1 branch
BranchTrueFalseTotal
unless $info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"} 5 10 15
Condition50%3/6
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
!ll&&!rl&&r
0510
$info and $info->{"attrs"}
!ll&&!rl&&r
0015
MC/DC33%1/3
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
$info $info->{"attrs"} $info->{"attrs"}{"is_foreign_key_constraint"}
Truth table50%2/4
A and B and C
A= $infoB= $info->{"attrs"}C= $info->{"attrs"}{"is_foreign_key_constraint"}
ABCresult
0XX0
10X0
1100
1111
669  
670 10 my $foreign = $info->{class};
671 10 my $fs = eval { $schema->source($foreign) }
672 0 ▶ // eval { $schema->source($foreign =~ s/.*:://r) };
Condition33%1/3
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
l!l&&r!l&&!r
1000
MC/DC0%0/2
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
eval { do { $schema->source($foreign) } } eval { do { $schema->source($foreign =~ s/.*:://r) } }
Truth table33%1/3
A // B
A= eval { do { $schema->source($foreign) } }B= eval { do { $schema->source($foreign =~ s/.*:://r) } }
ABresult
1X1
011
000
673 10 ▶ next unless $fs;
Branch: 1 branch
BranchTrueFalseTotal
unless $fs 0 10 10
674  
675 10 my $cond = $info->{cond};
676 10 ▶ next unless ref $cond eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cond eq "HASH" 0 10 10
677  
678 10 my (@from, @to);
679 10 for my $foreign_col (sort keys %$cond) {
680 10 my $fcol = $foreign_col;
681 10 $fcol =~ s/^foreign\.//;
682 10 my $self_col = $cond->{$foreign_col};
683 10 $self_col =~ s/^self\.//;
684 10 push @to, $fcol;
685 10 push @from, $self_col;
686 }
687 10 ▶ next unless @from;
Branch: 1 branch
BranchTrueFalseTotal
unless @from 0 10 10
688  
689 10 my $foreign_name = _resolve_table_name($fs->name);
690 10 ▶ next unless defined $foreign_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $foreign_name 0 10 10
691  
692 # The deterministic name keys on the local columns, so two relationships
693 # over the same column(s) would collide (DB2 rejects a duplicate constraint
694 # name, and the name-based diff needs one identity per name). Keep the
695 # first; a single FK per column-set is the normal case and is untouched.
696 10 my $name = _fk_constraint_name((_split_table_name($table_name))[1], \@from);
697 10 ▶ next if $seen_name{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_name{$name}++ 0 10 10
698  
699 10 ▶ my $attrs = $info->{attrs} || {};
Condition50%1/2
$info->{'attrs'} || {}
l!l
100
MC/DC0%0/1
$info->{'attrs'} || {}
$info->{'attrs'}
Truth table50%1/2
A
A= $info->{'attrs'}
Aresult
11
00
700 push @fks, {
701 constraint_name => $name,
702 from_columns => \@from,
703 to_table => $foreign_name,
704 to_columns => \@to,
705 on_delete => $attrs->{on_delete},
706 on_update => $attrs->{on_update},
707 10 };
708 }
709  
710 33 return @fks;
711 }
712  
713 31 ▶sub _topo_sort_sources {
Subroutine _topo_sort_sources: called CC=17 SCAR=30.3
714 31 my ($schema) = @_;
715  
716 31 my %deps;
717 my %by_table;
718 31 my @sources = sort $schema->sources;
719  
720 31 for my $name (@sources) {
721 58 my $s = $schema->source($name);
722 58 my $t = _resolve_table_name($s->name);
723 58 ▶ next unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 58 58
724 58 ▶ $by_table{$t} //= $name;
Condition33%1/3
$by_table{$t} //= $name
l!l&&r!l&&!r
0580
MC/DC0%0/2
$by_table{$t} //= $name
$by_table{$t} $name
Truth table33%1/3
A //= B
A= $by_table{$t}B= $name
ABresult
1X1
011
000
725 }
726  
727 31 for my $name (@sources) {
728 58 my $s = $schema->source($name);
729 58 ▶ next unless defined _resolve_table_name($s->name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined _resolve_table_name($s->name) 0 58 58
730 58 ▶ $deps{$name} ||= {};
Condition50%1/2
$deps{$name} ||= {}
l!l
058
MC/DC0%0/1
$deps{$name} ||= {}
$deps{$name}
Truth table50%1/2
A
A= $deps{$name}
Aresult
11
00
731 58 for my $rel ($s->relationships) {
732 14 my $info = $s->relationship_info($rel);
733 next unless $info && $info->{attrs}
734 14 ▶ && $info->{attrs}{is_foreign_key_constraint};
Branch: 1 branch
BranchTrueFalseTotal
unless $info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"} 5 9 14
Condition50%3/6
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
!ll&&!rl&&r
059
$info and $info->{"attrs"}
!ll&&!rl&&r
0014
MC/DC33%1/3
$info and $info->{"attrs"} and $info->{"attrs"}{"is_foreign_key_constraint"}
$info $info->{"attrs"} $info->{"attrs"}{"is_foreign_key_constraint"}
Truth table50%2/4
A and B and C
A= $infoB= $info->{"attrs"}C= $info->{"attrs"}{"is_foreign_key_constraint"}
ABCresult
0XX0
10X0
1100
1111
735 9 my $foreign = $info->{class};
736 9 my $fs = eval { $schema->source($foreign) }
737 0 ▶ // eval { $schema->source($foreign =~ s/.*:://r) };
Condition33%1/3
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
l!l&&r!l&&!r
900
MC/DC0%0/2
eval { do { $schema->source($foreign) } } // eval { do { $schema->source($foreign =~ s/.*:://r) } }
eval { do { $schema->source($foreign) } } eval { do { $schema->source($foreign =~ s/.*:://r) } }
Truth table33%1/3
A // B
A= eval { do { $schema->source($foreign) } }B= eval { do { $schema->source($foreign =~ s/.*:://r) } }
ABresult
1X1
011
000
738 9 ▶ next unless $fs;
Branch: 1 branch
BranchTrueFalseTotal
unless $fs 0 9 9
739 9 my $ft = _resolve_table_name($fs->name);
740 9 ▶ next unless defined $ft;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ft 0 9 9
741 9 my $owner = $by_table{$ft};
742 9 ▶ next unless $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless $owner 0 9 9
743 9 ▶ next if $owner eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $owner eq $name 0 9 9
744 9 $deps{$name}{$owner} = 1;
745 }
746 }
747  
748 31 my @out;
749 my %visited;
750 31 my $visit;
751 67 ▶ $visit = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
752 67 my ($n) = @_;
753 67 ▶ return if $visited{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if $visited{$n}++ 9 58 67
754 58 ▶ for my $d (sort keys %{ $deps{$n} || {} }) {
Condition50%1/2
$deps{$n} || {}
l!l
580
MC/DC0%0/1
$deps{$n} || {}
$deps{$n}
Truth table50%1/2
A
A= $deps{$n}
Aresult
11
00
755 9 $visit->($d);
756 }
757 58 push @out, $n;
758 31 };
759 31 $visit->($_) for @sources;
760 31 return @out;
761 }
762  
763 51 1;
764  
765 __END__
« DB2/Diff/Index.pm ↑ Summary DB2/Type.pm »