| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition50%2/4
$row->{"pk"} // 0
$row->{"hidden"} // 0
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"}
Truth table50%1/2
A
A= $row->{"hidden"}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||