first commit
|
1 |
package DBI::Custom; |
2 |
use Object::Simple; |
|
add test
|
3 | |
4 |
our $VERSION = '0.0101'; |
|
5 | ||
6 |
use Carp 'croak'; |
|
add some method
|
7 |
use DBI; |
add tests
|
8 |
use DBI::Custom::SQL::Template; |
add tests
|
9 |
use DBI::Custom::Result; |
cleanup
|
10 |
use DBI::Custom::Query; |
add tests
|
11 | |
12 |
### Class-Object Accessors |
|
update document
|
13 |
sub user : ClassObjectAttr { initialize => {clone => 'scalar'} } |
14 |
sub password : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
15 |
sub data_source : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
add various thins
|
16 |
sub database : ClassObjectAttr { initialize => {clone => 'scalar'} } |
cleanup
|
17 |
sub dbi_options : ClassObjectAttr { initialize => {clone => 'hash', |
add tests
|
18 |
default => sub { {} } } } |
catch up Object::Simple upda...
|
19 | |
update document
|
20 |
sub bind_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
21 |
sub fetch_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
catch up Object::Simple upda...
|
22 | |
add no_bind_filters
|
23 |
sub no_bind_filters : ClassObjectAttr { initialize => {clone => 'array'} } |
24 |
sub no_fetch_filters : ClassObjectAttr { initialize => {clone => 'array'} } |
|
add various thins
|
25 | |
catch up Object::Simple upda...
|
26 |
sub filters : ClassObjectAttr { |
27 |
type => 'hash', |
|
28 |
deref => 1, |
|
29 |
initialize => { |
|
add tests
|
30 |
clone => 'hash', |
31 |
default => sub { {} } |
|
catch up Object::Simple upda...
|
32 |
} |
33 |
} |
|
first commit
|
34 | |
catch up Object::Simple upda...
|
35 |
sub result_class : ClassObjectAttr { |
36 |
initialize => { |
|
add tests
|
37 |
clone => 'scalar', |
38 |
default => 'DBI::Custom::Result' |
|
catch up Object::Simple upda...
|
39 |
} |
40 |
} |
|
cleanup
|
41 | |
catch up Object::Simple upda...
|
42 |
sub sql_template : ClassObjectAttr { |
43 |
initialize => { |
|
update document
|
44 |
clone => sub {$_[0] ? $_[0]->clone : undef}, |
catch up Object::Simple upda...
|
45 |
default => sub {DBI::Custom::SQL::Template->new} |
46 |
} |
|
47 |
} |
|
cleanup
|
48 | |
add tests
|
49 |
### Object Accessor |
add tests
|
50 |
sub dbh : Attr {} |
add tests
|
51 | |
52 | ||
53 |
### Methods |
|
add various thins
|
54 | |
add tests
|
55 |
# Add filter |
56 |
sub add_filter { |
|
57 |
my $invocant = shift; |
|
58 |
|
|
59 |
my %old_filters = $invocant->filters; |
|
60 |
my %new_filters = ref $_[0] eq 'HASH' ? %{$_[0]} : @_; |
|
61 |
$invocant->filters(%old_filters, %new_filters); |
|
update document
|
62 |
return $invocant; |
add tests
|
63 |
} |
add various
|
64 | |
65 |
# Auto commit |
|
update document
|
66 |
sub _auto_commit { |
add various
|
67 |
my $self = shift; |
68 |
|
|
69 |
croak("Cannot change AutoCommit becouse of not connected") |
|
70 |
unless $self->dbh; |
|
71 |
|
|
72 |
if (@_) { |
|
73 |
$self->dbh->{AutoCommit} = $_[0]; |
|
74 |
return $self; |
|
75 |
} |
|
76 |
return $self->dbh->{AutoCommit}; |
|
77 |
} |
|
add test
|
78 | |
add various things
|
79 |
# Connect |
add some method
|
80 |
sub connect { |
81 |
my $self = shift; |
|
update document
|
82 |
my $data_source = $self->data_source; |
83 |
my $user = $self->user; |
|
84 |
my $password = $self->password; |
|
cleanup
|
85 |
my $dbi_options = $self->dbi_options; |
add test
|
86 |
|
add some method
|
87 |
my $dbh = DBI->connect( |
update document
|
88 |
$data_source, |
89 |
$user, |
|
90 |
$password, |
|
add some method
|
91 |
{ |
92 |
RaiseError => 1, |
|
93 |
PrintError => 0, |
|
94 |
AutoCommit => 1, |
|
cleanup
|
95 |
%{$dbi_options || {} } |
add some method
|
96 |
} |
97 |
); |
|
98 |
|
|
99 |
$self->dbh($dbh); |
|
add various
|
100 |
return $self; |
add some method
|
101 |
} |
first commit
|
102 | |
add tests
|
103 |
# DESTROY |
add tests
|
104 |
sub DESTROY { |
105 |
my $self = shift; |
|
add tests
|
106 |
$self->disconnect if $self->connected; |
add tests
|
107 |
} |
108 | ||
add various things
|
109 |
# Is connected? |
110 |
sub connected { |
|
111 |
my $self = shift; |
|
add tests
|
112 |
return exists $self->{dbh} && eval {$self->{dbh}->can('prepare')}; |
add various things
|
113 |
} |
114 | ||
115 |
# Disconnect |
|
116 |
sub disconnect { |
|
117 |
my $self = shift; |
|
add tests
|
118 |
if ($self->connected) { |
add various things
|
119 |
$self->dbh->disconnect; |
120 |
delete $self->{dbh}; |
|
121 |
} |
|
122 |
} |
|
123 | ||
124 |
# Reconnect |
|
125 |
sub reconnect { |
|
126 |
my $self = shift; |
|
add tests
|
127 |
$self->disconnect if $self->connected; |
add various things
|
128 |
$self->connect; |
129 |
} |
|
130 | ||
try various
|
131 |
# Run tranzaction |
132 |
sub run_tranzaction { |
|
133 |
my ($self, $tranzaction) = @_; |
|
134 |
|
|
update document
|
135 |
$self->_auto_commit(0); |
try various
|
136 |
|
137 |
eval { |
|
138 |
$tranzaction->(); |
|
139 |
$self->dbh->commit; |
|
140 |
}; |
|
141 |
|
|
142 |
if ($@) { |
|
143 |
my $tranzaction_error = $@; |
|
144 |
|
|
145 |
$self->dbh->rollback or croak("$@ and rollback also failed"); |
|
146 |
croak("$tranzaction_error"); |
|
147 |
} |
|
update document
|
148 |
$self->_auto_commit(1); |
add tests
|
149 |
} |
150 | ||
add prepare
|
151 |
sub prepare { |
152 |
my ($self, $sql) = @_; |
|
153 |
eval{$self->connect unless $self->connected}; |
|
154 |
croak($@) if $@; |
|
155 |
|
|
156 |
my $sth = eval{$self->dbh->prepare($sql)}; |
|
157 |
croak($@) if $@; |
|
158 |
return $sth; |
|
159 |
} |
|
160 | ||
161 |
sub do{ |
|
162 |
my ($self, $sql, @bind_values) = @_; |
|
163 |
eval{$self->connect unless $self->connected}; |
|
164 |
croak($@) if $@; |
|
165 |
|
|
166 |
eval{$self->dbh->do($sql, @bind_values)}; |
|
167 |
croak($@) if $@; |
|
168 |
} |
|
169 | ||
add various thins
|
170 |
sub create_query { |
171 |
my ($self, $template) = @_; |
|
add test
|
172 |
|
add various thins
|
173 |
# Create query from SQL template |
add prepare
|
174 |
my $sql_template = $self->sql_template; |
175 |
my $query = eval{$sql_template->create_query($template)}; |
|
176 |
croak($@) if $@; |
|
add test
|
177 |
|
add various thins
|
178 |
# Create Query object; |
cleanup
|
179 |
$query = DBI::Custom::Query->new($query); |
add various thins
|
180 |
|
181 |
# connect if not |
|
182 |
$self->connect unless $self->connected; |
|
try varioud way
|
183 |
|
add various thins
|
184 |
# Prepare statement handle |
add prepare
|
185 |
my $sth = eval{$self->dbh->prepare($query->{sql})}; |
add tests
|
186 |
if ($@) { |
187 |
my $sql = $query->{sql} || ''; |
|
188 |
my $message = "<Created SQL>\n$sql\n"; |
|
189 |
croak("$@$message"); |
|
190 |
} |
|
add tests
|
191 |
|
add no_bind_filters
|
192 |
# Set statement handle |
add various thins
|
193 |
$query->sth($sth); |
add tests
|
194 |
|
add no_bind_filters
|
195 |
# Set bind filter |
196 |
$query->bind_filter($self->bind_filter); |
|
197 |
|
|
198 |
# Set no filter keys when binding |
|
199 |
$query->no_bind_filters($self->no_bind_filters); |
|
add tests
|
200 |
|
add no_bind_filters
|
201 |
# Set fetch filter |
202 |
$query->fetch_filter($self->fetch_filter); |
|
203 |
|
|
204 |
# Set no filter keys when fetching |
|
205 |
$query->no_fetch_filters($self->no_fetch_filters); |
|
206 |
|
|
add various thins
|
207 |
return $query; |
208 |
} |
|
209 | ||
210 |
sub execute { |
|
211 |
my ($self, $query, $params) = @_; |
|
add tests
|
212 |
$params ||= {}; |
try varioud way
|
213 |
|
add tests
|
214 |
# First argument is SQL template |
215 |
if (!ref $query) { |
|
216 |
my $template = $query; |
|
217 |
$query = $self->create_query($template); |
|
218 |
my $query_edit_cb = $_[3]; |
|
219 |
$query_edit_cb->($query) if ref $query_edit_cb eq 'CODE'; |
|
220 |
} |
|
221 |
|
|
add various thins
|
222 |
# Create bind value |
223 |
my $bind_values = $self->_build_bind_values($query, $params); |
|
add tests
|
224 |
|
cleanup
|
225 |
# Execute |
cleanup
|
226 |
my $sth = $query->sth; |
add tests
|
227 |
my $ret_val = eval{$sth->execute(@$bind_values)}; |
add tests
|
228 |
if ($@) { |
229 |
require Data::Dumper; |
|
230 |
my $sql = $query->{sql} || ''; |
|
231 |
my $params_dump = Data::Dumper->Dump([$params], ['*params']); |
|
232 |
|
|
233 |
my $message = "<Created SQL>\n$sql\n<Your parameters>$params_dump"; |
|
234 |
croak("$@$message"); |
|
235 |
} |
|
add various things
|
236 |
|
cleanup
|
237 |
# Return resultset if select statement is executed |
add various things
|
238 |
if ($sth->{NUM_OF_FIELDS}) { |
239 |
my $result_class = $self->result_class; |
|
add various
|
240 |
my $result = $result_class->new({ |
add no_bind_filters
|
241 |
sth => $sth, |
242 |
fetch_filter => $query->fetch_filter, |
|
243 |
no_fetch_filters => $query->no_fetch_filters |
|
add various
|
244 |
}); |
add various things
|
245 |
return $result; |
246 |
} |
|
add tests
|
247 |
return $ret_val; |
add test
|
248 |
} |
249 | ||
add various thins
|
250 |
sub _build_bind_values { |
251 |
my ($self, $query, $params) = @_; |
|
cleanup
|
252 |
|
add no_bind_filters
|
253 |
my $key_infos = $query->key_infos; |
254 |
my $bind_filter = $query->bind_filter; |
|
255 |
my $no_bind_filters_map = $query->_no_bind_filters_map || {}; |
|
cleanup
|
256 |
|
add various thins
|
257 |
# binding values |
258 |
my @bind_values; |
|
cleanup
|
259 |
|
add tests
|
260 |
# Create bind values |
cleanup
|
261 |
foreach my $key_info (@$key_infos) { |
262 |
my $filtering_key = $key_info->{key}; |
|
263 |
my $access_keys = $key_info->{access_keys}; |
|
add various thins
|
264 |
|
cleanup
|
265 |
my $original_key = $key_info->{original_key} || ''; |
266 |
my $table = $key_info->{table} || ''; |
|
267 |
my $column = $key_info->{column} || ''; |
|
add various thins
|
268 |
|
add tests
|
269 |
my $found; |
add various thins
|
270 |
ACCESS_KEYS : |
271 |
foreach my $access_key (@$access_keys) { |
|
272 |
my $root_params = $params; |
|
273 |
for (my $i = 0; $i < @$access_key; $i++) { |
|
274 |
my $key = $access_key->[$i]; |
|
275 |
|
|
276 |
croak("'access_keys' each value must be string or array reference") |
|
277 |
unless (ref $key eq 'ARRAY' || ($key && !ref $key)); |
|
278 |
|
|
279 |
if ($i == @$access_key - 1) { |
|
280 |
if (ref $key eq 'ARRAY') { |
|
add no_bind_filters
|
281 |
if ($bind_filter && !$no_bind_filters_map->{$original_key}) { |
282 |
push @bind_values, |
|
cleanup
|
283 |
$bind_filter->($original_key, $root_params->[$key->[0]], |
284 |
$table, $column); |
|
add various thins
|
285 |
} |
286 |
else { |
|
287 |
push @bind_values, scalar $root_params->[$key->[0]]; |
|
288 |
} |
|
289 |
} |
|
290 |
else { |
|
291 |
next ACCESS_KEYS unless exists $root_params->{$key}; |
|
add no_bind_filters
|
292 |
if ($bind_filter && !$no_bind_filters_map->{$original_key}) { |
293 |
push @bind_values, |
|
cleanup
|
294 |
$bind_filter->($original_key, $root_params->{$key}, |
295 |
$table, $column); |
|
add various thins
|
296 |
} |
297 |
else { |
|
298 |
push @bind_values, scalar $root_params->{$key}; |
|
299 |
} |
|
300 |
} |
|
add tests
|
301 |
$found = 1; |
add various thins
|
302 |
} |
303 |
|
|
add tests
|
304 |
if (ref $key eq 'ARRAY') { |
add various thins
|
305 |
$root_params = $root_params->[$key->[0]]; |
306 |
} |
|
307 |
else { |
|
308 |
next ACCESS_KEYS unless exists $root_params->{$key}; |
|
309 |
$root_params = $root_params->{$key}; |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
add tests
|
313 |
|
314 |
unless ($found) { |
|
315 |
require Data::Dumper; |
|
add tests
|
316 |
my $key_info_dump = Data::Dumper->Dump([$key_info], ['*key_info']); |
add tests
|
317 |
my $params_dump = Data::Dumper->Dump([$params], ['*params']); |
add tests
|
318 |
croak("Key not found in your parameters\n" . |
add tests
|
319 |
"<Key information>\n$key_info_dump\n\n" . |
320 |
"<Your parameters>\n$params_dump\n"); |
|
321 |
} |
|
update document
|
322 |
} |
add tests
|
323 |
return \@bind_values; |
add test
|
324 |
} |
325 | ||
add various thins
|
326 | |
add test
|
327 |
Object::Simple->build_class; |
328 | ||
first commit
|
329 |
=head1 NAME |
330 | ||
add test
|
331 |
DBI::Custom - Customizable simple DBI |
first commit
|
332 | |
333 |
=head1 VERSION |
|
334 | ||
add test
|
335 |
Version 0.0101 |
first commit
|
336 | |
337 |
=cut |
|
338 | ||
339 |
=head1 SYNOPSIS |
|
340 | ||
add test
|
341 |
my $dbi = DBI::Custom->new; |
add various thins
|
342 |
|
343 |
my $query = $dbi->create_query($template); |
|
344 |
$dbi->execute($query); |
|
first commit
|
345 | |
update document
|
346 |
=head1 CLASS-OBJECT ACCESSORS |
first commit
|
347 | |
update document
|
348 |
=head2 user |
349 | ||
350 |
# Set and get database user name |
|
351 |
$self = $dbi->user($user); |
|
352 |
$user = $dbi->user; |
|
353 |
|
|
354 |
# Sample |
|
355 |
$dbi->user('taro'); |
|
356 | ||
357 |
=head2 password |
|
358 | ||
359 |
# Set and get database password |
|
360 |
$self = $dbi->password($password); |
|
361 |
$password = $dbi->password; |
|
362 |
|
|
363 |
# Sample |
|
364 |
$dbi->password('lkj&le`@s'); |
|
365 | ||
366 |
=head2 data_source |
|
367 | ||
368 |
# Set and get database data source |
|
369 |
$self = $dbi->data_source($data_soruce); |
|
370 |
$data_source = $dbi->data_source; |
|
371 |
|
|
372 |
# Sample(SQLite) |
|
373 |
$dbi->data_source(dbi:SQLite:dbname=$database); |
|
374 |
|
|
375 |
# Sample(MySQL); |
|
376 |
$dbi->data_source("dbi:mysql:dbname=$database"); |
|
377 |
|
|
378 |
# Sample(PostgreSQL) |
|
379 |
$dbi->data_source("dbi:Pg:dbname=$database"); |
|
cleanup
|
380 |
|
381 |
=head2 database |
|
382 | ||
383 |
# Set and get database name |
|
384 |
$self = $dbi->database($database); |
|
385 |
$database = $dbi->database; |
|
update document
|
386 | |
cleanup
|
387 |
=head2 dbi_options |
update document
|
388 | |
389 |
# Set and get DBI option |
|
cleanup
|
390 |
$self = $dbi->dbi_options({$options => $value, ...}); |
391 |
$dbi_options = $dbi->dbi_options; |
|
update document
|
392 | |
393 |
# Sample |
|
cleanup
|
394 |
$dbi->dbi_options({PrintError => 0, RaiseError => 1}); |
update document
|
395 | |
cleanup
|
396 |
dbi_options is used when you connect database by using connect. |
update document
|
397 | |
add prepare
|
398 |
=head2 prepare |
399 | ||
400 |
$sth = $dbi->prepare($sql); |
|
401 | ||
402 |
This method is same as DBI::prepare |
|
403 | ||
404 |
=head2 do |
|
405 | ||
406 |
$dbi->do($sql, @bind_values); |
|
407 | ||
408 |
This method is same as DBI::do |
|
409 | ||
update document
|
410 |
=head2 sql_template |
411 | ||
412 |
# Set and get SQL::Template object |
|
413 |
$self = $dbi->sql_template($sql_template); |
|
414 |
$sql_template = $dbi->sql_template; |
|
415 |
|
|
416 |
# Sample |
|
417 |
$dbi->sql_template(DBI::Cutom::SQL::Template->new); |
|
418 | ||
419 |
=head2 filters |
|
420 | ||
421 |
# Set and get filters |
|
422 |
$self = $dbi->filters($filters); |
|
423 |
$filters = $dbi->filters; |
|
first commit
|
424 | |
add test
|
425 |
=head2 bind_filter |
first commit
|
426 | |
update document
|
427 |
# Set and get binding filter |
428 |
$self = $dbi->bind_filter($bind_filter); |
|
429 |
$bind_filter = $dbi->bind_filter |
|
first commit
|
430 | |
update document
|
431 |
# Sample |
432 |
$dbi->bind_filter($self->filters->{default_bind_filter}); |
|
433 |
|
|
first commit
|
434 | |
update document
|
435 |
you can get DBI database handle if you need. |
first commit
|
436 | |
add test
|
437 |
=head2 fetch_filter |
first commit
|
438 | |
update document
|
439 |
# Set and get Fetch filter |
440 |
$self = $dbi->fetch_filter($fetch_filter); |
|
441 |
$fetch_filter = $dbi->fetch_filter; |
|
first commit
|
442 | |
update document
|
443 |
# Sample |
444 |
$dbi->fetch_filter($self->filters->{default_fetch_filter}); |
|
add test
|
445 | |
add no_bind_filters
|
446 |
=head2 no_bind_filters |
447 | ||
448 |
# Set and get no filter keys when binding |
|
449 |
$self = $dbi->no_bind_filters($no_bind_filters); |
|
450 |
$no_bind_filters = $dbi->no_bind_filters; |
|
451 | ||
452 |
=head2 no_fetch_filters |
|
cleanup
|
453 | |
add no_bind_filters
|
454 |
# Set and get no filter keys when fetching |
455 |
$self = $dbi->no_fetch_filters($no_fetch_filters); |
|
456 |
$no_fetch_filters = $dbi->no_fetch_filters; |
|
cleanup
|
457 | |
update document
|
458 |
=head2 result_class |
first commit
|
459 | |
update document
|
460 |
# Set and get resultset class |
461 |
$self = $dbi->result_class($result_class); |
|
462 |
$result_class = $dbi->result_class; |
|
463 |
|
|
464 |
# Sample |
|
465 |
$dbi->result_class('DBI::Custom::Result'); |
|
add test
|
466 | |
update document
|
467 |
=head2 dbh |
add test
|
468 | |
update document
|
469 |
# Get database handle |
470 |
$dbh = $self->dbh; |
|
add test
|
471 | |
update document
|
472 |
=head1 METHODS |
add tests
|
473 | |
update document
|
474 |
=head2 connect |
475 | ||
476 |
# Connect to database |
|
477 |
$self = $dbi->connect; |
|
478 |
|
|
479 |
# Sample |
|
480 |
$dbi = DBI::Custom->new(user => 'taro', password => 'lji8(', |
|
481 |
data_soruce => "dbi:mysql:dbname=$database"); |
|
482 |
$dbi->connect; |
|
add tests
|
483 | |
484 |
=head2 disconnect |
|
485 | ||
update document
|
486 |
# Disconnect database |
487 |
$dbi->disconnect; |
|
488 | ||
489 |
If database is already disconnected, this method do noting. |
|
490 | ||
add tests
|
491 |
=head2 reconnect |
492 | ||
update document
|
493 |
# Reconnect |
494 |
$dbi->reconnect; |
|
495 | ||
496 |
=head2 connected |
|
497 | ||
498 |
# Check connected |
|
499 |
$dbi->connected |
|
500 | ||
501 |
=head2 add_filter |
|
502 | ||
503 |
# Add filter (hash ref or hash can be recieve) |
|
504 |
$self = $dbi->add_filter({$filter_name => $filter, ...}); |
|
505 |
$self = $dbi->add_filter($filetr_name => $filter, ...); |
|
506 |
|
|
507 |
# Sample |
|
508 |
$dbi->add_filter( |
|
509 |
decode_utf8 => sub { |
|
cleanup
|
510 |
my ($key, $value, $table, $column) = @_; |
update document
|
511 |
return Encode::decode('UTF-8', $value); |
512 |
}, |
|
513 |
datetime_to_string => sub { |
|
cleanup
|
514 |
my ($key, $value, $table, $column) = @_; |
update document
|
515 |
return $value->strftime('%Y-%m-%d %H:%M:%S') |
516 |
}, |
|
517 |
default_bind_filter => sub { |
|
cleanup
|
518 |
my ($key, $value, $table, $column) = @_; |
update document
|
519 |
if (ref $value eq 'Time::Piece') { |
cleanup
|
520 |
return $dbi->filters->{datetime_to_string}->($value); |
update document
|
521 |
} |
522 |
else { |
|
cleanup
|
523 |
return $dbi->filters->{decode_utf8}->($value); |
update document
|
524 |
} |
525 |
}, |
|
526 |
|
|
527 |
encode_utf8 => sub { |
|
cleanup
|
528 |
my ($key, $value) = @_; |
update document
|
529 |
return Encode::encode('UTF-8', $value); |
530 |
}, |
|
531 |
string_to_datetime => sub { |
|
cleanup
|
532 |
my ($key, $value) = @_; |
update document
|
533 |
return DateTime::Format::MySQL->parse_datetime($value); |
534 |
}, |
|
535 |
default_fetch_filter => sub { |
|
cleanup
|
536 |
my ($key, $value, $type, $sth, $i) = @_; |
update document
|
537 |
if ($type eq 'DATETIME') { |
cleanup
|
538 |
return $dbi->filters->{string_to_datetime}->($value); |
update document
|
539 |
} |
540 |
else { |
|
cleanup
|
541 |
return $dbi->filters->{encode_utf8}->($value); |
update document
|
542 |
} |
543 |
} |
|
544 |
); |
|
545 | ||
546 |
add_filter add filter to filters |
|
add tests
|
547 | |
cleanup
|
548 |
=head2 create_query |
549 |
|
|
550 |
# Create Query object from SQL template |
|
551 |
my $query = $dbi->create_query($template); |
|
552 |
|
|
553 |
=head2 execute |
|
update document
|
554 | |
555 |
# Parse SQL template and execute SQL |
|
cleanup
|
556 |
$result = $dbi->query($query, $params); |
557 |
$result = $dbi->query($template, $params); # Shorcut |
|
update document
|
558 |
|
559 |
# Sample |
|
560 |
$result = $dbi->query("select * from authors where {= name} && {= age}", |
|
561 |
{author => 'taro', age => 19}); |
|
562 |
|
|
563 |
while (my @row = $result->fetch) { |
|
564 |
# do something |
|
565 |
} |
|
566 | ||
567 |
See also L<DBI::Custom::SQL::Template> |
|
568 | ||
cleanup
|
569 |
=head2 run_tranzaction |
first commit
|
570 | |
update document
|
571 |
# Run tranzaction |
572 |
$dbi->run_tranzaction(sub { |
|
573 |
# do something |
|
574 |
}); |
|
first commit
|
575 | |
update document
|
576 |
If tranzaction is success, commit is execute. |
577 |
If tranzation is died, rollback is execute. |
|
first commit
|
578 | |
cleanup
|
579 | |
580 | ||
add various
|
581 |
=head1 AUTHOR |
first commit
|
582 | |
add various
|
583 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
first commit
|
584 | |
add tests
|
585 |
Github L<http://github.com/yuki-kimoto> |
586 | ||
first commit
|
587 |
=head1 COPYRIGHT & LICENSE |
588 | ||
589 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
590 | ||
591 |
This program is free software; you can redistribute it and/or modify it |
|
592 |
under the same terms as Perl itself. |
|
593 | ||
594 | ||
595 |
=cut |
|
596 | ||
597 |
1; # End of DBI::Custom |