SQLite/Introspect/Columns.pm

filter: Statementstmt 100% 24 / 24 Branchbran 80.0% 8 / 10 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 86.6% 39 / 45 CC 9 SCAR 17.8
CC
9
Cov
89%
fetch
8.1
_has_xinfo
2.0
BEGIN
1.0
CRAP 5.9
« SQLite/Diff/Column.pm ↑ Summary SQLite/Diff/Index.pm »
1 package DBIO::SQLite::Introspect::Columns;
2 # ABSTRACT: Introspect SQLite columns
3  
4 197 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 197 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8  
9 26 ▶sub fetch {
Subroutine fetch: called CC=8 SCAR=20.9
Pod documented
10 26 my ($class, $dbh, $tables) = @_;
11 26 my %columns;
12  
13 # Prefer table_xinfo (SQLite 3.26+) -- it knows about hidden/generated cols.
14 26 my $use_xinfo = _has_xinfo($dbh);
15  
16 26 for my $table_name (sort keys %$tables) {
17 40 ▶ my $pragma = $use_xinfo ? 'table_xinfo' : 'table_info';
Branch: 1 branch
BranchTrueFalseTotal
$use_xinfo ? : 40 0 40
18 40 my $sth = $dbh->prepare(qq{PRAGMA $pragma("$table_name")});
19 40 $sth->execute;
20  
21 40 my @cols;
22 40 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 133 40 173
23 push @cols, {
24 column_name => $row->{name},
25 data_type => $row->{type},
26 not_null => $row->{notnull} ? 1 : 0,
27 default_value => $row->{dflt_value},
28 is_pk => $row->{pk} ? 1 : 0,
29 pk_position => $row->{pk} // 0,
30 133 ▶ hidden => $row->{hidden} // 0,
Branch: 2 branches
BranchTrueFalseTotal
$row->{'notnull'} ? : 70 63 133
$row->{'pk'} ? : 40 93 133
Condition50%2/4
$row->{"pk"} // 0
l!l
1330
$row->{"hidden"} // 0
l!l
1330
MC/DC0%0/1
$row->{"pk"} // 0
$row->{"pk"}
MC/DC0%0/1
$row->{"hidden"} // 0
$row->{"hidden"}
Truth table50%1/2
A
A= $row->{"pk"}
Aresult
11
00
Truth table50%1/2
A
A= $row->{"hidden"}
Aresult
11
00
31 };
32 }
33 40 $columns{$table_name} = \@cols;
34 }
35  
36 26 return \%columns;
37 }
38  
39 26 ▶sub _has_xinfo {
Subroutine _has_xinfo: called CC=2 SCAR=7.0
40 26 my ($dbh) = @_;
41 26 my $ok = eval {
42 26 $dbh->selectrow_array(q{PRAGMA table_xinfo("sqlite_master")});
43 26 1;
44 };
45 26 ▶ return $ok ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 26 0 26
46 }
47  
48 197 1;
49  
50 __END__
51  
52 =pod
53  
54 =encoding UTF-8
55  
56 =head1 NAME
57  
58 DBIO::SQLite::Introspect::Columns - Introspect SQLite columns
59  
60 =head1 VERSION
61  
62 version 0.900001
63  
64 =head1 DESCRIPTION
65  
66 Fetches column metadata via C<PRAGMA table_info()> (or C<table_xinfo>
67 when available, which also reports hidden/generated columns).
68  
69 =head1 METHODS
70  
71 =head2 fetch
72  
73 my $columns = DBIO::SQLite::Introspect::Columns->fetch($dbh, $tables);
74  
75 Given the tables hashref produced by L<DBIO::SQLite::Introspect::Tables>,
76 returns a hashref keyed by table name. Each value is an arrayref of
77 column hashrefs (in declaration order) with keys: C<column_name>,
78 C<data_type>, C<not_null>, C<default_value>, C<is_pk>, C<pk_position>,
79 C<hidden> (xinfo only).
80  
81 =head1 AUTHOR
82  
83 DBIO & DBIx::Class Authors
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 Copyright (C) 2026 DBIO Authors
88 Portions Copyright (C) 2005-2025 DBIx::Class Authors
89 Based on DBIx::Class, heavily modified.
90  
91 This is free software; you can redistribute it and/or modify it under
92 the same terms as the Perl 5 programming language system itself.
93  
94 =cut
« SQLite/Diff/Column.pm ↑ Summary SQLite/Diff/Index.pm »