MSSQL/Introspect/Tables.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 4 / 4 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 87.5% 28 / 32 CC 5 SCAR 13.6
CC
5
Cov
92%
fetch
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.9
« MSSQL/Adapter.pm ↑ Summary MSSQL/Diff/ForeignKey.pm »
1 package DBIO::MSSQL::Introspect::Tables;
2 # ABSTRACT: Introspect MSSQL tables and views
3  
4 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 28 our $VERSION = '0.900007';
8  
9  
10  
11 1 ▶sub fetch {
Subroutine fetch: called CC=5 SCAR=16.2
Pod documented
12 1 my ($class, $dbh, $schema) = @_;
13 1 ▶ $schema //= 'dbo';
Condition50%1/2
$schema //= "dbo"
l!l
10
MC/DC0%0/1
$schema //= "dbo"
$schema
Truth table50%1/2
A
A= $schema
Aresult
11
00
14  
15 # Every column is aliased explicitly and in lower case: an alias is echoed
16 # into the result metadata verbatim, which is the one way to be sure of the
17 # hash keys below without depending on the handle's FetchHashKeyName.
18 # INFORMATION_SCHEMA reports its columns UPPERCASE; unaliased, the key case
19 # in the row hash is decided by the transport, not by this code.
20 1 my $sth = $dbh->prepare(q{
21 SELECT table_name AS table_name, table_type AS table_type
22 FROM INFORMATION_SCHEMA.TABLES
23 WHERE table_schema = ?
24 ORDER BY table_name
25 });
26 1 $sth->execute($schema);
27  
28 1 my %tables;
29 1 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 3 1 4
30 3 ▶ my $type = lc($row->{table_type} // '');
Condition50%1/2
$row->{"table_type"} // ""
l!l
30
MC/DC0%0/1
$row->{"table_type"} // ""
$row->{"table_type"}
Truth table50%1/2
A
A= $row->{"table_type"}
Aresult
11
00
31 3 ▶ my $kind = $type =~ /view/ ? 'view' : 'table';
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /view/ ? : 1 2 3
32 $tables{ $row->{table_name} } = {
33 table_name => $row->{table_name},
34 3 kind => $kind,
35 schema => $schema,
36 };
37 }
38  
39 1 return \%tables;
40 }
41  
42 28 1;
43  
44 __END__
« MSSQL/Adapter.pm ↑ Summary MSSQL/Diff/ForeignKey.pm »