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
|
|
82
|
use strict; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
359
|
|
6
|
11
|
|
|
11
|
|
64
|
use warnings; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
328
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
58
|
use Carp qw(croak); |
|
11
|
|
|
|
|
31
|
|
|
11
|
|
|
|
|
582
|
|
9
|
11
|
|
|
11
|
|
68
|
use List::MoreUtils qw(all); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
155
|
|
10
|
11
|
|
|
11
|
|
8014
|
use Moo; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
74
|
|
11
|
11
|
|
|
11
|
|
10699
|
use SQL::Translator; |
|
11
|
|
|
|
|
3010110
|
|
|
11
|
|
|
|
|
457
|
|
12
|
11
|
|
|
11
|
|
107
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
603
|
|
13
|
11
|
|
|
11
|
|
78
|
use YAML::Tiny; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
571
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
76
|
use MySQL::Workbench::Parser::Column; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
252
|
|
16
|
11
|
|
|
11
|
|
58
|
use MySQL::Workbench::Parser::Index; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
230
|
|
17
|
11
|
|
|
11
|
|
6982
|
use MySQL::Workbench::Parser::MySQLParser; |
|
11
|
|
|
|
|
47
|
|
|
11
|
|
|
|
|
11045
|
|
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
|
24
|
my $self = shift; |
88
|
2
|
|
|
|
|
7
|
$self->_parse; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub as_hash { |
93
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
5
|
my @columns; |
96
|
2
|
|
|
|
|
4
|
for my $column ( @{$self->columns} ) { |
|
2
|
|
|
|
|
39
|
|
97
|
5
|
|
|
|
|
26
|
push @columns, $column->as_hash; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
15
|
my %info = ( |
101
|
|
|
|
|
|
|
name => $self->name, |
102
|
|
|
|
|
|
|
columns => \@columns, |
103
|
|
|
|
|
|
|
definition => $self->definition, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
2
|
50
|
|
|
|
8
|
$info{comment} = $self->comment if $self->comment; |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
8
|
return \%info; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _parse { |
112
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
8
|
my $node = $self->node; |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
4
|
my @columns; |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
8
|
my $definition = $node->findvalue( './value[@key="sqlDefinition"]' ); |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
310
|
$definition .= ';' if ';' ne substr $definition, -1; |
121
|
2
|
|
|
|
|
13
|
$self->_set_definition( $definition ); |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
63
|
my $translator = SQL::Translator->new; |
124
|
2
|
|
|
|
|
2077
|
my $sub = $translator->parser( 'MySQL::Workbench::Parser::MySQLParser' ); |
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
520
|
$sub->( $translator, $definition ); |
127
|
2
|
|
|
|
|
4281
|
my ($view) = $translator->schema->get_views; |
128
|
|
|
|
|
|
|
|
129
|
2
|
50
|
|
|
|
236
|
croak 'Error in parsing the VIEW' if !$view; |
130
|
|
|
|
|
|
|
|
131
|
2
|
50
|
|
|
|
6
|
my %map = %{ $self->column_mapping || {} }; |
|
2
|
|
|
|
|
41
|
|
132
|
2
|
|
|
|
|
92
|
for my $field ( $view->fields ) { |
133
|
5
|
|
|
|
|
165
|
my $column_obj; |
134
|
|
|
|
|
|
|
|
135
|
5
|
|
|
|
|
24
|
my ($table, $column) = split /\./, $field; |
136
|
5
|
100
|
|
|
|
14
|
if ( $column ) { |
137
|
1
|
|
|
|
|
4
|
$column_obj = $map{$table}->{$column}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
4
|
|
|
|
|
8
|
$column = $table; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
VIEWTABLE: |
143
|
4
|
|
|
|
|
78
|
for my $view_table ( $view->tables ) { |
144
|
5
|
|
|
|
|
255
|
$column_obj = $map{$view_table}->{$column}; |
145
|
5
|
100
|
|
|
|
19
|
last VIEWTABLE if $column_obj; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
5
|
50
|
|
|
|
21
|
push @columns, $column_obj if $column_obj; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
40
|
$self->_set_columns( \@columns ); |
153
|
2
|
|
|
|
|
61
|
$self->_set_tables( [ $view->tables ] ); |
154
|
|
|
|
|
|
|
|
155
|
2
|
|
|
|
|
37
|
my $comment = $node->findvalue( './value[@key="comment"]' ); |
156
|
2
|
50
|
|
|
|
769
|
$self->_set_comment( $comment ) if $comment; |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
8
|
my $name = $node->findvalue( './value[@key="name"]' ); |
159
|
2
|
|
|
|
|
283
|
$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__ |