line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MySQL::Util::Lite::Table; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use Modern::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
110
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
6424
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
59
|
use Method::Signatures; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
363
|
use Data::Printer alias => 'pdump'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
1679
|
use MySQL::Util::Lite::ForeignKey; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
11
|
1
|
|
|
1
|
|
508
|
use MySQL::Util::Lite::PrimaryKey; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
46
|
|
12
|
1
|
|
|
1
|
|
560
|
use MySQL::Util::Lite::AlternateKey; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
94
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'MySQL::Util::Lite::Roles::NewColumn'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has name => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => 'Str', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has schema_name => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => 'Str', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has columns => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'ArrayRef[MySQL::Util::Lite::Column]', |
31
|
|
|
|
|
|
|
lazy => 1, |
32
|
|
|
|
|
|
|
builder => '_build_columns', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has _util => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => 'MySQL::Util', |
38
|
|
|
|
|
|
|
required => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
1
|
0
|
|
1
|
|
685
|
method get_fq_name { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return sprintf('%s.%s', $self->schema_name, $self->name); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
1
|
0
|
|
1
|
|
749
|
method get_parent_tables { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my %seen; |
49
|
|
|
|
|
|
|
my @ret; |
50
|
0
|
|
|
|
|
|
my @fks = $self->get_foreign_keys; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
foreach my $fk (@fks) { |
53
|
0
|
|
|
|
|
|
foreach my $col ( @{ $fk->column_constraints } ) { |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $fq_table_name = sprintf( "%s.%s", |
56
|
|
|
|
|
|
|
$col->parent_schema_name, $col->parent_table_name ); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( !$seen{$fq_table_name} ) { |
59
|
0
|
|
|
|
|
|
push @ret, |
60
|
|
|
|
|
|
|
MySQL::Util::Lite::Table->new( |
61
|
|
|
|
|
|
|
name => $col->parent_table_name, |
62
|
|
|
|
|
|
|
schema_name => $col->parent_schema_name, |
63
|
|
|
|
|
|
|
_util => $self->_util |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$seen{$fq_table_name}++; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return @ret; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
0
|
|
1
|
|
980
|
method get_foreign_keys { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $fks_href = $self->_util->get_fk_constraints( $self->name ); |
77
|
0
|
|
|
|
|
|
my @fks; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
foreach my $fk_name ( keys %$fks_href ) { |
80
|
0
|
|
|
|
|
|
push @fks, |
81
|
|
|
|
|
|
|
MySQL::Util::Lite::ForeignKey->new( |
82
|
|
|
|
|
|
|
name => $fk_name, |
83
|
|
|
|
|
|
|
_util => $self->_util, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return @fks; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
0
|
|
1
|
|
811
|
method has_parents { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my @parents = $self->get_parent_tables; |
93
|
0
|
0
|
|
|
|
|
if (@parents) { |
94
|
0
|
|
|
|
|
|
return 1; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
0
|
|
1
|
|
743
|
method get_autoinc_column { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $cols = $self->columns; |
103
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
104
|
0
|
0
|
|
|
|
|
if ( $col->is_autoinc ) { |
105
|
0
|
|
|
|
|
|
return $col; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
1
|
0
|
0
|
1
|
|
3646
|
method get_column (Str :$name) { |
|
0
|
0
|
0
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $cols = $self->columns; |
113
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
114
|
0
|
0
|
|
|
|
|
if ( $col->name eq $name ) { |
115
|
0
|
|
|
|
|
|
return $col; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
1
|
0
|
|
1
|
|
1015
|
method get_primary_key () { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $pk_name = $self->_util->get_pk_name($self->name); |
123
|
0
|
0
|
|
|
|
|
if ($pk_name) { |
124
|
0
|
|
|
|
|
|
return MySQL::Util::Lite::PrimaryKey->new( |
125
|
|
|
|
|
|
|
name => $pk_name, |
126
|
|
|
|
|
|
|
table_name => $self->get_fq_name, |
127
|
|
|
|
|
|
|
_util => $self->_util, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
1
|
0
|
|
1
|
|
843
|
method get_alternate_keys() { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $href = $self->_util->get_ak_constraints($self->name); |
137
|
0
|
|
|
|
|
|
my @aks; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
foreach my $ak_name ( keys %$href ) { |
140
|
0
|
|
|
|
|
|
push @aks, |
141
|
|
|
|
|
|
|
MySQL::Util::Lite::AlternateKey->new( |
142
|
|
|
|
|
|
|
name => $ak_name, |
143
|
|
|
|
|
|
|
_util => $self->_util, |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return @aks; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
1
|
0
|
|
1
|
|
866
|
method get_columns { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return @{ $self->columns }; |
|
0
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
1
|
0
|
|
1
|
|
736
|
method _build_columns{ |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my @cols; |
157
|
0
|
|
|
|
|
|
my $aref = $self->_util->describe_table( $self->get_fq_name ); |
158
|
0
|
|
|
|
|
|
foreach my $col (@$aref) { |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
push @cols, $self->new_column($col); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return \@cols; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |