line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::DBI::Util::mysql; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use DBI; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1119
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub make_database { |
11
|
0
|
|
|
0
|
1
|
|
my ( $class, $dbh ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my @database; |
14
|
0
|
|
|
|
|
|
push( @database, $class->_tables($dbh) ); |
15
|
0
|
|
|
|
|
|
push( @database, $class->_procedures($dbh) ); |
16
|
0
|
|
|
|
|
|
push( @database, $class->_functions($dbh) ); |
17
|
0
|
|
|
|
|
|
push( @database, $class->_triggers($dbh) ); |
18
|
0
|
|
|
|
|
|
push( @database, $class->_events($dbh) ); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return \@database; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _tables { |
24
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
25
|
0
|
|
|
|
|
|
my @tables = |
26
|
0
|
|
|
|
|
|
map { $_->[0] } @{ $dbh->selectall_arrayref( q|SHOW TABLES|, ) }; |
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my @data; |
28
|
0
|
|
|
|
|
|
for my $table ( sort { $a cmp $b } @tables ) { |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my ( $schema, $data ) = |
30
|
|
|
|
|
|
|
$dbh->selectrow_array( sprintf( q|SHOW CREATE TABLE %s|, $table ) ); |
31
|
0
|
|
|
|
|
|
push( |
32
|
|
|
|
|
|
|
@data, |
33
|
|
|
|
|
|
|
+{ |
34
|
|
|
|
|
|
|
schema => $schema, |
35
|
|
|
|
|
|
|
data => $data, |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return @data; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _procedures { |
43
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
44
|
0
|
|
|
|
|
|
my $dbname = _dbname($dbh); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $rows = |
47
|
|
|
|
|
|
|
$dbh->selectall_arrayref( 'SHOW PROCEDURE STATUS', +{ Slice => +{} } ); |
48
|
0
|
|
|
|
|
|
my @data; |
49
|
0
|
|
|
|
|
|
for my $row ( |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
sort { $a->{Name} cmp $b->{Name} } |
51
|
|
|
|
|
|
|
grep { $_->{Db} eq $dbname } @$rows |
52
|
|
|
|
|
|
|
) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
55
|
|
|
|
|
|
|
sprintf( 'SHOW CREATE PROCEDURE %s', $row->{Name} ) ); |
56
|
0
|
|
|
|
|
|
push( |
57
|
|
|
|
|
|
|
@data, |
58
|
|
|
|
|
|
|
+{ |
59
|
|
|
|
|
|
|
procedure => $row->{Name}, |
60
|
|
|
|
|
|
|
data => $class->_remove_definer( $def->{'Create Procedure'} ), |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return @data; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _functions { |
69
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
70
|
0
|
|
|
|
|
|
my $dbname = _dbname($dbh); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $rows = |
73
|
|
|
|
|
|
|
$dbh->selectall_arrayref( 'SHOW FUNCTION STATUS', +{ Slice => +{} } ); |
74
|
0
|
|
|
|
|
|
my @data; |
75
|
0
|
|
|
|
|
|
for my $row ( |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
sort { $a->{Name} cmp $b->{Name} } |
77
|
|
|
|
|
|
|
grep { $_->{Db} eq $dbname } @$rows |
78
|
|
|
|
|
|
|
) |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
81
|
|
|
|
|
|
|
sprintf( 'SHOW CREATE FUNCTION %s', $row->{Name} ) ); |
82
|
0
|
|
|
|
|
|
push( |
83
|
|
|
|
|
|
|
@data, |
84
|
|
|
|
|
|
|
+{ |
85
|
|
|
|
|
|
|
function => $row->{Name}, |
86
|
|
|
|
|
|
|
data => $class->_remove_definer( $def->{'Create Function'} ), |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return @data; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _triggers { |
95
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my ( $is_enable_show_create_trigger ) = $dbh->selectrow_array( 'SELECT VERSION() >= 5.1' ); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
unless ( $is_enable_show_create_trigger ) { |
100
|
0
|
|
|
|
|
|
return (); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $rows = $dbh->selectall_arrayref( 'SHOW TRIGGERS', +{ Slice => +{} } ); |
104
|
0
|
|
|
|
|
|
my @data; |
105
|
0
|
|
|
|
|
|
for my $row ( sort { $a->{Trigger} cmp $b->{Trigger} } @$rows ) { |
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
107
|
|
|
|
|
|
|
sprintf( 'SHOW CREATE TRIGGER %s', $row->{Trigger} ) ); |
108
|
0
|
|
|
|
|
|
push( |
109
|
|
|
|
|
|
|
@data, |
110
|
|
|
|
|
|
|
+{ |
111
|
|
|
|
|
|
|
trigger => $row->{Trigger}, |
112
|
|
|
|
|
|
|
refer => $row->{Table}, |
113
|
|
|
|
|
|
|
data => |
114
|
|
|
|
|
|
|
$class->_remove_definer( $def->{'SQL Original Statement'} ), |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return @data; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _events { |
123
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my ( $is_enable_show_create_events ) = $dbh->selectrow_array( 'SELECT VERSION() >= 5.1' ); |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
unless ( $is_enable_show_create_events ) { |
128
|
0
|
|
|
|
|
|
return (); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $rows = $dbh->selectall_arrayref( 'SHOW EVENTS', +{ Slice => +{} } ); |
132
|
0
|
|
|
|
|
|
my @data; |
133
|
0
|
|
|
|
|
|
for my $row ( sort { $a->{Name} cmp $b->{Name} } @$rows ) { |
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( sprintf( 'SHOW CREATE EVENT %s', $row->{Name} ) ); |
135
|
0
|
|
|
|
|
|
push( |
136
|
|
|
|
|
|
|
@data, |
137
|
|
|
|
|
|
|
+{ |
138
|
|
|
|
|
|
|
name => $row->{Name}, |
139
|
|
|
|
|
|
|
interval_val => $row->{'Interval value'}, |
140
|
|
|
|
|
|
|
interval_field => $row->{'Interval field'}, |
141
|
|
|
|
|
|
|
data => $def->{'Create Event'}, |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return @data; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _remove_definer { |
150
|
0
|
|
|
0
|
|
|
my ( $class, $def ) = @_; |
151
|
0
|
|
|
|
|
|
$def =~ s/CREATE(\s*.*\s*)(PROCEDURE|FUNCTION|TRIGGER)/CREATE $2/i; |
152
|
0
|
|
|
|
|
|
$def; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub _dbname { |
156
|
0
|
|
|
0
|
|
|
my $dbh = shift; |
157
|
0
|
|
|
|
|
|
my %dsn = map { split( '=', $_, 2 ) } split( ';', $dbh->{Name} ); |
|
0
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
return exists $dsn{dbname} ? $dsn{dbname} : $dsn{db}; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |