line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MySQL::Workbench::Parser::View; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A view of the ER model |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
81
|
use strict; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
407
|
|
6
|
11
|
|
|
11
|
|
62
|
use warnings; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
369
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
63
|
use Carp qw(croak); |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
614
|
|
9
|
11
|
|
|
11
|
|
72
|
use List::MoreUtils qw(all); |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
124
|
|
10
|
11
|
|
|
11
|
|
8033
|
use Moo; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
69
|
|
11
|
11
|
|
|
11
|
|
10590
|
use SQL::Translator; |
|
11
|
|
|
|
|
3197359
|
|
|
11
|
|
|
|
|
491
|
|
12
|
11
|
|
|
11
|
|
125
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
676
|
|
13
|
11
|
|
|
11
|
|
78
|
use YAML::Tiny; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
570
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
72
|
use MySQL::Workbench::Parser::Column; |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
249
|
|
16
|
11
|
|
|
11
|
|
63
|
use MySQL::Workbench::Parser::Index; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
227
|
|
17
|
11
|
|
|
11
|
|
7305
|
use MySQL::Workbench::Parser::MySQLParser; |
|
11
|
|
|
|
|
39
|
|
|
11
|
|
|
|
|
11275
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has node => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
isa => sub { |
25
|
|
|
|
|
|
|
blessed $_[0] && $_[0]->isa( 'XML::LibXML::Node' ); |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has parser => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
isa => sub { |
33
|
|
|
|
|
|
|
blessed $_[0] && $_[0]->isa( 'MySQL::Workbench::Parser' ); |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has columns => ( |
38
|
|
|
|
|
|
|
is => 'rwp', |
39
|
|
|
|
|
|
|
isa => sub { |
40
|
|
|
|
|
|
|
ref $_[0] && ref $_[0] eq 'ARRAY' && |
41
|
|
|
|
|
|
|
all{ blessed $_ && $_->isa( 'MySQL::Workbench::Parser::Column' ) }@{$_[0]} |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
lazy => 1, |
44
|
|
|
|
|
|
|
default => sub { [] }, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has tables => ( |
48
|
|
|
|
|
|
|
is => 'rwp', |
49
|
|
|
|
|
|
|
isa => sub { |
50
|
|
|
|
|
|
|
ref $_[0] && ref $_[0] eq 'ARRAY' |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
lazy => 1, |
53
|
|
|
|
|
|
|
default => sub { [] }, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has comment => (is => 'rwp'); |
57
|
|
|
|
|
|
|
has name => (is => 'rwp'); |
58
|
|
|
|
|
|
|
has definition => (is => 'rwp'); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has column_mapping => ( |
61
|
|
|
|
|
|
|
is => 'rwp', |
62
|
|
|
|
|
|
|
lazy => 1, |
63
|
|
|
|
|
|
|
isa => sub { |
64
|
|
|
|
|
|
|
ref $_[0] && ref $_[0] eq 'HASH' |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
default => sub { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my %map; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
TABLE: |
72
|
|
|
|
|
|
|
for my $table ( @{ $self->parser->tables } ) { |
73
|
|
|
|
|
|
|
my $name = $table->name; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
for my $col ( @{ $table->columns } ) { |
76
|
|
|
|
|
|
|
my $col_name = $col->name; |
77
|
|
|
|
|
|
|
$map{$name}->{$col_name} = $col; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
\%map; |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub BUILD { |
87
|
2
|
|
|
2
|
1
|
21
|
my $self = shift; |
88
|
2
|
|
|
|
|
9
|
$self->_parse; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub as_hash { |
93
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
6
|
my @columns; |
96
|
2
|
|
|
|
|
3
|
for my $column ( @{$self->columns} ) { |
|
2
|
|
|
|
|
41
|
|
97
|
5
|
|
|
|
|
31
|
push @columns, $column->as_hash; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
17
|
my %info = ( |
101
|
|
|
|
|
|
|
name => $self->name, |
102
|
|
|
|
|
|
|
columns => \@columns, |
103
|
|
|
|
|
|
|
definition => $self->definition, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
2
|
50
|
|
|
|
10
|
$info{comment} = $self->comment if $self->comment; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
8
|
return \%info; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _parse { |
112
|
2
|
|
|
2
|
|
15
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
11
|
my $node = $self->node; |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
4
|
my @columns; |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
9
|
my $definition = $node->findvalue( './value[@key="sqlDefinition"]' ); |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
351
|
$definition .= ';' if ';' ne substr $definition, -1; |
121
|
2
|
|
|
|
|
16
|
$self->_set_definition( $definition ); |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
65
|
my $translator = SQL::Translator->new; |
124
|
2
|
|
|
|
|
2268
|
my $sub = $translator->parser( 'MySQL::Workbench::Parser::MySQLParser' ); |
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
530
|
$sub->( $translator, $definition ); |
127
|
2
|
|
|
|
|
4763
|
my ($view) = $translator->schema->get_views; |
128
|
|
|
|
|
|
|
|
129
|
2
|
50
|
|
|
|
312
|
croak 'Error in parsing the VIEW' if !$view; |
130
|
|
|
|
|
|
|
|
131
|
2
|
50
|
|
|
|
4
|
my %map = %{ $self->column_mapping || {} }; |
|
2
|
|
|
|
|
45
|
|
132
|
2
|
|
|
|
|
80
|
for my $field ( $view->fields ) { |
133
|
5
|
|
|
|
|
196
|
my $column_obj; |
134
|
|
|
|
|
|
|
|
135
|
5
|
|
|
|
|
44
|
my ($table, $column) = split /\./, $field; |
136
|
5
|
100
|
|
|
|
15
|
if ( $column ) { |
137
|
1
|
|
|
|
|
5
|
$column_obj = $map{$table}->{$column}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
4
|
|
|
|
|
8
|
$column = $table; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
VIEWTABLE: |
143
|
4
|
|
|
|
|
87
|
for my $view_table ( $view->tables ) { |
144
|
5
|
|
|
|
|
277
|
$column_obj = $map{$view_table}->{$column}; |
145
|
5
|
100
|
|
|
|
21
|
last VIEWTABLE if $column_obj; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
5
|
50
|
|
|
|
22
|
push @columns, $column_obj if $column_obj; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
46
|
$self->_set_columns( \@columns ); |
153
|
2
|
|
|
|
|
63
|
$self->_set_tables( [ $view->tables ] ); |
154
|
|
|
|
|
|
|
|
155
|
2
|
|
|
|
|
44
|
my $comment = $node->findvalue( './value[@key="comment"]' ); |
156
|
2
|
50
|
|
|
|
1003
|
$self->_set_comment( $comment ) if $comment; |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
8
|
my $name = $node->findvalue( './value[@key="name"]' ); |
159
|
2
|
|
|
|
|
316
|
$self->_set_name( $name ); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub get_datatype { |
164
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $self->parser->get_datatype( @_ ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |