line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SQLiteViewerLite::Command; |
2
|
3
|
|
|
3
|
|
23
|
use Mojo::Base 'Mojolicious::Plugin::SQLiteViewerLite::Base::Command'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'dbi'; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
0
|
25
|
sub current_database { 'main' } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub show_primary_key { |
9
|
15
|
|
|
15
|
0
|
47
|
my ($self, $database, $table) = @_; |
10
|
15
|
|
50
|
|
|
45
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
|
|
62
|
my @primary_keys = $self->dbi->dbh->primary_key(undef, $database, $table); |
13
|
15
|
|
|
|
|
23769
|
my $primary_key = '(' . join(', ', @primary_keys) . ')'; |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
59
|
return $primary_key; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_null_allowed_column { |
19
|
15
|
|
|
15
|
0
|
46
|
my ($self, $database, $table) = @_; |
20
|
|
|
|
|
|
|
|
21
|
15
|
|
|
|
|
47
|
my $sql = "pragma table_info($table)"; |
22
|
15
|
|
|
|
|
62
|
my $rows = $self->dbi->execute($sql)->all; |
23
|
15
|
|
|
|
|
7053
|
my $null_allowed_column = []; |
24
|
15
|
|
|
|
|
57
|
for my $row (@$rows) { |
25
|
30
|
100
|
|
|
|
96
|
push @$null_allowed_column, $row->{name} if !$row->{notnull}; |
26
|
|
|
|
|
|
|
} |
27
|
15
|
|
|
|
|
69
|
return $null_allowed_column; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub show_database_engines { |
31
|
0
|
|
|
0
|
0
|
0
|
my ($self, $database) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $tables = $self->show_tables($database); |
34
|
0
|
|
|
|
|
0
|
my $database_engines = {}; |
35
|
0
|
|
|
|
|
0
|
for my $table (@$tables) { |
36
|
0
|
|
|
|
|
0
|
my $database_engine = $self->show_database_engine($database, $table); |
37
|
0
|
|
|
|
|
0
|
$database_engines->{$table} = $database_engine; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
return $database_engines; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub show_database_engine { |
44
|
0
|
|
|
0
|
0
|
0
|
my ($self, $database, $table) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
0
|
|
|
0
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
47
|
0
|
|
|
|
|
0
|
my $database_engine = ''; |
48
|
0
|
0
|
|
|
|
0
|
if ($show_create_table =~ /ENGINE=(.+?)(\s+|$)/i) { |
49
|
0
|
|
|
|
|
0
|
$database_engine = $1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return $database_engine; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
8
|
|
|
8
|
0
|
55
|
sub show_databases { ['main'] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub show_tables { |
58
|
24
|
|
|
24
|
0
|
78
|
my ($self, $database) = @_; |
59
|
|
|
|
|
|
|
|
60
|
24
|
|
|
|
|
99
|
my $sql = <<"EOS"; |
61
|
|
|
|
|
|
|
select distinct(name) |
62
|
|
|
|
|
|
|
from $database.sqlite_master |
63
|
|
|
|
|
|
|
where type in ('table', 'view') |
64
|
|
|
|
|
|
|
order by name; |
65
|
|
|
|
|
|
|
EOS |
66
|
|
|
|
|
|
|
|
67
|
24
|
|
|
|
|
104
|
my $tables = $self->dbi->execute($sql)->values; |
68
|
|
|
|
|
|
|
|
69
|
24
|
|
|
|
|
16634
|
return $tables; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_create_table { |
73
|
40
|
|
|
40
|
0
|
199
|
my ($self, $database, $table) = @_; |
74
|
|
|
|
|
|
|
|
75
|
40
|
|
|
|
|
176
|
my $sql = <<"EOS"; |
76
|
|
|
|
|
|
|
select sql |
77
|
|
|
|
|
|
|
from $database.sqlite_master |
78
|
|
|
|
|
|
|
where type in ('table', 'type') and name = '$table' |
79
|
|
|
|
|
|
|
EOS |
80
|
|
|
|
|
|
|
|
81
|
40
|
|
|
|
|
164
|
my $create_table = $self->dbi->execute($sql)->value; |
82
|
|
|
|
|
|
|
|
83
|
40
|
100
|
|
|
|
21771
|
return unless defined $create_table; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Format |
86
|
31
|
|
|
|
|
175
|
$create_table =~ s/\(/(\n /; |
87
|
31
|
|
|
|
|
86
|
$create_table =~ s/, /,\n /g; |
88
|
31
|
|
|
|
|
171
|
$create_table =~ s/\)$/\n)/; |
89
|
|
|
|
|
|
|
|
90
|
31
|
|
|
|
|
159
|
return $create_table; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |