MSSQL/Introspect.pm

filter: Statementstmt 70.9% 22 / 31 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 68.1% 30 / 44 CC 2 SCAR 7.4
CC
2
Cov
67%
schema
6.0
_build_model
2.0
BEGIN
1.0
CRAP 2.1
« MSSQL/Diff/ForeignKey.pm ↑ Summary MSSQL/SQLMaker.pm »
1 package DBIO::MSSQL::Introspect;
2 # ABSTRACT: Introspect a Microsoft SQL Server database via information_schema
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use base 'DBIO::Introspect::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 2 ▶use DBIO::MSSQL::Introspect::Tables;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use DBIO::MSSQL::Introspect::Columns;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use DBIO::MSSQL::Introspect::Indexes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DBIO::MSSQL::Introspect::ForeignKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub schema { $_[0]->{schema} // 'dbo' }
Subroutine schema: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
$_[0]{"schema"} // "dbo"
l!l
00
MC/DC0%0/1
$_[0]{"schema"} // "dbo"
$_[0]{"schema"}
Truth table0%0/2
A
A= $_[0]{"schema"}
Aresult
11
00
16  
17  
18 0 ▶sub _build_model {
Subroutine _build_model: not called CC=1 SCAR=6.9
19 0 my ($self) = @_;
20 0 my $dbh = $self->dbh;
21 0 my $schema = $self->schema;
22  
23 0 my $tables = DBIO::MSSQL::Introspect::Tables->fetch($dbh, $schema);
24 0 my $columns = DBIO::MSSQL::Introspect::Columns->fetch($dbh, $schema, $tables);
25 0 my $indexes = DBIO::MSSQL::Introspect::Indexes->fetch($dbh, $schema, $tables);
26 0 my $fks = DBIO::MSSQL::Introspect::ForeignKeys->fetch($dbh, $schema, $tables);
27  
28 return {
29 0 tables => $tables,
30 columns => $columns,
31 indexes => $indexes,
32 foreign_keys => $fks,
33 };
34 }
35  
36  
37  
38 2 1;
39  
40 __END__
41  
42 =pod
43  
44 =encoding UTF-8
45  
46 =head1 NAME
47  
48 DBIO::MSSQL::Introspect - Introspect a Microsoft SQL Server database via information_schema
49  
50 =head1 VERSION
51  
52 version 0.900001
53  
54 =head1 DESCRIPTION
55  
56 C<DBIO::MSSQL::Introspect> reads the live state of a Microsoft SQL Server
57 database via the standard SQL C<INFORMATION_SCHEMA> views. It is the
58 source side of the test-deploy-and-compare strategy used by
59 L<DBIO::MSSQL::Deploy>.
60  
61 my $intro = DBIO::MSSQL::Introspect->new(dbh => $dbh);
62 my $model = $intro->model;
63  
64 Model shape mirrors L<DBIO::SQLite::Introspect>:
65  
66 {
67 tables => { $name => { ... } },
68 columns => { $table => [ { ... }, ... ] },
69 indexes => { $table => { $name => { ... } } },
70 foreign_keys => { $table => [ { ... }, ... ] },
71 }
72  
73 =head1 ATTRIBUTES
74  
75 =head2 schema
76  
77 Schema name to introspect. Defaults to C<dbo>.
78  
79 =head1 NORMALIZED INTROSPECTION CONTRACT
80  
81 The seven L<DBIO::Introspect::Base> contract methods (C<table_keys>,
82 C<table_columns>, C<table_columns_info>, C<table_pk_info>,
83 C<table_uniq_info>, C<table_fk_info>, C<table_is_view>) are B<inherited
84 unchanged> from the base: they are pure reads over the canonical L</model>
85 this class builds, so this introspector serves as a high-fidelity source
86 for L<DBIO::Generate> with no driver-specific override. Two model details
87 make the defaults correct here: L<DBIO::MSSQL::Introspect::Columns> emits
88 the canonical C<is_auto_increment> flag (alongside the MSSQL-native
89 C<is_identity>), and L<DBIO::MSSQL::Introspect::Indexes> already excludes
90 primary-key indexes, so C<table_uniq_info> never double-reports the PK.
91  
92 =seealso
93  
94 =over
95  
96 =item * L<DBIO::MSSQL::Deploy> - uses this class for test-deploy-and-compare
97  
98 =item * L<DBIO::MSSQL::Diff> - compares two models produced by this class
99  
100 =back
101  
102 =head1 AUTHOR
103  
104 DBIO & DBIx::Class Authors
105  
106 =head1 COPYRIGHT AND LICENSE
107  
108 Copyright (C) 2026 DBIO Authors
109 Portions Copyright (C) 2005-2025 DBIx::Class Authors
110 Based on DBIx::Class, heavily modified.
111  
112 This is free software; you can redistribute it and/or modify it under
113 the same terms as the Perl 5 programming language system itself.
114  
115 =cut
« MSSQL/Diff/ForeignKey.pm ↑ Summary MSSQL/SQLMaker.pm »