line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Otogiri::Plugin::TableInfo; |
2
|
2
|
|
|
2
|
|
10525
|
use 5.008005; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
67
|
|
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
48
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
448
|
use Otogiri; |
|
2
|
|
|
|
|
47067
|
|
|
2
|
|
|
|
|
209
|
|
7
|
2
|
|
|
2
|
|
578
|
use Otogiri::Plugin; |
|
2
|
|
|
|
|
520
|
|
|
2
|
|
|
|
|
39
|
|
8
|
2
|
|
|
2
|
|
817
|
use DBIx::Inspector; |
|
2
|
|
|
|
|
10891
|
|
|
2
|
|
|
|
|
57
|
|
9
|
2
|
|
|
2
|
|
827
|
use Otogiri::Plugin::TableInfo::Pg; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
109
|
|
10
|
2
|
|
|
2
|
|
12
|
use Carp qw(); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1012
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw(show_tables show_views show_create_table show_create_view desc); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub show_tables { |
17
|
2
|
|
|
2
|
1
|
4793
|
my ($self, $like_regex) = @_; |
18
|
2
|
|
|
|
|
9
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
19
|
2
|
|
|
|
|
2637
|
my @result = map { $_->name } $inspector->tables; |
|
6
|
|
|
|
|
1372
|
|
20
|
2
|
100
|
|
|
|
21
|
@result = grep { $_ =~ /$like_regex/ } @result if ( defined $like_regex ); |
|
3
|
|
|
|
|
16
|
|
21
|
2
|
|
|
|
|
12
|
return @result; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub show_views { |
25
|
2
|
|
|
2
|
1
|
3660
|
my ($self, $like_regex) = @_; |
26
|
2
|
|
|
|
|
9
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
27
|
2
|
|
|
|
|
192
|
my @result = map { $_->name } $inspector->views; |
|
4
|
|
|
|
|
1250
|
|
28
|
2
|
100
|
|
|
|
17
|
@result = grep { $_ =~ /$like_regex/ } @result if ( defined $like_regex ); |
|
2
|
|
|
|
|
16
|
|
29
|
2
|
|
|
|
|
10
|
return @result; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub show_create_table { |
34
|
3
|
|
|
3
|
1
|
6
|
my ($self, $table_name) = @_; |
35
|
3
|
|
|
|
|
10
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
36
|
3
|
|
|
|
|
253
|
my $table = $inspector->table($table_name); |
37
|
|
|
|
|
|
|
|
38
|
3
|
100
|
|
|
|
1513
|
return if ( !defined $table ); |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
7
|
my $driver_name = $self->maker->driver; |
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
30
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE TABLE $table_name"); |
44
|
0
|
|
|
|
|
0
|
return $row->{'Create Table'}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
47
|
2
|
|
|
|
|
10
|
return $table->{SQLITE_SQL}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
50
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
51
|
0
|
|
|
|
|
0
|
return $pg->show_create_table($table_name); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
Carp::carp "unsupported driver : $driver_name"; |
55
|
0
|
|
|
|
|
0
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub show_create_view { |
59
|
1
|
|
|
1
|
1
|
1879
|
my ($self, $view_name) = @_; |
60
|
1
|
|
|
|
|
4
|
my $inspector = DBIx::Inspector->new(dbh => $self->dbh); |
61
|
1
|
|
|
|
|
89
|
my $view = $inspector->view($view_name); |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
574
|
return if ( !defined $view ); |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
4
|
my $driver_name = $self->maker->driver; |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
13
|
if ( $driver_name eq 'mysql' ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
my ($row) = $self->search_by_sql("SHOW CREATE VIEW $view_name"); |
69
|
0
|
|
|
|
|
0
|
return $row->{'Create View'}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
72
|
1
|
|
|
|
|
4
|
return $view->{SQLITE_SQL}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ( $driver_name eq 'Pg' ) { |
75
|
0
|
|
|
|
|
0
|
my $pg = Otogiri::Plugin::TableInfo::Pg->new($self); |
76
|
0
|
|
|
|
|
0
|
return $pg->show_create_view($view_name); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
Carp::carp "unsupported driver : $driver_name"; |
80
|
0
|
|
|
|
|
0
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub desc { |
84
|
2
|
|
|
2
|
1
|
3222
|
my ($self, $table_name) = @_; |
85
|
2
|
|
|
|
|
6
|
$self->show_create_table($table_name); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |