line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Otogiri::Plugin::TableInfo; |
2
|
2
|
|
|
2
|
|
9863
|
use 5.008005; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
77
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
428
|
use Otogiri; |
|
2
|
|
|
|
|
37658
|
|
|
2
|
|
|
|
|
184
|
|
7
|
2
|
|
|
2
|
|
465
|
use Otogiri::Plugin; |
|
2
|
|
|
|
|
427
|
|
|
2
|
|
|
|
|
44
|
|
8
|
2
|
|
|
2
|
|
786
|
use DBIx::Inspector; |
|
2
|
|
|
|
|
9576
|
|
|
2
|
|
|
|
|
50
|
|
9
|
2
|
|
|
2
|
|
837
|
use Otogiri::Plugin::TableInfo::Pg; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
730
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(show_tables show_create_table show_create_view desc); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub show_tables { |
16
|
2
|
|
|
2
|
1
|
3994
|
my ($self, $like_regex) = @_; |
17
|
2
|
|
|
|
|
27
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
18
|
2
|
|
|
|
|
2483
|
my @tables = $inspector->tables; |
19
|
2
|
|
|
|
|
1293
|
my @result = map { $_->name } $inspector->tables; |
|
6
|
|
|
|
|
1114
|
|
20
|
2
|
100
|
|
|
|
21
|
@result = grep { $_ =~ /$like_regex/ } @result if ( defined $like_regex ); |
|
3
|
|
|
|
|
15
|
|
21
|
2
|
|
|
|
|
17
|
return @result; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub show_create_table { |
25
|
3
|
|
|
3
|
1
|
7
|
my ($self, $table_name) = @_; |
26
|
3
|
|
|
|
|
9
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
27
|
3
|
|
|
|
|
268
|
my $table = $inspector->table($table_name); |
28
|
|
|
|
|
|
|
|
29
|
3
|
100
|
|
|
|
1530
|
return if ( !defined $table ); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
7
|
my $driver_name = $self->{dsn}->{driver}; |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
9
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE TABLE $table_name"); |
35
|
0
|
|
|
|
|
0
|
return $row->{'Create Table'}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
38
|
2
|
|
|
|
|
12
|
return $table->{SQLITE_SQL}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
41
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
42
|
0
|
|
|
|
|
0
|
return $pg->show_create_table($table_name); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub show_create_view { |
48
|
1
|
|
|
1
|
1
|
2183
|
my ($self, $view_name) = @_; |
49
|
1
|
|
|
|
|
4
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
50
|
1
|
|
|
|
|
81
|
my $view = $inspector->view($view_name); |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
524
|
return if ( !defined $view ); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
3
|
my $driver_name = $self->{dsn}->{driver}; |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
6
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE VIEW $view_name"); |
58
|
0
|
|
|
|
|
0
|
return $row->{'Create View'}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
61
|
1
|
|
|
|
|
6
|
return $view->{SQLITE_SQL}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
64
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
65
|
0
|
|
|
|
|
0
|
return $pg->show_create_view($view_name); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
0
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub desc { |
71
|
2
|
|
|
2
|
1
|
3073
|
my ($self, $table_name) = @_; |
72
|
2
|
|
|
|
|
8
|
$self->show_create_table($table_name); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |