line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Anansi::Database::MySQL; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Anansi::Database::MySQL - A manager for MySQL databases. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Anansi::Database::MySQL; |
11
|
|
|
|
|
|
|
if(Anansi::Database::MySQL->validate( |
12
|
|
|
|
|
|
|
undef, |
13
|
|
|
|
|
|
|
DRIVER => 'MySQL', |
14
|
|
|
|
|
|
|
)) { |
15
|
|
|
|
|
|
|
my $OBJECT = Anansi::Database::MySQL->new(); |
16
|
|
|
|
|
|
|
if($OBJECT->connect( |
17
|
|
|
|
|
|
|
undef, |
18
|
|
|
|
|
|
|
DATABASE => 'someDatabase', |
19
|
|
|
|
|
|
|
PASSWORD => 'somePassword', |
20
|
|
|
|
|
|
|
USERNAME => 'someUser', |
21
|
|
|
|
|
|
|
)) { |
22
|
|
|
|
|
|
|
my $records = $OBJECT->statement( |
23
|
|
|
|
|
|
|
undef, |
24
|
|
|
|
|
|
|
INPUT => [ |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
DEFAULT => '0', |
27
|
|
|
|
|
|
|
NAME => 'yetAnotherField', |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
], |
30
|
|
|
|
|
|
|
SQL => 'SELECT some_field, another_field FROM some_table WHERE yet_another_field = ?;', |
31
|
|
|
|
|
|
|
yetAnotherField => 123, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
$OBJECT->disconnect(); |
34
|
|
|
|
|
|
|
if(defined($records)) { |
35
|
|
|
|
|
|
|
if(ref($records) =~ /^ARRAY$/i) { |
36
|
|
|
|
|
|
|
my $record = 0; |
37
|
|
|
|
|
|
|
foreach my $record (@{$records}) { |
38
|
|
|
|
|
|
|
next if(ref($record) !~ /^HASH$/i); |
39
|
|
|
|
|
|
|
print "\n" if(0 < $record); |
40
|
|
|
|
|
|
|
my $field = 0; |
41
|
|
|
|
|
|
|
foreach my $key (keys(%{$record})) { |
42
|
|
|
|
|
|
|
print ', ' if(0 < $field); |
43
|
|
|
|
|
|
|
print '"'.$key.'" = "'.${record}{$key}.'"'; |
44
|
|
|
|
|
|
|
$field++; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
$record++; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
print "\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
use Anansi::Database; |
55
|
|
|
|
|
|
|
my $OBJECT = Anansi::Database->new(); |
56
|
|
|
|
|
|
|
my $component = $OBJECT->addComponent( |
57
|
|
|
|
|
|
|
undef, |
58
|
|
|
|
|
|
|
DRIVER => 'MySQL', |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
if(defined($component)) { |
61
|
|
|
|
|
|
|
if($OBJECT->channel( |
62
|
|
|
|
|
|
|
'CONNECT', |
63
|
|
|
|
|
|
|
$component, |
64
|
|
|
|
|
|
|
DATABASE => 'someDatabase', |
65
|
|
|
|
|
|
|
PASSWORD => 'somePassword', |
66
|
|
|
|
|
|
|
USERNAME => 'someUser', |
67
|
|
|
|
|
|
|
)) { |
68
|
|
|
|
|
|
|
my $records = $OBJECT->channel( |
69
|
|
|
|
|
|
|
'STATEMENT', |
70
|
|
|
|
|
|
|
$component, |
71
|
|
|
|
|
|
|
INPUT => [ |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
DEFAULT => '0', |
74
|
|
|
|
|
|
|
NAME => 'yetAnotherField', |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
], |
77
|
|
|
|
|
|
|
SQL => 'SELECT some_field, another_field FROM some_table WHERE yet_another_field = ?;', |
78
|
|
|
|
|
|
|
yetAnotherField => 123, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
if(defined($records)) { |
81
|
|
|
|
|
|
|
if(ref($records) =~ /^ARRAY$/i) { |
82
|
|
|
|
|
|
|
my $record = 0; |
83
|
|
|
|
|
|
|
foreach my $record (@{$records}) { |
84
|
|
|
|
|
|
|
next if(ref($record) !~ /^HASH$/i); |
85
|
|
|
|
|
|
|
print "\n" if(0 < $record); |
86
|
|
|
|
|
|
|
my $field = 0; |
87
|
|
|
|
|
|
|
foreach my $key (keys(%{$record})) { |
88
|
|
|
|
|
|
|
print ', ' if(0 < $field); |
89
|
|
|
|
|
|
|
print '"'.$key.'" = "'.${record}{$key}.'"'; |
90
|
|
|
|
|
|
|
$field++; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
$record++; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
print "\n"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Manages MySQL databases allowing the opening and closing of MySQL databases. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
1
|
|
24762
|
use base qw(Anansi::DatabaseComponent); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1899
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 Anansi::Class |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
See L for details. A parent module of L. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head3 DESTROY |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
See L for details. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head3 finalise |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
See L for details. Overridden by L. A virtual method. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head3 implicate |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
See L for details. A virtual method. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head3 import |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
See L for details. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head3 initialise |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
See L for details. Overridden by L. A virtual method. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head3 new |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
See L for details. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head3 old |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
See L for details. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head3 used |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
See L for details. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head3 uses |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
See L for details. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head3 using |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
See L for details. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 Anansi::Component |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
See L for details. A parent module of L. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head3 Anansi::Class |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
See L for details. A parent module of L. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head3 addChannel |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
See L for details. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 channel |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
See L for details. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head3 componentManagers |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
See L for details. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head3 removeChannel |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
See L for details. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 Anansi::DatabaseComponent |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
See L for details. A parent module of L. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head3 Anansi::Component |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
See L for details. A parent module of L. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head3 autoCommit |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
See L for details. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'AUTOCOMMIT' => 'Anansi::DatabaseComponent::autocommit'); |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head3 bind |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
See L for details. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head3 binding |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
See L for details. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head3 commit |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
See L for details. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'COMMIT' => 'Anansi::DatabaseComponent::commit'); |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head3 connect |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
See L for details. Overridden by L. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head3 disconnect |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
See L for details. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'DISCONNECT' => 'Anansi::DatabaseComponent::disconnect'); |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head3 finalise |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
See L for details. Overrides L. A virtual method. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head3 finish |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
See L for details. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=cut |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'FINISH' => 'Anansi::DatabaseComponent::finish'); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head3 handle |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
See L for details. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=cut |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'HANDLE' => 'Anansi::DatabaseComponent::handle'); |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head3 initialise |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
See L for details. Overrides L. A virtual method. |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=cut |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head3 prepare |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
See L for details. |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=cut |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'PREPARE' => 'Anansi::DatabaseComponent::prepare'); |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head3 rollback |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
See L for details. |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=cut |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'ROLLBACK' => 'Anansi::DatabaseComponent::rollback'); |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=head3 statement |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
See L for details. |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=cut |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'STATEMENT' => 'Anansi::DatabaseComponent::statement'); |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=head3 validate |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
See L for details. Overridden by L. |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=cut |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=head2 connect |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
if(Anansi::Database::MySQL::connect( |
375
|
|
|
|
|
|
|
$OBJECT, |
376
|
|
|
|
|
|
|
undef, |
377
|
|
|
|
|
|
|
DATABASE => 'someDatabase', |
378
|
|
|
|
|
|
|
PASSWORD => 'somePassword', |
379
|
|
|
|
|
|
|
USERNAME => 'someUser', |
380
|
|
|
|
|
|
|
)); |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
my $handle = DBI->connect('DBI:mysql:database=someDatabase', 'someUser', 'somePassword'); |
383
|
|
|
|
|
|
|
if($OBJECT->connect( |
384
|
|
|
|
|
|
|
undef, |
385
|
|
|
|
|
|
|
HANDLE => $handle, |
386
|
|
|
|
|
|
|
)); |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
=over 4 |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=item self I<(Blessed Hash, Required)> |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
An object of this namespace. |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=item channel I<(String, Required)> |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
The abstract identifier of a subroutine. |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=item parameters I<(Hash, Optional)> |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
Named parameters. |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=over 4 |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=item AutoCommit I<(String, Optional)> |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
Defines whether the MySQL driver automatically saves any changes made to the |
407
|
|
|
|
|
|
|
B. A value of B<1> I<(one)> means changes will be saved, a value of |
408
|
|
|
|
|
|
|
B<0> I<(zero)> means changes will need to be manually saved. Changes are not |
409
|
|
|
|
|
|
|
saved by default. |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
=item DATABASE I<(String, Optional)> |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
The name of the MySQL database. A value of B is used by default. |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
=item HANDLE I<(DBI::db, Optional)> |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
The database handle of an existing database connection. |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
=item HOSTNAME I<(String, Optional)> |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
The IP address of the computer where the MySQL B is hosted. A value |
422
|
|
|
|
|
|
|
of B<127.0.0.1> is used by default. |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
=item PASSWORD I<(String, Optional)> |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
The password of the B that is accessing the MySQL database. A value |
427
|
|
|
|
|
|
|
of B is used by default. |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=item PORT I<(String, Optional)> |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
The IP address port number of the computer where the MySQL B is |
432
|
|
|
|
|
|
|
hosted. A value of B<3306> I<(three three zero six)> is used by default. |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
=item PrintError I<(String, Optional)> |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
Defines whether the MySQL driver will use the B function. A value of B<1> |
437
|
|
|
|
|
|
|
I<(one)> means errors will be output using B, a value of B<0> I<(zero)> |
438
|
|
|
|
|
|
|
means errors will not be output in this way. Errors are output by default. |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=item RaiseError I<(String, Optional)> |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
Defines whether the MySQL driver will use the B function. A value of B<1> |
443
|
|
|
|
|
|
|
I<(one)> means errors will be output using B, a value of B<0> I<(zero)> |
444
|
|
|
|
|
|
|
means errors will not be output in this way. Errors are output by default. |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=item USERNAME I<(String, Optional)> |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
The user that is accessing the MySQL database. A value of B is used by |
449
|
|
|
|
|
|
|
default. |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=back |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=back |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
Overrides L. |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
=cut |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
sub connect { |
461
|
0
|
|
|
0
|
1
|
|
my ($self, $channel, %parameters) = @_; |
462
|
0
|
|
|
|
|
|
return $self->SUPER::connect( |
463
|
|
|
|
|
|
|
undef, |
464
|
|
|
|
|
|
|
INPUT => [ |
465
|
|
|
|
|
|
|
{ |
466
|
|
|
|
|
|
|
INPUT => [ |
467
|
|
|
|
|
|
|
'dbi:mysql:database=', { |
468
|
|
|
|
|
|
|
DEFAULT => 'mysql', |
469
|
|
|
|
|
|
|
NAME => 'DATABASE', |
470
|
|
|
|
|
|
|
REF => '', |
471
|
|
|
|
|
|
|
}, |
472
|
|
|
|
|
|
|
';host=', { |
473
|
|
|
|
|
|
|
DEFAULT => '127.0.0.1', |
474
|
|
|
|
|
|
|
NAME => 'HOSTNAME', |
475
|
|
|
|
|
|
|
REF => '', |
476
|
|
|
|
|
|
|
}, |
477
|
|
|
|
|
|
|
';port=', { |
478
|
|
|
|
|
|
|
DEFAULT => '3306', |
479
|
|
|
|
|
|
|
NAME => 'PORT', |
480
|
|
|
|
|
|
|
REF => '', |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
], |
483
|
|
|
|
|
|
|
REF => '', |
484
|
|
|
|
|
|
|
}, { |
485
|
|
|
|
|
|
|
NAME => 'USERNAME', |
486
|
|
|
|
|
|
|
REF => '', |
487
|
|
|
|
|
|
|
}, { |
488
|
|
|
|
|
|
|
NAME => 'PASSWORD', |
489
|
|
|
|
|
|
|
REF => '', |
490
|
|
|
|
|
|
|
}, { |
491
|
|
|
|
|
|
|
INPUT => [ |
492
|
|
|
|
|
|
|
{ |
493
|
|
|
|
|
|
|
DEFAULT => 0, |
494
|
|
|
|
|
|
|
NAME => 'AutoCommit', |
495
|
|
|
|
|
|
|
REF => '', |
496
|
|
|
|
|
|
|
}, { |
497
|
|
|
|
|
|
|
DEFAULT => 1, |
498
|
|
|
|
|
|
|
NAME => 'PrintError', |
499
|
|
|
|
|
|
|
REF => '', |
500
|
|
|
|
|
|
|
}, { |
501
|
|
|
|
|
|
|
DEFAULT => 1, |
502
|
|
|
|
|
|
|
NAME => 'RaiseError', |
503
|
|
|
|
|
|
|
REF => '', |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
], |
506
|
|
|
|
|
|
|
REF => 'HASH', |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
], |
509
|
|
|
|
|
|
|
(%parameters), |
510
|
|
|
|
|
|
|
); |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'CONNECT' => 'connect'); |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
=head2 validate |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL::validate($OBJECT, undef)); |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL::channel($OBJECT, 'VALIDATE_AS_APPROPRIATE')); |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL->validate(undef)); |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL->channel('VALIDATE_AS_APPROPRIATE')); |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
if(1 == $OBJECT->validate(undef, DRIVER => 'MySQL')); |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
if(1 == $OBJECT->channel('VALIDATE_AS_APPROPRIATE', DRIVER => 'MySQL')); |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL->validate(undef, DRIVER => 'MySQL')); |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
if(1 == Anansi::Database::MySQL->channel('VALIDATE_AS_APPROPRIATE', DRIVER => 'MySQL')); |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=over 4 |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=item self I<(Blessed Hash B String, Required)> |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
Either an object or a string of this namespace. |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=item channel I<(String, Required)> |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
The abstract identifier of a subroutine. |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
=item parameters I<(Hash, Optional)> |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
Named parameters. |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=over 4 |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=item DRIVER |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
When the B parameter is defined as I then this database driver |
554
|
|
|
|
|
|
|
component will be used otherwise an attempt will be made to use this driver. |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=back |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
=back |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
Overrides L. |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=cut |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
sub validate { |
566
|
0
|
|
|
0
|
1
|
|
my ($self, $channel, %parameters) = @_; |
567
|
0
|
|
|
|
|
|
$parameters{DRIVERS} = 'MySQL'; |
568
|
0
|
|
|
|
|
|
return $self->SUPER::validate(undef, (%parameters)); |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
Anansi::Component::addChannel('Anansi::Database::MySQL', 'VALIDATE_AS_APPROPRIATE' => 'validate'); |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=head1 NOTES |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
This module is designed to make it simple, easy and quite fast to code your |
578
|
|
|
|
|
|
|
design in perl. If for any reason you feel that it doesn't achieve these goals |
579
|
|
|
|
|
|
|
then please let me know. I am here to help. All constructive criticisms are |
580
|
|
|
|
|
|
|
also welcomed. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=cut |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=head1 AUTHOR |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
Kevin Treleaven treleaven I net> |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=cut |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
1; |