| 1 | package DBIO::Firebird::Introspect::Tables; | ||||||||||
| 2 | # ABSTRACT: Introspect Firebird tables and views via rdb$relations | ||||||||||
| 3 | |||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 6 | our $VERSION = '0.900007'; | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub fetch { | ||||||||
|
Subroutine
fetch: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 12 | 0 | my ($class, $dbh) = @_; | |||||||||
| 13 | |||||||||||
| 14 | 0 | my $sth = $dbh->prepare(q{ | |||||||||
| 15 | SELECT rdb$relation_name, rdb$view_source | ||||||||||
| 16 | FROM rdb$relations | ||||||||||
| 17 | WHERE rdb$system_flag = 0 | ||||||||||
| 18 | AND rdb$relation_type IN (0, 1) | ||||||||||
| 19 | ORDER BY rdb$relation_name | ||||||||||
| 20 | }); | ||||||||||
| 21 | 0 | $sth->execute; | |||||||||
| 22 | |||||||||||
| 23 | 0 | my %tables; | |||||||||
| 24 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | my $name = $row->{'rdb$relation_name'}; | |||||||||
| 26 | 0 | $name =~ s/\s+$//; | |||||||||
| 27 | 0 | ▶ | my $kind = defined $row->{'rdb$view_source'} ? 'view' : 'table'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | ▶ | $tables{$name} = { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | table_name => $name, | ||||||||||
| 30 | kind => $kind, | ||||||||||
| 31 | ( $kind eq 'view' ? ( view_source => "$row->{'rdb$view_source'}" ) : () ), | ||||||||||
| 32 | }; | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | my $pk = $dbh->prepare(q{ | |||||||||
| 36 | SELECT rdb$relation_name, rdb$constraint_name | ||||||||||
| 37 | FROM rdb$relation_constraints | ||||||||||
| 38 | WHERE rdb$constraint_type = 'PRIMARY KEY' | ||||||||||
| 39 | }); | ||||||||||
| 40 | 0 | $pk->execute; | |||||||||
| 41 | 0 | ▶ | while (my $row = $pk->fetchrow_hashref) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | my ($table, $name) = map { my $v = $row->{$_}; $v =~ s/\s+$//; $v } | |||||||||
| 43 | 'rdb$relation_name', 'rdb$constraint_name'; | ||||||||||
| 44 | 0 | ▶ | $tables{$table}{primary_key_name} = $name if exists $tables{$table}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | return \%tables; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 6 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||