| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Module::Build::DBD::mysql; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
43785
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
125
|
|
|
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
143
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
6
|
3
|
|
|
3
|
|
18
|
use Cwd; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
3701
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
1
|
22
|
sub get_client { 'mysql' } |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get_db_and_command { |
|
11
|
4
|
|
|
4
|
1
|
809
|
my ($class, $client, $p) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
4
|
|
33
|
|
|
27
|
my @cmd = ( |
|
14
|
|
|
|
|
|
|
$client, |
|
15
|
|
|
|
|
|
|
'--user' => $p->{db_super_user} || $p->{username} || $p->{user}, |
|
16
|
|
|
|
|
|
|
'--skip-pager', |
|
17
|
|
|
|
|
|
|
'--silent', |
|
18
|
|
|
|
|
|
|
'--skip-column-names', |
|
19
|
|
|
|
|
|
|
'--skip-line-numbers', |
|
20
|
|
|
|
|
|
|
); |
|
21
|
4
|
100
|
66
|
|
|
73
|
if (my $pass = $p->{db_super_pass} || $p->{password} || $p->{pass}) { |
|
22
|
1
|
|
|
|
|
4
|
push @cmd, "--password=$pass"; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
4
|
100
|
|
|
|
15
|
push @cmd, '--host' => $p->{host} if $p->{host}; |
|
25
|
4
|
100
|
|
|
|
12
|
push @cmd, '--port' => $p->{port} if $p->{port}; |
|
26
|
4
|
|
|
|
|
23
|
return $p->{database}, \@cmd |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_db_option { |
|
30
|
3
|
|
|
3
|
1
|
5
|
my ($class, $db) = @_; |
|
31
|
3
|
|
|
|
|
17
|
return ('--database' => $db); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_create_db_command { |
|
35
|
1
|
|
|
1
|
1
|
3
|
my ($class, $cmd, $db) = @_; |
|
36
|
1
|
|
|
|
|
7
|
$class->get_execute_command($cmd, undef, qq{CREATE DATABASE "$db"}); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_drop_db_command { |
|
40
|
1
|
|
|
1
|
1
|
3
|
my ($class, $cmd, $db) = @_; |
|
41
|
1
|
|
|
|
|
6
|
$class->get_execute_command( $cmd, undef, qq{DROP DATABASE IF EXISTS "$db"}); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_check_db_command { |
|
45
|
1
|
|
|
1
|
1
|
3
|
my ($class, $cmd, $db) = @_; |
|
46
|
1
|
|
|
|
|
6
|
$class->get_execute_command( $cmd, undef, qq{ |
|
47
|
|
|
|
|
|
|
SELECT 1 |
|
48
|
|
|
|
|
|
|
FROM information_schema.schemata |
|
49
|
|
|
|
|
|
|
WHERE schema_name = '$db'; |
|
50
|
|
|
|
|
|
|
}); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_execute_command { |
|
54
|
4
|
|
|
4
|
1
|
9
|
my ($class, $cmd, $db, $sql) = @_; |
|
55
|
|
|
|
|
|
|
return ( |
|
56
|
4
|
100
|
|
|
|
30
|
@$cmd, |
|
57
|
|
|
|
|
|
|
$db ? $class->get_db_option($db) : (), |
|
58
|
|
|
|
|
|
|
'--execute' => $sql, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_file_command { |
|
63
|
1
|
|
|
1
|
1
|
2
|
my ($class, $cmd, $db, $fn) = @_; |
|
64
|
|
|
|
|
|
|
return ( |
|
65
|
1
|
|
|
|
|
4
|
@$cmd, |
|
66
|
|
|
|
|
|
|
$class->get_db_option($db), |
|
67
|
|
|
|
|
|
|
'--execute' => "source $fn", |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_meta_table_sql { |
|
72
|
1
|
|
|
1
|
1
|
2
|
my ($class, $table) = @_; |
|
73
|
1
|
|
|
|
|
17
|
return qq{ |
|
74
|
|
|
|
|
|
|
CREATE TABLE $table ( |
|
75
|
|
|
|
|
|
|
label VARCHAR(255) PRIMARY KEY, |
|
76
|
|
|
|
|
|
|
value INT NOT NULL DEFAULT 0, |
|
77
|
|
|
|
|
|
|
note TEXT NOT NULL |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 Name |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Module::Build::DBD:mysql - MySQL specifics for Module::Build::DBD |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 Description |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This module contains a number of class methods called by L |
|
91
|
|
|
|
|
|
|
to handle MySQL specific tasks when detecting, building, and updating a |
|
92
|
|
|
|
|
|
|
database. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 Methods |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
All methods are class methods. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 C |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $client = Module::Build::DBD::mysql->get_client; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the name of the client to use to connect to MySQL. For now, that's |
|
103
|
|
|
|
|
|
|
just C, which is fine if it's in your path. Some code to search for a |
|
104
|
|
|
|
|
|
|
client might be added in the future. Either way, it's best to specify use the |
|
105
|
|
|
|
|
|
|
C<--db_client> option to avoid all ambiguity. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head3 C |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my ($db_name, $cmd) = Module::Build::DBD::mysql->get_db_and_command($client, $params); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns a database name culled from C<$params> and an array reference with |
|
112
|
|
|
|
|
|
|
C<$client> and all required options for all access to the database. C<$params> |
|
113
|
|
|
|
|
|
|
contains both the contents of the context configuration file's DBI section and |
|
114
|
|
|
|
|
|
|
the attributes defined in the driver DSN (e.g., C in |
|
115
|
|
|
|
|
|
|
C). |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head3 C |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my @opts = Module::Build::DBD::mysql->get_db_option($db_name); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns a list of options to be appended to the command returned by |
|
122
|
|
|
|
|
|
|
C to connect to a specific database. For MySQL, that's |
|
123
|
|
|
|
|
|
|
simply C<< ('--database' => $dbname) >>. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head3 C |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my @command = Module::Build::DBD::mysql->get_create_db_command($cmd, $db); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns a command list suitable for passing to C that will create a |
|
130
|
|
|
|
|
|
|
new database. C<$cmd> is the command returned by C and |
|
131
|
|
|
|
|
|
|
C<$db> is the name of the database to be created. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head3 C |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my @command = Module::Build::DBD::mysql->get_drop_db_command($cmd, $db); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns a command list suitable for passing to C that will drop an |
|
138
|
|
|
|
|
|
|
existing database. C<$cmd> is the command returned by C |
|
139
|
|
|
|
|
|
|
and C<$db> is the name of the database to be dropped. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head3 C |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my @command = Module::Build::DBD::mysql->get_check_db_command($cmd, $db); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Returns a command list suitable for passing to C that will, when |
|
146
|
|
|
|
|
|
|
executed, output a 1 when C<$db> exists and nothing when C<$db> does not |
|
147
|
|
|
|
|
|
|
exist. C<$cmd> is the command returned by C and C<$db> |
|
148
|
|
|
|
|
|
|
is the name of the database to be checked. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head3 C |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my @command = Module::Build::DBD::mysql->get_execute_command($cmd, $db, $sql); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Returns a command list suitable for passing to C that will execute |
|
155
|
|
|
|
|
|
|
the SQL in C<$sql> and return its output, if any. C<$cmd> is the command |
|
156
|
|
|
|
|
|
|
returned by C, C<$db> is the name of the database to be |
|
157
|
|
|
|
|
|
|
connect to for the query, and C<$sql> is the SQL command or commands to be |
|
158
|
|
|
|
|
|
|
executed. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head3 C |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my @command = Module::Build::DBD::mysql->get_file_command($cmd, $db, $sql); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns a command list suitable for passing to C that will execute |
|
165
|
|
|
|
|
|
|
the SQL in C<$file> and return its output, if any. C<$cmd> is the command |
|
166
|
|
|
|
|
|
|
returned by C, C<$db> is the name of the database to be |
|
167
|
|
|
|
|
|
|
connect to for the query, and C<$file> is a file with SQL commands. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head3 C |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $sql = Module::Build::DBD::mysql->get_met_table_sql; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns an SQL string that creates a metadata table named C<$table_name>. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 Author |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
David E. Wheeler |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 Copyright |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright (c) 2008-2010 David E. Wheeler. Some Rights Reserved. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
|
184
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |