line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Otogiri::Plugin::TableInfo; |
2
|
2
|
|
|
2
|
|
12080
|
use 5.008005; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
66
|
|
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
435
|
use Otogiri; |
|
2
|
|
|
|
|
39225
|
|
|
2
|
|
|
|
|
202
|
|
7
|
2
|
|
|
2
|
|
464
|
use Otogiri::Plugin; |
|
2
|
|
|
|
|
436
|
|
|
2
|
|
|
|
|
43
|
|
8
|
2
|
|
|
2
|
|
925
|
use DBIx::Inspector; |
|
2
|
|
|
|
|
10213
|
|
|
2
|
|
|
|
|
54
|
|
9
|
2
|
|
|
2
|
|
848
|
use Otogiri::Plugin::TableInfo::Pg; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
877
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(show_tables show_views show_create_table show_create_view desc); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub show_tables { |
16
|
2
|
|
|
2
|
1
|
3723
|
my ($self, $like_regex) = @_; |
17
|
2
|
|
|
|
|
21
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
18
|
2
|
|
|
|
|
2607
|
my @result = map { $_->name } $inspector->tables; |
|
6
|
|
|
|
|
1326
|
|
19
|
2
|
100
|
|
|
|
19
|
@result = grep { $_ =~ /$like_regex/ } @result if ( defined $like_regex ); |
|
3
|
|
|
|
|
13
|
|
20
|
2
|
|
|
|
|
11
|
return @result; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub show_views { |
24
|
2
|
|
|
2
|
1
|
2642
|
my ($self, $like_regex) = @_; |
25
|
2
|
|
|
|
|
7
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
26
|
2
|
|
|
|
|
171
|
my @result = map { $_->name } $inspector->views; |
|
4
|
|
|
|
|
1088
|
|
27
|
2
|
100
|
|
|
|
16
|
@result = grep { $_ =~ /$like_regex/ } @result if ( defined $like_regex ); |
|
2
|
|
|
|
|
13
|
|
28
|
2
|
|
|
|
|
9
|
return @result; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub show_create_table { |
33
|
3
|
|
|
3
|
1
|
7
|
my ($self, $table_name) = @_; |
34
|
3
|
|
|
|
|
10
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
35
|
3
|
|
|
|
|
254
|
my $table = $inspector->table($table_name); |
36
|
|
|
|
|
|
|
|
37
|
3
|
100
|
|
|
|
1477
|
return if ( !defined $table ); |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
7
|
my $driver_name = $self->{dsn}->{driver}; |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
7
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE TABLE $table_name"); |
43
|
0
|
|
|
|
|
0
|
return $row->{'Create Table'}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
46
|
2
|
|
|
|
|
10
|
return $table->{SQLITE_SQL}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
49
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
50
|
0
|
|
|
|
|
0
|
return $pg->show_create_table($table_name); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
0
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub show_create_view { |
56
|
1
|
|
|
1
|
1
|
1348
|
my ($self, $view_name) = @_; |
57
|
1
|
|
|
|
|
4
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
58
|
1
|
|
|
|
|
88
|
my $view = $inspector->view($view_name); |
59
|
|
|
|
|
|
|
|
60
|
1
|
50
|
|
|
|
508
|
return if ( !defined $view ); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
4
|
my $driver_name = $self->{dsn}->{driver}; |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
5
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE VIEW $view_name"); |
66
|
0
|
|
|
|
|
0
|
return $row->{'Create View'}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
69
|
1
|
|
|
|
|
5
|
return $view->{SQLITE_SQL}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
72
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
73
|
0
|
|
|
|
|
0
|
return $pg->show_create_view($view_name); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
0
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub desc { |
79
|
2
|
|
|
2
|
1
|
2232
|
my ($self, $table_name) = @_; |
80
|
2
|
|
|
|
|
7
|
$self->show_create_table($table_name); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |