| 1 | package DBIO::SQLite::Introspect::Tables; | ||||||||||||
| 2 | # ABSTRACT: Introspect SQLite tables and views | ||||||||||||
| 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=5 SCAR=16.2
Pod
documented
| |||||||||||||
| 10 | 26 | my ($class, $dbh) = @_; | |||||||||||
| 11 | |||||||||||||
| 12 | 26 | my $sth = $dbh->prepare(q{ | |||||||||||
| 13 | SELECT name, type, sql | ||||||||||||
| 14 | FROM sqlite_master | ||||||||||||
| 15 | WHERE type IN ('table', 'view') | ||||||||||||
| 16 | AND name NOT LIKE 'sqlite_%' | ||||||||||||
| 17 | ORDER BY name | ||||||||||||
| 18 | }); | ||||||||||||
| 19 | 26 | $sth->execute; | |||||||||||
| 20 | |||||||||||||
| 21 | 26 | my %tables; | |||||||||||
| 22 | 26 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 40 | ▶ | my $sql = $row->{sql} // ''; | ||||||||||
|
Condition50%1/2
$row->{"sql"} // ""
MC/DC0%0/1
$row->{"sql"} // ""
$row->{"sql"}
Truth table50%1/2
A
A= $row->{"sql"}
| |||||||||||||
| 24 | |||||||||||||
| 25 | # Detect WITHOUT ROWID and STRICT modifiers from the original CREATE | ||||||||||||
| 26 | 40 | ▶ | my $without_rowid = $sql =~ /\bWITHOUT\s+ROWID\b/i ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 40 | ▶ | my $strict = $sql =~ /\)\s*STRICT\s*;?\s*$/i ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | |||||||||||||
| 29 | $tables{ $row->{name} } = { | ||||||||||||
| 30 | table_name => $row->{name}, | ||||||||||||
| 31 | kind => $row->{type}, | ||||||||||||
| 32 | 40 | sql => $sql, | |||||||||||
| 33 | without_rowid => $without_rowid, | ||||||||||||
| 34 | strict => $strict, | ||||||||||||
| 35 | }; | ||||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 26 | return \%tables; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 197 | 1; | |||||||||||
| 42 | |||||||||||||
| 43 | __END__ | ||||||||||||
| 44 | |||||||||||||
| 45 | =pod | ||||||||||||
| 46 | |||||||||||||
| 47 | =encoding UTF-8 | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 NAME | ||||||||||||
| 50 | |||||||||||||
| 51 | DBIO::SQLite::Introspect::Tables - Introspect SQLite tables and views | ||||||||||||
| 52 | |||||||||||||
| 53 | =head1 VERSION | ||||||||||||
| 54 | |||||||||||||
| 55 | version 0.900001 | ||||||||||||
| 56 | |||||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||||
| 58 | |||||||||||||
| 59 | Fetches SQLite table and view metadata from C<sqlite_master>. Skips | ||||||||||||
| 60 | internal C<sqlite_*> objects and the C<dbio_changelog>/migration tables | ||||||||||||
| 61 | when present. | ||||||||||||
| 62 | |||||||||||||
| 63 | =head1 METHODS | ||||||||||||
| 64 | |||||||||||||
| 65 | =head2 fetch | ||||||||||||
| 66 | |||||||||||||
| 67 | my $tables = DBIO::SQLite::Introspect::Tables->fetch($dbh); | ||||||||||||
| 68 | |||||||||||||
| 69 | Returns a hashref keyed by table name. Each value is a hashref with | ||||||||||||
| 70 | keys: C<table_name>, C<kind> (C<table> or C<view>), C<sql> (the original | ||||||||||||
| 71 | C<CREATE> statement from C<sqlite_master>), C<without_rowid>, C<strict>. | ||||||||||||
| 72 | |||||||||||||
| 73 | =head1 AUTHOR | ||||||||||||
| 74 | |||||||||||||
| 75 | DBIO & DBIx::Class Authors | ||||||||||||
| 76 | |||||||||||||
| 77 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 78 | |||||||||||||
| 79 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 80 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||
| 81 | Based on DBIx::Class, heavily modified. | ||||||||||||
| 82 | |||||||||||||
| 83 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 84 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 85 | |||||||||||||
| 86 | =cut | ||||||||||||