| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MySQL::Util::Lite::Table; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use Modern::Perl; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
6
|
1
|
|
|
1
|
|
119
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
6581
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
8
|
1
|
|
|
1
|
|
60
|
use Method::Signatures; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
9
|
1
|
|
|
1
|
|
353
|
use Data::Printer alias => 'pdump'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
10
|
1
|
|
|
1
|
|
1727
|
use MySQL::Util::Lite::ForeignKey; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
75
|
|
|
11
|
1
|
|
|
1
|
|
587
|
use MySQL::Util::Lite::PrimaryKey; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
50
|
|
|
12
|
1
|
|
|
1
|
|
569
|
use MySQL::Util::Lite::AlternateKey; |
|
|
1
|
|
|
|
|
3
|
|
|
|
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
|
|
655
|
method get_fq_name { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return sprintf( '%s.%s', $self->schema_name, $self->name ); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
0
|
0
|
1
|
|
3780
|
method get_parent_tables (Str :$column_name) { |
|
|
0
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ($column_name) { |
|
49
|
0
|
|
|
|
|
|
return $self->_get_column_parent_tables( column_name => $column_name ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
else { |
|
52
|
0
|
|
|
|
|
|
return $self->_get_parent_tables; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
0
|
0
|
1
|
|
3267
|
method _get_column_parent_tables (Str :$column_name) { |
|
|
0
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my %seen; |
|
59
|
|
|
|
|
|
|
my @ret; |
|
60
|
0
|
|
|
|
|
|
my @fks = $self->get_foreign_keys; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
foreach my $fk (@fks) { |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $con ( @{ $fk->column_constraints } ) { |
|
|
0
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ( $con->column_name eq $column_name ) { |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $fq_table_name = sprintf( "%s.%s", |
|
69
|
|
|
|
|
|
|
$con->parent_schema_name, $con->parent_table_name ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ( !$seen{$fq_table_name} ) { |
|
72
|
0
|
|
|
|
|
|
push @ret, |
|
73
|
|
|
|
|
|
|
MySQL::Util::Lite::Table->new( |
|
74
|
|
|
|
|
|
|
name => $con->parent_table_name, |
|
75
|
|
|
|
|
|
|
schema_name => $con->parent_schema_name, |
|
76
|
|
|
|
|
|
|
_util => $self->_util |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$seen{$fq_table_name}++; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return @ret; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
1
|
0
|
|
1
|
|
1093
|
method _get_parent_tables { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my %seen; |
|
91
|
|
|
|
|
|
|
my @ret; |
|
92
|
0
|
|
|
|
|
|
my @fks = $self->get_foreign_keys; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
foreach my $fk (@fks) { |
|
95
|
0
|
|
|
|
|
|
foreach my $col ( @{ $fk->column_constraints } ) { |
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $fq_table_name = sprintf( "%s.%s", |
|
98
|
|
|
|
|
|
|
$col->parent_schema_name, $col->parent_table_name ); |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ( !$seen{$fq_table_name} ) { |
|
101
|
0
|
|
|
|
|
|
push @ret, |
|
102
|
|
|
|
|
|
|
MySQL::Util::Lite::Table->new( |
|
103
|
|
|
|
|
|
|
name => $col->parent_table_name, |
|
104
|
|
|
|
|
|
|
schema_name => $col->parent_schema_name, |
|
105
|
|
|
|
|
|
|
_util => $self->_util |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$seen{$fq_table_name}++; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return @ret; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
1
|
0
|
|
1
|
|
954
|
method get_foreign_keys { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $fks_href = $self->_util->get_fk_constraints( $self->name ); |
|
119
|
0
|
|
|
|
|
|
my @fks; |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
foreach my $fk_name ( keys %$fks_href ) { |
|
122
|
0
|
|
|
|
|
|
push @fks, |
|
123
|
|
|
|
|
|
|
MySQL::Util::Lite::ForeignKey->new( |
|
124
|
|
|
|
|
|
|
name => $fk_name, |
|
125
|
|
|
|
|
|
|
_util => $self->_util, |
|
126
|
|
|
|
|
|
|
); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return @fks; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
1
|
0
|
|
1
|
|
824
|
method has_parents { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my @parents = $self->get_parent_tables; |
|
135
|
0
|
0
|
|
|
|
|
if (@parents) { |
|
136
|
0
|
|
|
|
|
|
return 1; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return 0; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
1
|
0
|
|
1
|
|
815
|
method get_autoinc_column { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $cols = $self->columns; |
|
145
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
|
146
|
0
|
0
|
|
|
|
|
if ( $col->is_autoinc ) { |
|
147
|
0
|
|
|
|
|
|
return $col; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
1
|
0
|
0
|
1
|
|
2948
|
method get_column (Str :$name) { |
|
|
0
|
0
|
0
|
0
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $cols = $self->columns; |
|
155
|
0
|
|
|
|
|
|
foreach my $col (@$cols) { |
|
156
|
0
|
0
|
|
|
|
|
if ( $col->name eq $name ) { |
|
157
|
0
|
|
|
|
|
|
return $col; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
1
|
0
|
|
1
|
|
1062
|
method get_primary_key () { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $pk_name = $self->_util->get_pk_name( $self->name ); |
|
165
|
0
|
0
|
|
|
|
|
if ($pk_name) { |
|
166
|
0
|
|
|
|
|
|
return MySQL::Util::Lite::PrimaryKey->new( |
|
167
|
|
|
|
|
|
|
name => $pk_name, |
|
168
|
|
|
|
|
|
|
table_name => $self->get_fq_name, |
|
169
|
|
|
|
|
|
|
_util => $self->_util, |
|
170
|
|
|
|
|
|
|
); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
return; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
1
|
0
|
|
1
|
|
879
|
method get_alternate_keys () { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $href = $self->_util->get_ak_constraints( $self->name ); |
|
179
|
0
|
|
|
|
|
|
my @aks; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
foreach my $ak_name ( keys %$href ) { |
|
182
|
0
|
|
|
|
|
|
push @aks, |
|
183
|
|
|
|
|
|
|
MySQL::Util::Lite::AlternateKey->new( |
|
184
|
|
|
|
|
|
|
name => $ak_name, |
|
185
|
|
|
|
|
|
|
_util => $self->_util, |
|
186
|
|
|
|
|
|
|
); |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
return @aks; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
1
|
0
|
|
1
|
|
885
|
method get_columns { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return @{ $self->columns }; |
|
|
0
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
1
|
0
|
|
1
|
|
785
|
method _build_columns { |
|
|
0
|
|
|
0
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my @cols; |
|
199
|
0
|
|
|
|
|
|
my $aref = $self->_util->describe_table( $self->get_fq_name ); |
|
200
|
0
|
|
|
|
|
|
foreach my $col (@$aref) { |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
push @cols, $self->new_column($col); |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
return \@cols; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |