line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DBViewer::SQLite::Command; |
2
|
2
|
|
|
2
|
|
9
|
use Mojo::Base 'Mojolicious::Plugin::DBViewer::Command'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'dbi'; |
5
|
|
|
|
|
|
|
|
6
|
17
|
|
|
17
|
0
|
79
|
sub current_database { 'main' } |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub show_primary_key { |
9
|
18
|
|
|
18
|
0
|
23
|
my ($self, $database, $table) = @_; |
10
|
18
|
|
50
|
|
|
35
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
11
|
|
|
|
|
|
|
|
12
|
18
|
|
|
|
|
60
|
my @primary_keys = $self->dbi->dbh->primary_key(undef, $database, $table); |
13
|
18
|
|
|
|
|
13713
|
my $primary_key = '(' . join(', ', @primary_keys) . ')'; |
14
|
|
|
|
|
|
|
|
15
|
18
|
|
|
|
|
49
|
return $primary_key; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_null_allowed_column { |
19
|
18
|
|
|
18
|
0
|
29
|
my ($self, $database, $table) = @_; |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
|
|
33
|
my $sql = "pragma table_info($table)"; |
22
|
18
|
|
|
|
|
42
|
my $rows = $self->dbi->execute($sql)->all; |
23
|
18
|
|
|
|
|
5902
|
my $null_allowed_column = []; |
24
|
18
|
|
|
|
|
35
|
for my $row (@$rows) { |
25
|
36
|
100
|
|
|
|
76
|
push @$null_allowed_column, $row->{name} if !$row->{notnull}; |
26
|
|
|
|
|
|
|
} |
27
|
18
|
|
|
|
|
62
|
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
|
197255
|
sub show_databases { ['main'] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub show_tables { |
58
|
32
|
|
|
32
|
0
|
1501
|
my ($self, $database) = @_; |
59
|
|
|
|
|
|
|
|
60
|
32
|
|
|
|
|
127
|
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
|
|
|
|
|
127
|
my $tables = $self->dbi->execute($sql)->values; |
68
|
|
|
|
|
|
|
|
69
|
32
|
|
|
|
|
19467
|
return $tables; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_create_table { |
73
|
48
|
|
|
48
|
0
|
1519
|
my ($self, $database, $table) = @_; |
74
|
|
|
|
|
|
|
|
75
|
48
|
|
|
|
|
233
|
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
|
|
|
|
|
164
|
my $create_table = $self->dbi->execute($sql)->value; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Format |
84
|
48
|
100
|
|
|
|
21478
|
if (defined $create_table) { |
85
|
36
|
|
|
|
|
142
|
$create_table =~ s/\(/(\n /; |
86
|
36
|
|
|
|
|
55
|
$create_table =~ s/, /,\n /g; |
87
|
36
|
|
|
|
|
109
|
$create_table =~ s/\)$/\n)/; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
48
|
|
|
|
|
162
|
return $create_table; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |