Oracle/Test/Conformance.pm

filter: Statementstmt 14.9% 44 / 295 Branchbran 2.2% 2 / 90 Conditioncond 2.2% 2 / 90 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 42.4% 14 / 33 Podpod 100% 11 / 11 totaltotal 12.8% 73 / 567 CC 102 SCAR 52.4
CC
102
Cov
10%
conformance_fact
650.0
_drop_foreign_objects
210.0
_drop_own_objects
132.0
CRAP 189.6
« Oracle/Introspect/Columns.pm ↑ Summary Oracle/Storage/AutoIncrement.pm »
1 package DBIO::Oracle::Test::Conformance;
2 # ABSTRACT: Answers the shared conformance case table for the Oracle driver
3  
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our $VERSION = '0.900007';
8  
9 11 ▶use base 'DBIO::Test::Conformance';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use DBI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use DBIO::Oracle::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use DBIO::Oracle::DDL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use DBIO::Oracle::Deploy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use DBIO::Oracle::Identifier ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 # schema class => the objects the user owned before the case
20 11 my %BEFORE;
21  
22 # schema class => { schema => the objects that schema owned before the case },
23 # for the schemas a declaration with a 'schema.table' source writes to
24 my %FOREIGN_BEFORE;
25  
26 # Objects the cleanup drops, in the order it drops them. INDEX and TRIGGER go
27 # with their table; they are listed so that one left behind is found.
28 11 my @DROP_ORDER = qw(VIEW TABLE SEQUENCE TRIGGER INDEX);
29  
30  
31 16 ▶sub conformance_live_available {
Subroutine conformance_live_available: called CC=4 SCAR=22.5
Pod documented
32 16 ▶ return 0 unless length($ENV{DBIO_TEST_ORA_DSN} // '');
Branch: 1 branch
BranchTrueFalseTotal
unless length($ENV{"DBIO_TEST_ORA_DSN"} // "") 16 0 16
Condition50%1/2
$ENV{"DBIO_TEST_ORA_DSN"} // ""
l!l
016
MC/DC0%0/1
$ENV{"DBIO_TEST_ORA_DSN"} // ""
$ENV{"DBIO_TEST_ORA_DSN"}
Truth table50%1/2
A
A= $ENV{"DBIO_TEST_ORA_DSN"}
Aresult
11
00
33 0 ▶ return eval { require DBD::Oracle; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DBD::Oracle; 1 } } ? : 0 0 0
34 }
35  
36  
37 0 ▶sub conformance_connect {
Subroutine conformance_connect: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($class, $schema_class) = @_;
39 0 $schema_class->load_components('Oracle');
40 return $schema_class->connect(
41 0 @ENV{qw(DBIO_TEST_ORA_DSN DBIO_TEST_ORA_USER DBIO_TEST_ORA_PASS)},
42 { AutoCommit => 1, RaiseError => 1, PrintError => 0 },
43 );
44 }
45  
46 # The objects the connected user owns, as { "TYPE\0NAME" => [ type, name ] }.
47 # The recycle bin is left out: those are Oracle's, not a case's.
48 0 ▶sub _owned_objects {
Subroutine _owned_objects: not called CC=2 SCAR=17.9
49 0 my ($class, $dbh) = @_;
50 0 my %owned;
51 0 my $rows = $dbh->selectall_arrayref(
52 q{SELECT object_type, object_name FROM user_objects
53 WHERE object_name NOT LIKE 'BIN$%'});
54 0 $owned{"$_->[0]\0$_->[1]"} = [ @$_ ] for @$rows;
55 0 return \%owned;
56 }
57  
58  
59 0 ▶sub conformance_namespace {
Subroutine conformance_namespace: not called CC=3 SCAR=24.8
Pod documented
60 0 my ($class, $schema, $case) = @_;
61 0 my $dbh = $schema->storage->dbh;
62 0 my $owned = $class->_owned_objects($dbh);
63 0 $BEFORE{ ref $schema } = $owned;
64 # a table in another schema (karr k58, a source 'schema.table') is made
65 # there: what that schema owns now is recorded as well
66 0 ▶ my $own = eval { DBIO::Oracle::DDL->declared_objects($schema) } || {};
Condition0%0/2
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } } || {}
l!l
00
MC/DC0%0/1
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } } || {}
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } }
Truth table0%0/2
A
A= eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } }
Aresult
11
00
67 $FOREIGN_BEFORE{ ref $schema } = {
68 0 ▶ map { $_ => $class->_owned_in($dbh, $_) } keys %{ $own->{schema} || {} }
Condition0%0/2
$own->{'schema'} || {}
l!l
00
MC/DC0%0/1
$own->{'schema'} || {}
$own->{'schema'}
Truth table0%0/2
A
A= $own->{'schema'}
Aresult
11
00
69 };
70 0 return $owned;
71 }
72  
73 # The objects of the schema (user) $owner as { "TYPE\0NAME" => [ type, name ] },
74 # as far as the connected user sees them.
75 0 ▶sub _owned_in {
Subroutine _owned_in: not called CC=2 SCAR=17.9
76 0 my ($class, $dbh, $owner) = @_;
77 0 my %owned;
78 0 my $rows = $dbh->selectall_arrayref(
79 q{SELECT object_type, object_name FROM all_objects
80 WHERE owner = ? AND object_name NOT LIKE 'BIN$%'}, undef, $owner);
81 0 $owned{"$_->[0]\0$_->[1]"} = [ @$_ ] for @$rows;
82 0 return \%owned;
83 }
84  
85  
86 0 ▶sub conformance_install {
Subroutine conformance_install: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($class, $schema, $case) = @_;
88 0 $schema->deploy;
89 0 return;
90 }
91  
92  
93 0 ▶sub conformance_cleanup {
Subroutine conformance_cleanup: not called CC=9 SCAR=45.0
Pod documented
94 0 my ($class, $schema, $case, $namespace) = @_;
95 0 my $before = delete $BEFORE{ ref $schema };
96 0 ▶ $before //= $namespace;
Condition0%0/3
$before //= $namespace
l!l&&r!l&&!r
000
MC/DC0%0/2
$before //= $namespace
$before $namespace
Truth table0%0/3
A //= B
A= $beforeB= $namespace
ABresult
1X1
011
000
97  
98 0 my $storage = $schema->storage;
99 0 my $error;
100 0 ▶ if ($before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before) 0 0 0
101 # What the case declared. A declaration the driver refuses was never sent
102 # to the server, so there is nothing of it to drop.
103 0 ▶ my $own = eval { DBIO::Oracle::DDL->declared_objects($schema) } || {};
Condition0%0/2
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } } || {}
l!l
00
MC/DC0%0/1
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } } || {}
eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } }
Truth table0%0/2
A
A= eval { do { 'DBIO::Oracle::DDL'->declared_objects($schema) } }
Aresult
11
00
104 0 my $dbh = eval { $storage->dbh };
105 0 my $mine;
106 0 ▶ unless ($dbh and eval { $dbh->ping }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh and eval { do { $dbh->ping } }) 0 0 0
Condition0%0/3
$dbh and eval { do { $dbh->ping } }
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh and eval { do { $dbh->ping } }
$dbh eval { do { $dbh->ping } }
Truth table0%0/3
A and B
A= $dbhB= eval { do { $dbh->ping } }
ABresult
0X0
100
111
107 $dbh = $mine = DBI->connect(
108 0 @ENV{qw(DBIO_TEST_ORA_DSN DBIO_TEST_ORA_USER DBIO_TEST_ORA_PASS)},
109 { RaiseError => 1, PrintError => 0, AutoCommit => 1 });
110 }
111 0 $error = $class->_drop_own_objects($dbh, $before, $own);
112 my $foreign = $class->_drop_foreign_objects(
113 0 $dbh, delete $FOREIGN_BEFORE{ ref $schema }, $own);
114 0 $error = join '; ', grep { defined } $error, $foreign;
115 0 ▶ $error = undef unless length $error;
Branch: 1 branch
BranchTrueFalseTotal
unless length $error 0 0 0
116 0 ▶ $mine->disconnect if $mine;
Branch: 1 branch
BranchTrueFalseTotal
if $mine 0 0 0
117 }
118 0 $storage->disconnect;
119 0 ▶ DBIO::Exception->throw("conformance: cleanup left objects behind: $error")
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
120 if defined $error;
121 0 return;
122 }
123  
124 # The new objects of the user that the declaration names, as { key => [ type,
125 # name ] } with the key of _owned_objects, and the new objects it does not.
126 0 ▶sub _new_objects {
Subroutine _new_objects: not called CC=10 SCAR=47.0
127 0 my ($class, $dbh, $before, $own) = @_;
128 0 my $now = $class->_owned_objects($dbh);
129 0 ▶ my %name = map { my $type = $_; ($type => { map { $_ => 1 } @{ $own->{$type} || [] } }) }
Condition0%0/2
$own->{$type} || []
l!l
00
MC/DC0%0/1
$own->{$type} || []
$own->{$type}
Truth table0%0/2
A
A= $own->{$type}
Aresult
11
00
130 qw(table view sequence trigger);
131 0 ▶ my %index_table = map { @$_ } @{ $own->{index} || [] };
Condition0%0/2
$own->{'index'} || []
l!l
00
MC/DC0%0/1
$own->{'index'} || []
$own->{'index'}
Truth table0%0/2
A
A= $own->{'index'}
Aresult
11
00
132 0 my %table_of = map { @$_ } @{ $dbh->selectall_arrayref(
133 q{SELECT index_name, table_name FROM user_indexes}) };
134  
135 0 my (@mine, @foreign);
136 0 for my $key (sort keys %$now) {
137 0 ▶ next if $before->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $before->{$key} 0 0 0
138 0 my ($type, $obj) = @{ $now->{$key} };
139 my $is_mine = $type eq 'INDEX'
140 ? (exists $index_table{$obj} && ($table_of{$obj} // '') eq $index_table{$obj})
141 0 ▶ : ($name{ lc $type } && $name{ lc $type }{$obj});
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'INDEX' ? : 0 0 0
Condition0%0/8
exists $index_table{$obj} and ($table_of{$obj} // "") eq $index_table{$obj}
!ll&&!rl&&r
000
$table_of{$obj} // ""
l!l
00
$name{lc $type} and $name{lc $type}{$obj}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $index_table{$obj} and ($table_of{$obj} // "") eq $index_table{$obj}
exists $index_table{$obj} $table_of{$obj}
MC/DC0%0/2
$name{lc $type} and $name{lc $type}{$obj}
$name{lc $type} $name{lc $type}{$obj}
Truth table0%0/3
A and B
A= exists $index_table{$obj}B= $table_of{$obj}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $name{lc $type}B= $name{lc $type}{$obj}
ABresult
0X0
100
111
142 0 ▶ push @{ $is_mine ? \@mine : \@foreign }, $now->{$key};
Branch: 1 branch
BranchTrueFalseTotal
$is_mine ? : 0 0 0
143 }
144 0 return (\@mine, \@foreign);
145 }
146  
147 0 ▶sub _drop_own_objects {
Subroutine _drop_own_objects: not called CC=11 SCAR=48.8
148 0 my ($class, $dbh, $before, $own) = @_;
149 0 my @failed;
150 0 for my $round (1 .. 2) {
151 0 my ($mine) = $class->_new_objects($dbh, $before, $own);
152 0 ▶ last unless @$mine;
Branch: 1 branch
BranchTrueFalseTotal
unless @$mine 0 0 0
153 0 for my $type (@DROP_ORDER) {
154 0 for my $object (grep { $_->[0] eq $type } @$mine) {
155 0 (my $q = $object->[1]) =~ s/"/""/g;
156 0 ▶ my $sql = $type eq 'TABLE'
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'TABLE' ? : 0 0 0
157 ? qq{DROP TABLE "$q" CASCADE CONSTRAINTS PURGE}
158 : qq{DROP $type "$q"};
159 # a trigger or an index may have gone with its table
160 0 my $done = eval { $dbh->do($sql); 1 };
161 0 ▶ push @failed, "$sql ($@)" if !$done and $round == 2;
Branch: 1 branch
BranchTrueFalseTotal
if not $done and $round == 2 0 0 0
Condition0%0/3
not $done and $round == 2
!ll&&!rl&&r
000
MC/DC0%0/2
not $done and $round == 2
not $done $round == 2
Truth table0%0/3
not(A) and B
A= not $doneB= $round == 2
ABresult
0X0
100
111
162 }
163 }
164 }
165 0 my ($left, $foreign) = $class->_new_objects($dbh, $before, $own);
166 0 ▶ $class->_report_foreign($foreign) if @$foreign;
Branch: 1 branch
BranchTrueFalseTotal
if @$foreign 0 0 0
167 0 ▶ return undef unless @$left;
Branch: 1 branch
BranchTrueFalseTotal
unless @$left 0 0 0
168 0 ▶ return join(', ', map { "$_->[0] $_->[1]" } @$left)
Branch: 1 branch
BranchTrueFalseTotal
@failed ? : 0 0 0
169 . (@failed ? ' -- ' . join('; ', @failed) : '');
170 }
171  
172 # The objects a declaration made in other schemas (karr k58): in each schema
173 # the declaration writes to, those that are new since the case began and whose
174 # names the declaration gives -- the same rule as for the user's own schema.
175 # Returns the objects left, as text, or undef.
176 0 ▶sub _drop_foreign_objects {
Subroutine _drop_foreign_objects: not called CC=14 SCAR=53.5
177 0 my ($class, $dbh, $before, $own) = @_;
178 0 my @left;
179 0 ▶ for my $owner (sort keys %{ $own->{schema} || {} }) {
Condition0%0/2
$own->{'schema'} || {}
l!l
00
MC/DC0%0/1
$own->{'schema'} || {}
$own->{'schema'}
Truth table0%0/2
A
A= $own->{'schema'}
Aresult
11
00
180 0 my $decl = $own->{schema}{$owner};
181 0 ▶ my $was = ($before || {})->{$owner} || {};
Condition0%0/4
+($before || {})->{$owner} || {}
l!l
00
$before || {}
l!l
00
MC/DC0%0/1
+($before || {})->{$owner} || {}
$before
Truth table0%0/2
A
A= $before
Aresult
11
00
182 0 ▶ my %name = map { my $t = $_; ($t => { map { $_ => 1 } @{ $decl->{$t} || [] } }) }
Condition0%0/2
$decl->{$t} || []
l!l
00
MC/DC0%0/1
$decl->{$t} || []
$decl->{$t}
Truth table0%0/2
A
A= $decl->{$t}
Aresult
11
00
183 qw(table view sequence trigger);
184 0 ▶ $name{index} = { map { $_->[0] => 1 } @{ $decl->{index} || [] } };
Condition0%0/2
$decl->{'index'} || []
l!l
00
MC/DC0%0/1
$decl->{'index'} || []
$decl->{'index'}
Truth table0%0/2
A
A= $decl->{'index'}
Aresult
11
00
185  
186 0 ▶ my $mine = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
187 0 my $now = $class->_owned_in($dbh, $owner);
188 0 ▶ return grep { $name{ lc $_->[0] } && $name{ lc $_->[0] }{ $_->[1] } }
Condition0%0/3
$name{lc $_->[0]} && $name{lc $_->[0]}{$_->[1]}
!ll&&!rl&&r
000
MC/DC0%0/2
$name{lc $_->[0]} && $name{lc $_->[0]}{$_->[1]}
$name{lc $_->[0]} $name{lc $_->[0]}{$_->[1]}
Truth table0%0/3
A && B
A= $name{lc $_->[0]}B= $name{lc $_->[0]}{$_->[1]}
ABresult
0X0
100
111
189 0 map { $now->{$_} } grep { !$was->{$_} } sort keys %$now;
190 0 };
191 0 for my $round (1 .. 2) {
192 0 ▶ my @objects = $mine->() or last;
Branch: 1 branch
BranchTrueFalseTotal
my(@objects) = &$mine() or last 0 0 0
193 0 for my $type (@DROP_ORDER) {
194 0 for my $object (grep { $_->[0] eq $type } @objects) {
195 0 ▶ my $sql = sprintf '%s %s%s', ($type eq 'TABLE' ? 'DROP TABLE' : "DROP $type"),
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'TABLE' ? : 0 0 0
$type eq 'TABLE' ? : 0 0 0
196 DBIO::Oracle::Identifier::quote_in("$owner.x", $object->[1]),
197 ($type eq 'TABLE' ? ' CASCADE CONSTRAINTS PURGE' : '');
198 0 eval { $dbh->do($sql); 1 };
199 }
200 }
201 }
202 0 push @left, map { "$_->[0] $owner.$_->[1]" } $mine->();
203 }
204 0 ▶ return @left ? join(', ', @left) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@left ? : 0 0 0
205 }
206  
207 # Objects that are new but not the case's: told, never dropped.
208 0 ▶sub _report_foreign {
Subroutine _report_foreign: not called CC=1 SCAR=6.9
209 0 my ($class, $foreign) = @_;
210 0 require Test::More;
211 Test::More::diag('conformance: left alone, new in the user\'s schema but not '
212 0 . 'declared by the case: ' . join(', ', map { "$_->[0] $_->[1]" } @$foreign));
213 0 return;
214 }
215  
216  
217 0 ▶sub conformance_diff_is_empty {
Subroutine conformance_diff_is_empty: not called CC=11 SCAR=48.8
Pod documented
218 0 my ($class, $schema, $case) = @_;
219  
220 0 my $diff = DBIO::Oracle::Deploy->new(schema => $schema)->diff;
221 0 ▶ return 1 unless $diff && $diff->has_changes;
Branch: 1 branch
BranchTrueFalseTotal
unless $diff and $diff->has_changes 0 0 0
Condition0%0/3
$diff and $diff->has_changes
!ll&&!rl&&r
000
MC/DC0%0/2
$diff and $diff->has_changes
$diff $diff->has_changes
Truth table0%0/3
A and B
A= $diffB= $diff->has_changes
ABresult
0X0
100
111
222  
223 0 my $declared = DBIO::Oracle::DDL->declared_objects($schema);
224 0 ▶ my %own = map { $_ => 1 } @{ $declared->{table} // [] }, @{ $declared->{view} // [] };
Condition0%0/4
$declared->{"table"} // []
l!l
00
$declared->{"view"} // []
l!l
00
MC/DC0%0/1
$declared->{"table"} // []
$declared->{"table"}
MC/DC0%0/1
$declared->{"view"} // []
$declared->{"view"}
Truth table0%0/2
A
A= $declared->{"table"}
Aresult
11
00
Truth table0%0/2
A
A= $declared->{"view"}
Aresult
11
00
225 # a table in another schema is 'schema.table' in the diff (karr k58)
226 0 ▶ for my $s (keys %{ $declared->{schema} // {} }) {
Condition0%0/2
$declared->{"schema"} // {}
l!l
00
MC/DC0%0/1
$declared->{"schema"} // {}
$declared->{"schema"}
Truth table0%0/2
A
A= $declared->{"schema"}
Aresult
11
00
227 0 ▶ $own{"$s.$_"} = 1 for @{ $declared->{schema}{$s}{table} // [] }, @{ $declared->{schema}{$s}{view} // [] };
Condition0%0/4
$declared->{"schema"}{$s}{"table"} // []
l!l
00
$declared->{"schema"}{$s}{"view"} // []
l!l
00
MC/DC0%0/1
$declared->{"schema"}{$s}{"table"} // []
$declared->{"schema"}{$s}{"table"}
MC/DC0%0/1
$declared->{"schema"}{$s}{"view"} // []
$declared->{"schema"}{$s}{"view"}
Truth table0%0/2
A
A= $declared->{"schema"}{$s}{"table"}
Aresult
11
00
Truth table0%0/2
A
A= $declared->{"schema"}{$s}{"view"}
Aresult
11
00
228 }
229 0 my @mine = grep { $own{ $_->table_name } } @{ $diff->operations };
230 0 ▶ return 1 unless @mine;
Branch: 1 branch
BranchTrueFalseTotal
unless @mine 0 0 0
231  
232 0 require Test::More;
233 Test::More::diag('conformance: the diff against the installed declaration is '
234 0 . "not empty:\n" . join("\n", map { $_->summary } @mine));
235 0 return 0;
236 }
237  
238  
239 # The tables and views the declarations of the schemas name, as { name => 1 }:
240 # 'table', and 'schema.table' for a source in another schema.
241 0 ▶sub _case_tables {
Subroutine _case_tables: not called CC=10 SCAR=47.0
242 0 my ($class, @schemas) = @_;
243 0 my %mine;
244 0 for my $s (@schemas) {
245 0 my $declared = DBIO::Oracle::DDL->declared_objects($s);
246 0 ▶ $mine{$_} = 1 for @{ $declared->{table} // [] }, @{ $declared->{view} // [] };
Condition0%0/4
$declared->{"table"} // []
l!l
00
$declared->{"view"} // []
l!l
00
MC/DC0%0/1
$declared->{"table"} // []
$declared->{"table"}
MC/DC0%0/1
$declared->{"view"} // []
$declared->{"view"}
Truth table0%0/2
A
A= $declared->{"table"}
Aresult
11
00
Truth table0%0/2
A
A= $declared->{"view"}
Aresult
11
00
247 0 ▶ for my $owner (keys %{ $declared->{schema} // {} }) {
Condition0%0/2
$declared->{"schema"} // {}
l!l
00
MC/DC0%0/1
$declared->{"schema"} // {}
$declared->{"schema"}
Truth table0%0/2
A
A= $declared->{"schema"}
Aresult
11
00
248 $mine{"$owner.$_"} = 1
249 0 ▶ for @{ $declared->{schema}{$owner}{table} // [] },
Condition0%0/2
$declared->{"schema"}{$owner}{"table"} // []
l!l
00
MC/DC0%0/1
$declared->{"schema"}{$owner}{"table"} // []
$declared->{"schema"}{$owner}{"table"}
Truth table0%0/2
A
A= $declared->{"schema"}{$owner}{"table"}
Aresult
11
00
250 0 ▶ @{ $declared->{schema}{$owner}{view} // [] };
Condition0%0/2
$declared->{"schema"}{$owner}{"view"} // []
l!l
00
MC/DC0%0/1
$declared->{"schema"}{$owner}{"view"} // []
$declared->{"schema"}{$owner}{"view"}
Truth table0%0/2
A
A= $declared->{"schema"}{$owner}{"view"}
Aresult
11
00
251 }
252 }
253 0 return \%mine;
254 }
255  
256 0 ▶sub conformance_upgrade {
Subroutine conformance_upgrade: not called CC=2 SCAR=17.9
Pod documented
257 0 my ($class, $schema, $to_class, $case) = @_;
258 0 my $to = $class->conformance_connect($to_class);
259  
260 0 my $done = eval {
261 0 my $deploy = DBIO::Oracle::Test::Conformance::Deploy->new(
262 schema => $to, case_tables => $class->_case_tables($schema, $to));
263 0 my $diff = $deploy->diff;
264 0 $deploy->apply($diff, allow_destructive => 1);
265 0 1;
266 };
267 0 my $error = $@;
268 0 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 0 0 0
269 # the target declaration may have created some of its objects
270 0 my $mark = $BEFORE{ ref $schema };
271 0 eval { $class->conformance_cleanup($to, $case, $mark) };
272 0 die $error;
273 }
274 0 return $to;
275 }
276  
277  
278 0 ▶sub conformance_deploy {
Subroutine conformance_deploy: not called CC=1 SCAR=6.9
Pod documented
279 0 my ($class, $schema, $to_class, $case) = @_;
280 0 my $to = $class->conformance_connect($to_class);
281 0 return DBIO::Oracle::Test::Conformance::Deploy->new(
282 schema => $to, case_tables => $class->_case_tables($schema, $to));
283 }
284  
285 {
286 package DBIO::Oracle::Test::Conformance::Deploy;
287  
288 11 ▶ use base 'DBIO::Oracle::Deploy';
Subroutine BEGIN: called CC=1 SCAR=0.0
289  
290 0 ▶ sub diff {
Subroutine diff: not called CC=3 SCAR=24.8
291 0 my ($self) = @_;
292 0 my $diff = $self->SUPER::diff;
293 0 ▶ my $mine = $self->{case_tables} or return $diff;
Branch: 1 branch
BranchTrueFalseTotal
my $mine = $self->{"case_tables"} or return $diff 0 0 0
294 0 my @ops = grep { $mine->{ $_->table_name } } @{ $diff->operations };
295 0 my @other = grep { !$mine->{ $_->table_name } } @{ $diff->operations };
296 0 ▶ if (@other) {
Branch: 1 branch
BranchTrueFalseTotal
if (@other) 0 0 0
297 0 require Test::More;
298 Test::More::diag('conformance: left alone, not an object of the case: '
299 0 . join('; ', map { $_->summary } @other));
300 }
301 0 $diff->{operations} = \@ops;
302 0 return $diff;
303 }
304 }
305  
306  
307 11 ▶sub conformance_answered_through {
Subroutine conformance_answered_through: called CC=1 SCAR=0.0
Pod documented
308 10 my ($class) = @_;
309 return {
310 10 DDL => 2,
311 Diff => 4,
312 Bind => 1,
313 };
314 }
315  
316  
317 9 ▶sub conformance_refusals {
Subroutine conformance_refusals: called CC=3 SCAR=12.0
Pod documented
318 9 my ($class) = @_;
319 9 my $refusals = $class->_conformance_refusals;
320 # The case writes to the schema 'other' and the driver creates no user
321 # (karr k58): where the server has no user of that exact name the install is
322 # refused, as the driver's own refusal that waits for such a user.
323 9 ▶ $refusals->{'ddl-qualified-source-name'} = {
Branch: 1 branch
BranchTrueFalseTotal
if $class->conformance_live_available and not $class->_user_exists("other") 0 9 9
Condition33%1/3
$class->conformance_live_available and not $class->_user_exists("other")
!ll&&!rl&&r
900
MC/DC0%0/2
$class->conformance_live_available and not $class->_user_exists("other")
$class->conformance_live_available not $class->_user_exists("other")
Truth table33%1/3
A and not(B)
A= $class->conformance_live_availableB= not $class->_user_exists("other")
ABresult
0X0
100
111
324 kind => 'pending',
325 reason => qr/does not exist/,
326 } if $class->conformance_live_available && !$class->_user_exists('other');
327 9 return $refusals;
328 }
329  
330 # Whether the server has a user of exactly that name; asked once per name and
331 # process.
332 11 my %USER_EXISTS;
333 0 ▶sub _user_exists {
Subroutine _user_exists: not called CC=3 SCAR=24.8
334 0 my ($class, $name) = @_;
335 0 ▶ return $USER_EXISTS{$name} //= do {
Condition0%0/3
$USER_EXISTS{$name} //= do { my $dbh = "DBI"->connect(@ENV{"DBIO_TEST_ORA_DSN", "DBIO_TEST_ORA_USER", "DBIO_TEST_ORA_PASS"}, {"RaiseError", 1, "PrintError", 0, "AutoCommit", 1}); my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM all_users WHERE username = ?", undef, $name); $dbh->disconnect; $found ? 1 : 0 }
l!l&&r!l&&!r
000
MC/DC0%0/2
$USER_EXISTS{$name} //= do { my $dbh = "DBI"->connect(@ENV{"DBIO_TEST_ORA_DSN", "DBIO_TEST_ORA_USER", "DBIO_TEST_ORA_PASS"}, {"RaiseError", 1, "PrintError", 0, "AutoCommit", 1}); my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM all_users WHERE username = ?", undef, $name); $dbh->disconnect; $found ? 1 : 0 }
$USER_EXISTS{$name} do { my $dbh = "DBI"->connect(@ENV{"DBIO_TEST_ORA_DSN", "DBIO_TEST_ORA_USER", "DBIO_TEST_ORA_PASS"}, {"RaiseError", 1, "PrintError", 0, "AutoCommit", 1}); my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM all_users WHERE username = ?", undef, $name); $dbh->disconnect; $found ? 1 : 0 }
Truth table0%0/3
A //= B
A= $USER_EXISTS{$name}B= do { my $dbh = "DBI"->connect(@ENV{"DBIO_TEST_ORA_DSN", "DBIO_TEST_ORA_USER", "DBIO_TEST_ORA_PASS"}, {"RaiseError", 1, "PrintError", 0, "AutoCommit", 1}); my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM all_users WHERE username = ?", undef, $name); $dbh->disconnect; $found ? 1 : 0 }
ABresult
1X1
011
000
336 0 my $dbh = DBI->connect(@ENV{qw(DBIO_TEST_ORA_DSN DBIO_TEST_ORA_USER DBIO_TEST_ORA_PASS)},
337 { RaiseError => 1, PrintError => 0, AutoCommit => 1 });
338 0 my ($found) = $dbh->selectrow_array(
339 'SELECT COUNT(*) FROM all_users WHERE username = ?', undef, $name);
340 0 $dbh->disconnect;
341 0 ▶ $found ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 0 0
342 };
343 }
344  
345 9 ▶sub _conformance_refusals {{
Subroutine _conformance_refusals: called CC=1 SCAR=0.0
346 9 'ddl-enum-value-apostrophe' => {
347 kind => 'server',
348 reason => qr/no enum type/,
349 },
350 'ddl-ident-special-chars' => {
351 kind => 'server',
352 reason => qr/double quote/,
353 },
354 'ddl-type-size-bit' => {
355 kind => 'server',
356 reason => qr/no BIT type/,
357 },
358 'ddl-index-on-unique-columns' => {
359 kind => 'server',
360 reason => qr/one index/,
361 },
362 'ddl-default-digit-string' => {
363 kind => 'deviation',
364 fact => qr/Code\.code: expected '007', read back '007 '/,
365 reason => 'CHAR(n) is blank-padded to n by Oracle itself: the default is the string 007 '
366 . '(not the number 7), and a row without the column reads it back padded to '
367 . "'007 '. The driver does not trim it",
368 },
369 # --- the Diff list (karr k63)
370 'diff-column-added-not-null-populated' => {
371 kind => 'server',
372 reason => qr/NOT NULL without a default, and table base holds rows/,
373 },
374 'diff-not-null-over-nulls' => {
375 kind => 'server',
376 reason => qr/table opt holds rows where it is NULL/,
377 },
378 'diff-column-type-change' => {
379 kind => 'server',
380 reason => qr/changes the datatype of a column only while it is empty/,
381 },
382 # --- the Bind list (karr k63)
383 'bind-empty-string' => {
384 kind => 'deviation',
385 fact => qr/Val: the server accepted a row it must reject/,
386 reason => 'Oracle does not know the empty string: for a VARCHAR2, a NUMBER or any other '
387 . 'type but a LOB, \'\' is NULL, so the nullable integer column of the case takes it '
388 . '(SQL Language Reference, "Nulls": "Oracle Database currently treats a character '
389 . 'value with a length of zero as null"). The text column holds \'\' as an empty LOB '
390 . 'and finds it again',
391 },
392 'bind-numeric-exact' => {
393 kind => 'deviation',
394 fact => qr/Num\.v create: expected '1234567890123456\.7890', read back '1234567890123456\.789'.*expected '0\.0001', read back '\.0001'/s,
395 reason => 'the value is exact and the digits are all there, but Oracle has no display scale: a '
396 . 'NUMBER is read as the shortest text of its value, without trailing zeros after the '
397 . 'point and without the zero before a leading point (1234567890123456.7890 is '
398 . '1234567890123456.789, 0.0001 is .0001); NUMBER(20,4) does not pad to four places',
399 },
400 }}
401  
402  
403 0 ▶sub conformance_fact {
Subroutine conformance_fact: not called CC=25 SCAR=64.8
Pod documented
404 0 my ($class, $schema, $name, $args) = @_;
405 0 my $dbh = $schema->storage->dbh;
406 0 my $table = $args->{table};
407  
408 0 ▶ if ($name eq 'table_in_namespace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_in_namespace") 0 0 0
409 my $other = DBIO::Oracle::Introspect->new(
410 0 dbh => $dbh, schema => $args->{namespace});
411 0 ▶ return exists $other->model->{tables}{ $args->{unqualified} } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $other->model->{'tables'}{$args->{'unqualified'}} ? : 0 0 0
412 }
413  
414 0 my $model = DBIO::Oracle::Introspect->new(dbh => $dbh)->model;
415 0 my $entry = $model->{tables}{$table};
416 0 ▶ my @cols = @{ $args->{columns} || [] };
Condition0%0/2
$args->{'columns'} || []
l!l
00
MC/DC0%0/1
$args->{'columns'} || []
$args->{'columns'}
Truth table0%0/2
A
A= $args->{'columns'}
Aresult
11
00
417 0 ▶ my $same = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
418 0 my ($got) = @_;
419 0 ▶ return 0 unless @$got == @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @$got == @cols 0 0 0
420 0 ▶ return (join("\0", map { $_ // '' } @$got) eq join("\0", @cols)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
join("\000", map({$_ // '';} @$got)) eq join("\000", @cols) ? : 0 0 0
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
421 0 };
422  
423 0 ▶ if ($name eq 'object_kind') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "object_kind") 0 0 0
424 0 ▶ return undef unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
425 0 return $entry->{kind};
426 }
427 0 ▶ if ($name eq 'table_name') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_name") 0 0 0
428 0 ▶ return $entry ? $entry->{table_name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$entry ? : 0 0 0
429 }
430  
431 0 ▶ my $columns = $model->{columns}{$table} || [];
Condition0%0/2
$model->{'columns'}{$table} || []
l!l
00
MC/DC0%0/1
$model->{'columns'}{$table} || []
$model->{'columns'}{$table}
Truth table0%0/2
A
A= $model->{'columns'}{$table}
Aresult
11
00
432 0 ▶ if ($name eq 'column_names') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_names") 0 0 0
433 0 return [ map { $_->{column_name} } @$columns ];
434 }
435 0 ▶ if ($name eq 'column_size') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_size") 0 0 0
436 0 my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns;
437 0 ▶ return $col ? $col->{size} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$col ? : 0 0 0
438 }
439 0 ▶ if ($name eq 'column_auto_increment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_auto_increment") 0 0 0
440 0 my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns;
441 0 ▶ return $col && $col->{is_auto_increment} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$col && $col->{'is_auto_increment'} ? : 0 0 0
Condition0%0/3
$col and $col->{"is_auto_increment"}
!ll&&!rl&&r
000
MC/DC0%0/2
$col and $col->{"is_auto_increment"}
$col $col->{"is_auto_increment"}
Truth table0%0/3
A and B
A= $colB= $col->{"is_auto_increment"}
ABresult
0X0
100
111
442 }
443 0 ▶ if ($name eq 'primary_key_columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "primary_key_columns") 0 0 0
444 0 ▶ return [ @{ $model->{primary_keys}{$table} || [] } ];
Condition0%0/2
$model->{'primary_keys'}{$table} || []
l!l
00
MC/DC0%0/1
$model->{'primary_keys'}{$table} || []
$model->{'primary_keys'}{$table}
Truth table0%0/2
A
A= $model->{'primary_keys'}{$table}
Aresult
11
00
445 }
446 0 ▶ if ($name eq 'unique_exists') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "unique_exists") 0 0 0
447 0 ▶ return (grep { $same->($_->[1]) } @{ $model->{unique_constraints}{$table} || [] })
Branch: 1 branch
BranchTrueFalseTotal
grep({&$same($_->[1]);} @{$model->{'unique_constraints'}{$table} or [];}) ? : 0 0 0
Condition0%0/2
$model->{'unique_constraints'}{$table} || []
l!l
00
MC/DC0%0/1
$model->{'unique_constraints'}{$table} || []
$model->{'unique_constraints'}{$table}
Truth table0%0/2
A
A= $model->{'unique_constraints'}{$table}
Aresult
11
00
448 ? 1 : 0;
449 }
450 0 ▶ if ($name eq 'foreign_key_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "foreign_key_count") 0 0 0
451 0 ▶ return scalar @{ $model->{foreign_keys}{$table} || [] };
Condition0%0/2
$model->{'foreign_keys'}{$table} || []
l!l
00
MC/DC0%0/1
$model->{'foreign_keys'}{$table} || []
$model->{'foreign_keys'}{$table}
Truth table0%0/2
A
A= $model->{'foreign_keys'}{$table}
Aresult
11
00
452 }
453 0 ▶ if ($name eq 'index_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "index_count") 0 0 0
454 0 return (scalar grep { $same->($_->{columns}) }
455 0 ▶ values %{ $model->{indexes}{$table} || {} })
Condition0%0/2
$model->{'indexes'}{$table} || {}
l!l
00
MC/DC0%0/1
$model->{'indexes'}{$table} || {}
$model->{'indexes'}{$table}
Truth table0%0/2
A
A= $model->{'indexes'}{$table}
Aresult
11
00
456 0 + (scalar grep { $same->($_->[1]) }
457 0 ▶ @{ $model->{unique_constraints}{$table} || [] });
Condition0%0/2
$model->{'unique_constraints'}{$table} || []
l!l
00
MC/DC0%0/1
$model->{'unique_constraints'}{$table} || []
$model->{'unique_constraints'}{$table}
Truth table0%0/2
A
A= $model->{'unique_constraints'}{$table}
Aresult
11
00
458 }
459  
460 0 DBIO::Exception->throw("unknown conformance fact '$name'");
461 }
462  
463 11 1;
464  
465 __END__
« Oracle/Introspect/Columns.pm ↑ Summary Oracle/Storage/AutoIncrement.pm »