line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SQLiteViewerLite::Command; |
2
|
2
|
|
|
2
|
|
12
|
use Mojo::Base 'Mojolicious::Plugin::SQLiteViewerLite::Base::Command'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'dbi'; |
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
0
|
17
|
sub current_database { 'main' } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub show_primary_key { |
9
|
12
|
|
|
12
|
0
|
28
|
my ($self, $database, $table) = @_; |
10
|
12
|
|
50
|
|
|
33
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
11
|
|
|
|
|
|
|
|
12
|
12
|
|
|
|
|
40
|
my @primary_keys = $self->dbi->dbh->primary_key(undef, $database, $table); |
13
|
12
|
|
|
|
|
12465
|
my $primary_key = '(' . join(', ', @primary_keys) . ')'; |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
|
|
134
|
return $primary_key; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_null_allowed_column { |
19
|
12
|
|
|
12
|
0
|
24
|
my ($self, $database, $table) = @_; |
20
|
|
|
|
|
|
|
|
21
|
12
|
|
|
|
|
33
|
my $sql = "pragma table_info($table)"; |
22
|
12
|
|
|
|
|
38
|
my $rows = $self->dbi->execute($sql)->all; |
23
|
12
|
|
|
|
|
6424
|
my $null_allowed_column = []; |
24
|
12
|
|
|
|
|
28
|
for my $row (@$rows) { |
25
|
24
|
100
|
|
|
|
68
|
push @$null_allowed_column, $row->{name} if !$row->{notnull}; |
26
|
|
|
|
|
|
|
} |
27
|
12
|
|
|
|
|
49
|
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
|
6
|
|
|
6
|
0
|
25
|
sub show_databases { ['main'] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub show_tables { |
58
|
18
|
|
|
18
|
0
|
48
|
my ($self, $database) = @_; |
59
|
|
|
|
|
|
|
|
60
|
18
|
|
|
|
|
80
|
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
|
18
|
|
|
|
|
121
|
my $tables = $self->dbi->execute($sql)->values; |
68
|
|
|
|
|
|
|
|
69
|
18
|
|
|
|
|
15455
|
return $tables; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_create_table { |
73
|
31
|
|
|
31
|
0
|
114
|
my ($self, $database, $table) = @_; |
74
|
|
|
|
|
|
|
|
75
|
31
|
|
|
|
|
145
|
my $sql = <<"EOS"; |
76
|
|
|
|
|
|
|
select sql |
77
|
|
|
|
|
|
|
from $database.sqlite_master |
78
|
|
|
|
|
|
|
where type in ('table', 'type') and name = '$table' |
79
|
|
|
|
|
|
|
EOS |
80
|
|
|
|
|
|
|
|
81
|
31
|
|
|
|
|
110
|
my $create_table = $self->dbi->execute($sql)->value; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Format |
84
|
31
|
|
|
|
|
18953
|
$create_table =~ s/\(/(\n /; |
85
|
31
|
|
|
|
|
140
|
$create_table =~ s/, /,\n /g; |
86
|
31
|
|
|
|
|
152
|
$create_table =~ s/\)$/\n)/; |
87
|
|
|
|
|
|
|
|
88
|
31
|
|
|
|
|
154
|
return $create_table; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |