line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MySQLViewerLite::Command; |
2
|
1
|
|
|
1
|
|
7
|
use Mojo::Base 'Mojolicious::Plugin::MySQLViewerLite::Base::Command'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
sub current_database { |
5
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
6
|
0
|
|
|
|
|
|
return $self->dbi->execute('select database()')->fetch->[0]; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub show_primary_key { |
10
|
0
|
|
|
0
|
0
|
|
my ($self, $database, $table) = @_; |
11
|
0
|
|
0
|
|
|
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
12
|
0
|
|
|
|
|
|
my $primary_key = ''; |
13
|
0
|
0
|
|
|
|
|
if ($show_create_table =~ /PRIMARY\s+KEY\s+(.+?)\n/i) { |
14
|
0
|
|
|
|
|
|
$primary_key = $1; |
15
|
0
|
|
|
|
|
|
$primary_key =~ s/,$//; |
16
|
|
|
|
|
|
|
} |
17
|
0
|
|
|
|
|
|
return $primary_key; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub show_null_allowed_column { |
21
|
0
|
|
|
0
|
0
|
|
my ($self, $database, $table) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
24
|
0
|
|
|
|
|
|
my @lines = split(/\n/, $show_create_table); |
25
|
0
|
|
|
|
|
|
my $null_allowed_column = []; |
26
|
0
|
|
|
|
|
|
for my $line (@lines) { |
27
|
0
|
0
|
0
|
|
|
|
next if /^\s*`/ || $line =~ /NOT\s+NULL/i; |
28
|
0
|
0
|
|
|
|
|
if ($line =~ /^\s+(`\w+?`)/) { |
29
|
0
|
|
|
|
|
|
push @$null_allowed_column, $1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
return $null_allowed_column; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub show_database_engine { |
36
|
0
|
|
|
0
|
0
|
|
my ($self, $database, $table) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
0
|
|
|
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
39
|
0
|
|
|
|
|
|
my $database_engine = ''; |
40
|
0
|
0
|
|
|
|
|
if ($show_create_table =~ /ENGINE=(.+?)(\s+|$)/i) { |
41
|
0
|
|
|
|
|
|
$database_engine = $1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return $database_engine; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub show_charsets { |
48
|
0
|
|
|
0
|
0
|
|
my ($self, $database) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $tables = $self->show_tables($database); |
51
|
0
|
|
|
|
|
|
my $charsets = {}; |
52
|
0
|
|
|
|
|
|
for my $table (@$tables) { |
53
|
0
|
|
|
|
|
|
my $charset = $self->show_charset($database, $table); |
54
|
0
|
|
|
|
|
|
$charsets->{$table} = $charset; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return $charsets; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub show_charset { |
61
|
0
|
|
|
0
|
0
|
|
my ($self, $database, $table) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
0
|
|
|
|
my $show_create_table = $self->show_create_table($database, $table) || ''; |
64
|
0
|
|
|
|
|
|
my $charset = ''; |
65
|
0
|
0
|
|
|
|
|
if ($show_create_table =~ /CHARSET=(.+?)(\s+|$)/i) { |
66
|
0
|
|
|
|
|
|
$charset = $1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $charset; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub show_databases { |
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $databases = []; |
76
|
0
|
|
|
|
|
|
my $database_rows = $self->dbi->execute('show databases')->all; |
77
|
0
|
|
|
|
|
|
for my $database_row (@$database_rows) { |
78
|
0
|
|
|
|
|
|
push @$databases, $database_row->{(keys %$database_row)[0]}; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
return $databases; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub show_tables { |
84
|
0
|
|
|
0
|
0
|
|
my ($self, $database) = @_; |
85
|
0
|
|
|
|
|
|
my $tables = $self->dbi->execute("show tables from $database")->values; |
86
|
0
|
|
|
|
|
|
return $tables; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub show_create_table { |
90
|
0
|
|
|
0
|
0
|
|
my ($self, $database, $table) = @_; |
91
|
0
|
|
|
|
|
|
my $table_def_row; |
92
|
0
|
|
|
|
|
|
eval { $table_def_row = $self->dbi->execute("show create table $database.$table")->one }; |
|
0
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
|
$table_def_row ||= {}; |
94
|
0
|
|
0
|
|
|
|
my $table_def = $table_def_row->{'Create Table'} || ''; |
95
|
0
|
|
|
|
|
|
return $table_def; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |