| 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"
MC/DC0%0/1
$schema //= "dbo"
$schema
Truth table50%1/2
A
A= $schema
| |||||||||||||
| 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
| |||||||||||||
| 30 | 3 | ▶ | my $type = lc($row->{table_type} // ''); | ||||||||||
|
Condition50%1/2
$row->{"table_type"} // ""
MC/DC0%0/1
$row->{"table_type"} // ""
$row->{"table_type"}
Truth table50%1/2
A
A= $row->{"table_type"}
| |||||||||||||
| 31 | 3 | ▶ | my $kind = $type =~ /view/ ? 'view' : 'table'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||