line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SQLiteViewerLite::Base::Sqliteviewerlite; |
2
|
1
|
|
|
1
|
|
1201
|
use Mojo::Base 'Mojolicious::Controller'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
3
|
1
|
|
|
1
|
|
1029
|
use Data::Page; |
|
1
|
|
|
|
|
6228
|
|
|
1
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub default { |
6
|
6
|
|
|
6
|
0
|
58306
|
my $self = shift; |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
|
|
27
|
my $plugin = $self->stash->{plugin}; |
9
|
6
|
|
|
|
|
65
|
my $command = $plugin->command; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
|
|
95
|
my $database = $command->show_databases; |
12
|
6
|
|
|
|
|
25
|
my $current_database = $command->current_database; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
|
|
45
|
$self->render( |
15
|
|
|
|
|
|
|
databases => $database, |
16
|
|
|
|
|
|
|
current_database => $current_database, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub tables { |
21
|
4
|
|
|
4
|
0
|
110314
|
my $self = shift;; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
22
|
my $plugin = $self->stash->{plugin}; |
24
|
4
|
|
|
|
|
51
|
my $command = $plugin->command; |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
55
|
my $params = $command->params($self); |
27
|
4
|
|
|
|
|
42
|
my $rule = [ |
28
|
|
|
|
|
|
|
database => {default => ''} => [ |
29
|
|
|
|
|
|
|
'safety_name' |
30
|
|
|
|
|
|
|
] |
31
|
|
|
|
|
|
|
]; |
32
|
4
|
|
|
|
|
40
|
my $vresult = $plugin->validator->validate($params, $rule); |
33
|
4
|
|
|
|
|
332
|
my $database = $vresult->data->{database}; |
34
|
4
|
|
|
|
|
39
|
my $tables = $command->show_tables($database); |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
60
|
return $self->render( |
37
|
|
|
|
|
|
|
database => $database, |
38
|
|
|
|
|
|
|
tables => $tables |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub table { |
43
|
10
|
|
|
10
|
0
|
160763
|
my $self = shift;; |
44
|
|
|
|
|
|
|
|
45
|
10
|
|
|
|
|
42
|
my $plugin = $self->stash->{plugin}; |
46
|
10
|
|
|
|
|
120
|
my $command = $plugin->command; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Validation |
49
|
10
|
|
|
|
|
145
|
my $params = $command->params($self); |
50
|
10
|
|
|
|
|
93
|
my $rule = [ |
51
|
|
|
|
|
|
|
database => {default => ''} => [ |
52
|
|
|
|
|
|
|
'safety_name' |
53
|
|
|
|
|
|
|
], |
54
|
|
|
|
|
|
|
table => {default => ''} => [ |
55
|
|
|
|
|
|
|
'safety_name' |
56
|
|
|
|
|
|
|
] |
57
|
|
|
|
|
|
|
]; |
58
|
10
|
|
|
|
|
96
|
my $vresult = $plugin->validator->validate($params, $rule); |
59
|
10
|
|
|
|
|
790
|
my $database = $vresult->data->{database}; |
60
|
10
|
|
|
|
|
218
|
my $table = $vresult->data->{table}; |
61
|
|
|
|
|
|
|
|
62
|
10
|
|
|
|
|
101
|
my $table_def = $command->show_create_table($database, $table); |
63
|
|
|
|
|
|
|
|
64
|
10
|
|
|
|
|
148
|
return $self->render( |
65
|
|
|
|
|
|
|
database => $database, |
66
|
|
|
|
|
|
|
table => $table, |
67
|
|
|
|
|
|
|
table_def => $table_def, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub showcreatetables { |
72
|
3
|
|
|
3
|
0
|
45050
|
my $self = shift;; |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
17
|
my $plugin = $self->stash->{plugin}; |
75
|
3
|
|
|
|
|
39
|
my $command = $plugin->command; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Validation |
78
|
3
|
|
|
|
|
46
|
my $params = $command->params($self); |
79
|
3
|
|
|
|
|
22
|
my $rule = [ |
80
|
|
|
|
|
|
|
database => {default => ''} => [ |
81
|
|
|
|
|
|
|
'safety_name' |
82
|
|
|
|
|
|
|
] |
83
|
|
|
|
|
|
|
]; |
84
|
3
|
|
|
|
|
27
|
my $vresult = $plugin->validator->validate($params, $rule); |
85
|
3
|
|
|
|
|
275
|
my $database = $vresult->data->{database}; |
86
|
3
|
|
|
|
|
36
|
my $tables = $command->show_tables($database); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Get create tables |
89
|
3
|
|
|
|
|
10
|
my $create_tables = {}; |
90
|
3
|
|
|
|
|
10
|
for my $table (@$tables) { |
91
|
9
|
|
|
|
|
30
|
$create_tables->{$table} = $plugin->command->show_create_table($database, $table); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->render( |
95
|
3
|
|
|
|
|
60
|
database => $database, |
96
|
|
|
|
|
|
|
create_tables => $create_tables |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub showselecttables { |
101
|
3
|
|
|
3
|
0
|
57124
|
my $self = shift;; |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
12
|
my $plugin = $self->stash->{plugin}; |
104
|
3
|
|
|
|
|
35
|
my $command = $plugin->command; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Validation |
107
|
3
|
|
|
|
|
46
|
my $params = $command->params($self); |
108
|
3
|
|
|
|
|
18
|
my $rule = [ |
109
|
|
|
|
|
|
|
database => {default => ''} => [ |
110
|
|
|
|
|
|
|
'safety_name' |
111
|
|
|
|
|
|
|
] |
112
|
|
|
|
|
|
|
]; |
113
|
3
|
|
|
|
|
27
|
my $vresult = $plugin->validator->validate($params, $rule); |
114
|
3
|
|
|
|
|
234
|
my $database = $vresult->data->{database}; |
115
|
3
|
|
|
|
|
32
|
my $tables = $command->show_tables($database); |
116
|
|
|
|
|
|
|
|
117
|
3
|
|
|
|
|
40
|
$self->render( |
118
|
|
|
|
|
|
|
database => $database, |
119
|
|
|
|
|
|
|
tables => $tables |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub showprimarykeys { |
124
|
4
|
|
|
4
|
0
|
91502
|
my $self = shift;; |
125
|
|
|
|
|
|
|
|
126
|
4
|
|
|
|
|
20
|
my $plugin = $self->stash->{plugin}; |
127
|
4
|
|
|
|
|
46
|
my $command = $plugin->command; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Validation |
130
|
4
|
|
|
|
|
54
|
my $params = $command->params($self); |
131
|
4
|
|
|
|
|
31
|
my $rule = [ |
132
|
|
|
|
|
|
|
database => {default => ''} => [ |
133
|
|
|
|
|
|
|
'safety_name' |
134
|
|
|
|
|
|
|
], |
135
|
|
|
|
|
|
|
]; |
136
|
4
|
|
|
|
|
38
|
my $vresult = $plugin->validator->validate($params, $rule); |
137
|
4
|
|
|
|
|
428
|
my $database = $vresult->data->{database}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Get primary keys |
140
|
4
|
|
|
|
|
119
|
my $primary_keys = $command->show_primary_keys($database); |
141
|
|
|
|
|
|
|
|
142
|
4
|
|
|
|
|
77
|
$self->render( |
143
|
|
|
|
|
|
|
database => $database, |
144
|
|
|
|
|
|
|
primary_keys => $primary_keys |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub shownullallowedcolumns { |
149
|
4
|
|
|
4
|
0
|
76006
|
my $self = shift;; |
150
|
|
|
|
|
|
|
|
151
|
4
|
|
|
|
|
23
|
my $plugin = $self->stash->{plugin}; |
152
|
4
|
|
|
|
|
55
|
my $command = $plugin->command; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Validation |
155
|
4
|
|
|
|
|
62
|
my $params = $command->params($self); |
156
|
4
|
|
|
|
|
31
|
my $rule = [ |
157
|
|
|
|
|
|
|
database => {default => ''} => [ |
158
|
|
|
|
|
|
|
'safety_name' |
159
|
|
|
|
|
|
|
], |
160
|
|
|
|
|
|
|
]; |
161
|
4
|
|
|
|
|
40
|
my $vresult = $plugin->validator->validate($params, $rule); |
162
|
4
|
|
|
|
|
474
|
my $database = $vresult->data->{database}; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# Get null allowed columns |
165
|
4
|
|
|
|
|
66
|
my $null_allowed_columns = $command->show_null_allowed_columns($database); |
166
|
|
|
|
|
|
|
|
167
|
4
|
|
|
|
|
68
|
$self->render( |
168
|
|
|
|
|
|
|
database => $database, |
169
|
|
|
|
|
|
|
null_allowed_columns => $null_allowed_columns |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub select { |
174
|
11
|
|
|
11
|
0
|
2362837
|
my $self = shift;; |
175
|
|
|
|
|
|
|
|
176
|
11
|
|
|
|
|
50
|
my $plugin = $self->stash->{plugin}; |
177
|
11
|
|
|
|
|
117
|
my $command = $plugin->command; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Validation |
180
|
11
|
|
|
|
|
152
|
my $params = $command->params($self); |
181
|
11
|
|
|
|
|
155
|
my $rule = [ |
182
|
|
|
|
|
|
|
database => {default => ''} => [ |
183
|
|
|
|
|
|
|
'safety_name' |
184
|
|
|
|
|
|
|
], |
185
|
|
|
|
|
|
|
table => {default => ''} => [ |
186
|
|
|
|
|
|
|
'safety_name' |
187
|
|
|
|
|
|
|
], |
188
|
|
|
|
|
|
|
page => {default => 1} => [ |
189
|
|
|
|
|
|
|
'uint' |
190
|
|
|
|
|
|
|
], |
191
|
|
|
|
|
|
|
condition_column => [ |
192
|
|
|
|
|
|
|
'safety_name' |
193
|
|
|
|
|
|
|
], |
194
|
|
|
|
|
|
|
condition_value => [ |
195
|
|
|
|
|
|
|
'not_blank' |
196
|
|
|
|
|
|
|
] |
197
|
|
|
|
|
|
|
]; |
198
|
11
|
|
|
|
|
106
|
my $vresult = $plugin->validator->validate($params, $rule); |
199
|
11
|
|
|
|
|
1903
|
my $database = $vresult->data->{database}; |
200
|
11
|
|
|
|
|
198
|
my $table = $vresult->data->{table}; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Where |
203
|
11
|
|
|
|
|
193
|
my $column = $vresult->data->{condition_column}; |
204
|
11
|
|
|
|
|
228
|
my $value = $vresult->data->{condition_value}; |
205
|
|
|
|
|
|
|
|
206
|
11
|
|
|
|
|
62
|
my $where; |
207
|
11
|
100
|
66
|
|
|
53
|
if (defined $column && defined $value) { |
208
|
1
|
|
|
|
|
11
|
$where = $plugin->dbi->where; |
209
|
1
|
|
|
|
|
122
|
$where->clause(":${column}{like}"); |
210
|
1
|
|
|
|
|
25
|
$where->param({$column => $value}); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# Limit |
214
|
11
|
|
|
|
|
187
|
my $page = $vresult->data->{page}; |
215
|
11
|
|
|
|
|
61
|
my $count = 100; |
216
|
11
|
|
|
|
|
31
|
my $offset = ($page - 1) * $count; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Get null allowed columns |
219
|
11
|
|
|
|
|
80
|
my $result = $plugin->dbi->select( |
220
|
|
|
|
|
|
|
table => "$database.$table", |
221
|
|
|
|
|
|
|
where => $where, |
222
|
|
|
|
|
|
|
append => "limit $offset, $count" |
223
|
|
|
|
|
|
|
); |
224
|
9
|
|
|
|
|
7807
|
my $header = $result->header; |
225
|
9
|
|
|
|
|
435
|
my $rows = $result->fetch_all; |
226
|
9
|
|
|
|
|
7946
|
my $sql = $plugin->dbi->last_sql; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# Pager |
229
|
9
|
|
|
|
|
316
|
my $total = $plugin->dbi->select( |
230
|
|
|
|
|
|
|
'count(*)', |
231
|
|
|
|
|
|
|
table => "$database.$table", |
232
|
|
|
|
|
|
|
where => $where |
233
|
|
|
|
|
|
|
)->value; |
234
|
9
|
|
|
|
|
6377
|
my $pager = Data::Page->new($total, $count, $page); |
235
|
|
|
|
|
|
|
|
236
|
9
|
|
|
|
|
646
|
$self->render( |
237
|
|
|
|
|
|
|
database => $database, |
238
|
|
|
|
|
|
|
table => $table, |
239
|
|
|
|
|
|
|
header => $header, |
240
|
|
|
|
|
|
|
rows => $rows, |
241
|
|
|
|
|
|
|
sql => $sql, |
242
|
|
|
|
|
|
|
pager => $pager |
243
|
|
|
|
|
|
|
); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
1; |