line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::DBI::Util::mysql; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use DBI; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
701
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
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
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return \@database; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _tables { |
23
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
24
|
|
|
|
|
|
|
my @tables = |
25
|
0
|
|
|
|
|
|
map { $_->[0] } @{ $dbh->selectall_arrayref( q|SHOW TABLES|, ) }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my @data; |
27
|
0
|
|
|
|
|
|
for my $table ( sort { $a cmp $b } @tables ) { |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my ( $schema, $data ) = |
29
|
|
|
|
|
|
|
$dbh->selectrow_array( sprintf( q|SHOW CREATE TABLE %s|, $table ) ); |
30
|
0
|
|
|
|
|
|
push( |
31
|
|
|
|
|
|
|
@data, |
32
|
|
|
|
|
|
|
+{ |
33
|
|
|
|
|
|
|
schema => $schema, |
34
|
|
|
|
|
|
|
data => $data, |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
return @data; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _procedures { |
42
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
43
|
0
|
|
|
|
|
|
my $dbname = _dbname($dbh); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $rows = |
46
|
|
|
|
|
|
|
$dbh->selectall_arrayref( 'SHOW PROCEDURE STATUS', +{ Slice => +{} } ); |
47
|
0
|
|
|
|
|
|
my @data; |
48
|
0
|
|
|
|
|
|
for my $row ( |
49
|
0
|
|
|
|
|
|
sort { $a->{Name} cmp $b->{Name} } |
50
|
0
|
|
|
|
|
|
grep { $_->{Db} eq $dbname } @$rows |
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
54
|
0
|
|
|
|
|
|
sprintf( 'SHOW CREATE PROCEDURE %s', $row->{Name} ) ); |
55
|
|
|
|
|
|
|
push( |
56
|
|
|
|
|
|
|
@data, |
57
|
|
|
|
|
|
|
+{ |
58
|
|
|
|
|
|
|
procedure => $row->{Name}, |
59
|
0
|
|
|
|
|
|
data => $class->_remove_definer( $def->{'Create Procedure'} ), |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return @data; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _functions { |
68
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
69
|
0
|
|
|
|
|
|
my $dbname = _dbname($dbh); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $rows = |
72
|
|
|
|
|
|
|
$dbh->selectall_arrayref( 'SHOW FUNCTION STATUS', +{ Slice => +{} } ); |
73
|
0
|
|
|
|
|
|
my @data; |
74
|
0
|
|
|
|
|
|
for my $row ( |
75
|
0
|
|
|
|
|
|
sort { $a->{Name} cmp $b->{Name} } |
76
|
0
|
|
|
|
|
|
grep { $_->{Db} eq $dbname } @$rows |
77
|
|
|
|
|
|
|
) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
80
|
0
|
|
|
|
|
|
sprintf( 'SHOW CREATE FUNCTION %s', $row->{Name} ) ); |
81
|
|
|
|
|
|
|
push( |
82
|
|
|
|
|
|
|
@data, |
83
|
|
|
|
|
|
|
+{ |
84
|
|
|
|
|
|
|
function => $row->{Name}, |
85
|
0
|
|
|
|
|
|
data => $class->_remove_definer( $def->{'Create Function'} ), |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return @data; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _triggers { |
94
|
0
|
|
|
0
|
|
|
my ( $class, $dbh ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $rows = $dbh->selectall_arrayref( 'SHOW TRIGGERS', +{ Slice => +{} } ); |
97
|
0
|
|
|
|
|
|
my @data; |
98
|
0
|
|
|
|
|
|
for my $row ( sort { $a->{Trigger} cmp $b->{Trigger} } @$rows ) { |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $def = $dbh->selectrow_hashref( |
100
|
0
|
|
|
|
|
|
sprintf( 'SHOW CREATE TRIGGER %s', $row->{Trigger} ) ); |
101
|
|
|
|
|
|
|
push( |
102
|
|
|
|
|
|
|
@data, |
103
|
|
|
|
|
|
|
+{ |
104
|
|
|
|
|
|
|
trigger => $row->{Trigger}, |
105
|
|
|
|
|
|
|
refer => $row->{Table}, |
106
|
|
|
|
|
|
|
data => |
107
|
0
|
|
|
|
|
|
$class->_remove_definer( $def->{'SQL Original Statement'} ), |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return @data; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _remove_definer { |
116
|
0
|
|
|
0
|
|
|
my ( $class, $def ) = @_; |
117
|
0
|
|
|
|
|
|
$def =~ s/CREATE(\s*.*\s*)(PROCEDURE|FUNCTION|TRIGGER)/CREATE $2/i; |
118
|
0
|
|
|
|
|
|
$def; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dbname { |
122
|
0
|
|
|
0
|
|
|
my $dbh = shift; |
123
|
0
|
|
|
|
|
|
my %dsn = map { split( '=', $_ ) } split( ';', $dbh->{Name} ); |
|
0
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
return exists $dsn{dbname} ? $dsn{dbname} : $dsn{db}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |