line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DBViewer::SQLite::Command; |
2
|
2
|
|
|
2
|
|
15
|
use Mojo::Base 'Mojolicious::Plugin::DBViewer::Command'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'dbi'; |
5
|
|
|
|
|
|
|
|
6
|
17
|
|
|
17
|
0
|
109
|
sub current_database { 'main' } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub show_primary_key { |
9
|
18
|
|
|
18
|
0
|
56
|
my ($self, $database, $table) = @_; |
10
|
18
|
|
50
|
|
|
59
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
11
|
|
|
|
|
|
|
|
12
|
18
|
|
|
|
|
75
|
my @primary_keys = $self->dbi->dbh->primary_key(undef, $database, $table); |
13
|
18
|
|
|
|
|
22268
|
my $primary_key = '(' . join(', ', @primary_keys) . ')'; |
14
|
|
|
|
|
|
|
|
15
|
18
|
|
|
|
|
76
|
return $primary_key; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_null_allowed_column { |
19
|
18
|
|
|
18
|
0
|
52
|
my ($self, $database, $table) = @_; |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
|
|
67
|
my $sql = "pragma table_info($table)"; |
22
|
18
|
|
|
|
|
63
|
my $rows = $self->dbi->execute($sql)->all; |
23
|
18
|
|
|
|
|
8654
|
my $null_allowed_column = []; |
24
|
18
|
|
|
|
|
64
|
for my $row (@$rows) { |
25
|
36
|
100
|
|
|
|
111
|
push @$null_allowed_column, $row->{name} if !$row->{notnull}; |
26
|
|
|
|
|
|
|
} |
27
|
18
|
|
|
|
|
82
|
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
|
17
|
|
|
17
|
0
|
330617
|
sub show_databases { ['main'] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub show_tables { |
58
|
32
|
|
|
32
|
0
|
1931
|
my ($self, $database) = @_; |
59
|
|
|
|
|
|
|
|
60
|
32
|
|
|
|
|
144
|
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
|
32
|
|
|
|
|
153
|
my $tables = $self->dbi->execute($sql)->values; |
68
|
|
|
|
|
|
|
|
69
|
32
|
|
|
|
|
22759
|
return $tables; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_create_table { |
73
|
48
|
|
|
48
|
0
|
2073
|
my ($self, $database, $table) = @_; |
74
|
|
|
|
|
|
|
|
75
|
48
|
|
|
|
|
211
|
my $sql = <<"EOS"; |
76
|
|
|
|
|
|
|
select sql |
77
|
|
|
|
|
|
|
from $database.sqlite_master |
78
|
|
|
|
|
|
|
where type in ('table', 'type') and name = '$table' |
79
|
|
|
|
|
|
|
EOS |
80
|
|
|
|
|
|
|
|
81
|
48
|
|
|
|
|
199
|
my $create_table = $self->dbi->execute($sql)->value; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Format |
84
|
48
|
100
|
|
|
|
25905
|
if (defined $create_table) { |
85
|
36
|
|
|
|
|
250
|
$create_table =~ s/\(/(\n /; |
86
|
36
|
|
|
|
|
102
|
$create_table =~ s/, /,\n /g; |
87
|
36
|
|
|
|
|
167
|
$create_table =~ s/\)$/\n)/; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
48
|
|
|
|
|
222
|
return $create_table; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |