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
|
|
68
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
306
|
|
6
|
11
|
|
|
11
|
|
48
|
use warnings; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
290
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
59
|
use Carp qw(croak); |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
610
|
|
9
|
11
|
|
|
11
|
|
54
|
use List::MoreUtils qw(all); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
131
|
|
10
|
11
|
|
|
11
|
|
6608
|
use Moo; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
62
|
|
11
|
11
|
|
|
11
|
|
8862
|
use SQL::Translator; |
|
11
|
|
|
|
|
2503389
|
|
|
11
|
|
|
|
|
379
|
|
12
|
11
|
|
|
11
|
|
82
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
530
|
|
13
|
11
|
|
|
11
|
|
83
|
use YAML::Tiny; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
465
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
61
|
use MySQL::Workbench::Parser::Column; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
201
|
|
16
|
11
|
|
|
11
|
|
49
|
use MySQL::Workbench::Parser::Index; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
188
|
|
17
|
11
|
|
|
11
|
|
6161
|
use MySQL::Workbench::Parser::MySQLParser; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
8413
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
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 comment => (is => 'rwp'); |
48
|
|
|
|
|
|
|
has name => (is => 'rwp'); |
49
|
|
|
|
|
|
|
has definition => (is => 'rwp'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has column_mapping => ( |
52
|
|
|
|
|
|
|
is => 'rwp', |
53
|
|
|
|
|
|
|
lazy => 1, |
54
|
|
|
|
|
|
|
isa => sub { |
55
|
|
|
|
|
|
|
ref $_[0] && ref $_[0] eq 'HASH' |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
default => sub { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my %map; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
TABLE: |
63
|
|
|
|
|
|
|
for my $table ( @{ $self->parser->tables } ) { |
64
|
|
|
|
|
|
|
my $name = $table->name; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
for my $col ( @{ $table->columns } ) { |
67
|
|
|
|
|
|
|
my $col_name = $col->name; |
68
|
|
|
|
|
|
|
$map{$name}->{$col_name} = $col; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
\%map; |
73
|
|
|
|
|
|
|
}, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub BUILD { |
78
|
2
|
|
|
2
|
1
|
18
|
my $self = shift; |
79
|
2
|
|
|
|
|
6
|
$self->_parse; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub as_hash { |
84
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
3
|
my @columns; |
87
|
2
|
|
|
|
|
4
|
for my $column ( @{$self->columns} ) { |
|
2
|
|
|
|
|
30
|
|
88
|
5
|
|
|
|
|
22
|
push @columns, $column->as_hash; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
11
|
my %info = ( |
92
|
|
|
|
|
|
|
name => $self->name, |
93
|
|
|
|
|
|
|
columns => \@columns, |
94
|
|
|
|
|
|
|
definition => $self->definition, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
2
|
50
|
|
|
|
6
|
$info{comment} = $self->comment if $self->comment; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
7
|
return \%info; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _parse { |
103
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
7
|
my $node = $self->node; |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
4
|
my @columns; |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
|
|
8
|
my $definition = $node->findvalue( './value[@key="sqlDefinition"]' ); |
110
|
|
|
|
|
|
|
|
111
|
2
|
50
|
|
|
|
215
|
$definition .= ';' if ';' ne substr $definition, -1; |
112
|
2
|
|
|
|
|
10
|
$self->_set_definition( $definition ); |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
50
|
my $translator = SQL::Translator->new; |
115
|
2
|
|
|
|
|
1645
|
my $sub = $translator->parser( 'MySQL::Workbench::Parser::MySQLParser' ); |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
413
|
$sub->( $translator, $definition ); |
118
|
2
|
|
|
|
|
3553
|
my ($view) = $translator->schema->get_views; |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
199
|
croak 'Error in parsing the VIEW' if !$view; |
121
|
|
|
|
|
|
|
|
122
|
2
|
50
|
|
|
|
4
|
my %map = %{ $self->column_mapping || {} }; |
|
2
|
|
|
|
|
37
|
|
123
|
2
|
|
|
|
|
58
|
for my $field ( $view->fields ) { |
124
|
5
|
|
|
|
|
147
|
my $column_obj; |
125
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
15
|
my ($table, $column) = split /\./, $field; |
127
|
5
|
100
|
|
|
|
27
|
if ( $column ) { |
128
|
1
|
|
|
|
|
4
|
$column_obj = $map{$table}->{$column}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else { |
131
|
4
|
|
|
|
|
7
|
$column = $table; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
VIEWTABLE: |
134
|
4
|
|
|
|
|
80
|
for my $view_table ( $view->tables ) { |
135
|
5
|
|
|
|
|
215
|
$column_obj = $map{$view_table}->{$column}; |
136
|
5
|
100
|
|
|
|
13
|
last VIEWTABLE if $column_obj; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
5
|
50
|
|
|
|
15
|
push @columns, $column_obj if $column_obj; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
2
|
|
|
|
|
34
|
$self->_set_columns( \@columns ); |
144
|
|
|
|
|
|
|
|
145
|
2
|
|
|
|
|
37
|
my $comment = $node->findvalue( './value[@key="comment"]' ); |
146
|
2
|
50
|
|
|
|
676
|
$self->_set_comment( $comment ) if $comment; |
147
|
|
|
|
|
|
|
|
148
|
2
|
|
|
|
|
7
|
my $name = $node->findvalue( './value[@key="name"]' ); |
149
|
2
|
|
|
|
|
216
|
$self->_set_name( $name ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub get_datatype { |
154
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return $self->parser->get_datatype( @_ ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__END__ |