line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SQLiteViewerLite::Command; |
2
|
3
|
|
|
3
|
|
20
|
use Mojo::Base 'Mojolicious::Plugin::SQLiteViewerLite::Base::Command'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
20
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'dbi'; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
0
|
28
|
sub current_database { 'main' } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub show_primary_key { |
9
|
15
|
|
|
15
|
0
|
43
|
my ($self, $database, $table) = @_; |
10
|
15
|
|
50
|
|
|
50
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
|
|
56
|
my @primary_keys = $self->dbi->dbh->primary_key(undef, $database, $table); |
13
|
15
|
|
|
|
|
16796
|
my $primary_key = '(' . join(', ', @primary_keys) . ')'; |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
61
|
return $primary_key; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_null_allowed_column { |
19
|
15
|
|
|
15
|
0
|
46
|
my ($self, $database, $table) = @_; |
20
|
|
|
|
|
|
|
|
21
|
15
|
|
|
|
|
44
|
my $sql = "pragma table_info($table)"; |
22
|
15
|
|
|
|
|
51
|
my $rows = $self->dbi->execute($sql)->all; |
23
|
15
|
|
|
|
|
6115
|
my $null_allowed_column = []; |
24
|
15
|
|
|
|
|
50
|
for my $row (@$rows) { |
25
|
30
|
100
|
|
|
|
98
|
push @$null_allowed_column, $row->{name} if !$row->{notnull}; |
26
|
|
|
|
|
|
|
} |
27
|
15
|
|
|
|
|
65
|
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
|
33
|
sub show_databases { ['main'] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub show_tables { |
58
|
24
|
|
|
24
|
0
|
90
|
my ($self, $database) = @_; |
59
|
|
|
|
|
|
|
|
60
|
24
|
|
|
|
|
124
|
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
|
|
|
|
|
120
|
my $tables = $self->dbi->execute($sql)->values; |
68
|
|
|
|
|
|
|
|
69
|
24
|
|
|
|
|
16282
|
return $tables; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_create_table { |
73
|
40
|
|
|
40
|
0
|
161
|
my ($self, $database, $table) = @_; |
74
|
|
|
|
|
|
|
|
75
|
40
|
|
|
|
|
167
|
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
|
|
|
|
|
154
|
my $create_table = $self->dbi->execute($sql)->value; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Format |
84
|
40
|
|
|
|
|
20970
|
$create_table =~ s/\(/(\n /; |
85
|
40
|
|
|
|
|
390
|
$create_table =~ s/, /,\n /g; |
86
|
40
|
|
|
|
|
428
|
$create_table =~ s/\)$/\n)/; |
87
|
|
|
|
|
|
|
|
88
|
40
|
|
|
|
|
213
|
return $create_table; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |