cleanup
|
1 |
package DBIx::Custom; |
2 | ||
cleanup
|
3 |
our $VERSION = '0.1618'; |
fixed DBIx::Custom::QueryBui...
|
4 | |
5 |
use 5.008001; |
|
cleanup
|
6 |
use strict; |
7 |
use warnings; |
|
8 | ||
remove run_transaction().
|
9 |
use base 'Object::Simple'; |
many change
|
10 | |
packaging one directory
|
11 |
use Carp 'croak'; |
12 |
use DBI; |
|
13 |
use DBIx::Custom::Result; |
|
cleanup
|
14 |
use DBIx::Custom::Query; |
cleanup
|
15 |
use DBIx::Custom::QueryBuilder; |
update document
|
16 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
17 | |
cleanup
|
18 |
__PACKAGE__->attr([qw/data_source dbh default_bind_filter |
19 |
default_fetch_filter password user/]); |
|
added cache_method attribute
|
20 | |
add cache attribute
|
21 |
__PACKAGE__->attr(cache => 1); |
added cache_method attribute
|
22 |
__PACKAGE__->attr(cache_method => sub { |
23 |
sub { |
|
24 |
my $self = shift; |
|
25 |
|
|
26 |
$self->{_cached} ||= {}; |
|
27 |
|
|
28 |
if (@_ > 1) { |
|
29 |
$self->{_cached}{$_[0]} = $_[1] |
|
30 |
} |
|
31 |
else { |
|
32 |
return $self->{_cached}{$_[0]} |
|
33 |
} |
|
34 |
} |
|
35 |
}); |
|
removed register_format()
|
36 | |
cleanup
|
37 |
__PACKAGE__->dual_attr('filters', default => sub { {} }, |
38 |
inherit => 'hash_copy'); |
|
added check_filter attribute
|
39 |
__PACKAGE__->attr(filter_check => 1); |
cleanup
|
40 |
__PACKAGE__->attr(query_builder => sub {DBIx::Custom::QueryBuilder->new}); |
41 |
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result'); |
|
42 | ||
43 |
# DBI methods |
|
44 |
foreach my $method (qw/begin_work commit rollback/) { |
|
45 |
my $code = sub { |
|
46 |
my $self = shift; |
|
47 |
my $ret = eval {$self->dbh->$method}; |
|
48 |
croak $@ if $@; |
|
49 |
return $ret; |
|
50 |
}; |
|
51 |
no strict 'refs'; |
|
52 |
my $pkg = __PACKAGE__; |
|
53 |
*{"${pkg}::$method"} = $code; |
|
54 |
}; |
|
55 | ||
56 |
# Regster filter |
|
57 |
__PACKAGE__->register_filter( |
|
58 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
59 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
60 |
); |
|
added check_filter attribute
|
61 | |
added helper method
|
62 |
our $AUTOLOAD; |
63 | ||
64 |
sub AUTOLOAD { |
|
65 |
my $self = shift; |
|
66 | ||
67 |
# Method |
|
68 |
my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
69 | ||
70 |
# Helper |
|
71 |
$self->{_helpers} ||= {}; |
|
72 |
croak qq/Can't locate object method "$method" via "$package"/ |
|
73 |
unless my $helper = $self->{_helpers}->{$method}; |
|
74 | ||
75 |
# Run |
|
76 |
return $self->$helper(@_); |
|
77 |
} |
|
78 | ||
79 |
sub helper { |
|
80 |
my $self = shift; |
|
81 |
|
|
82 |
# Merge |
|
83 |
my $helpers = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
84 |
$self->{_helpers} = {%{$self->{_helpers} || {}}, %$helpers}; |
|
85 |
|
|
86 |
return $self; |
|
87 |
} |
|
88 | ||
packaging one directory
|
89 |
sub connect { |
removed register_format()
|
90 |
my $proto = shift; |
91 |
|
|
92 |
# Create |
|
93 |
my $self = ref $proto ? $proto : $proto->new(@_); |
|
update document
|
94 |
|
95 |
# Information |
|
packaging one directory
|
96 |
my $data_source = $self->data_source; |
97 |
my $user = $self->user; |
|
98 |
my $password = $self->password; |
|
99 |
|
|
removed experimental registe...
|
100 |
|
update document
|
101 |
# Connect |
select, insert, update, upda...
|
102 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
103 |
$data_source, |
104 |
$user, |
|
105 |
$password, |
|
106 |
{ |
|
107 |
RaiseError => 1, |
|
108 |
PrintError => 0, |
|
109 |
AutoCommit => 1, |
|
110 |
} |
|
111 |
)}; |
|
112 |
|
|
update document
|
113 |
# Connect error |
packaging one directory
|
114 |
croak $@ if $@; |
115 |
|
|
update document
|
116 |
# Database handle |
packaging one directory
|
117 |
$self->dbh($dbh); |
update document
|
118 |
|
packaging one directory
|
119 |
return $self; |
120 |
} |
|
121 | ||
cleanup
|
122 |
sub create_query { |
123 |
my ($self, $source) = @_; |
|
update document
|
124 |
|
cleanup
|
125 |
# Cache |
126 |
my $cache = $self->cache; |
|
update document
|
127 |
|
cleanup
|
128 |
# Create query |
129 |
my $query; |
|
130 |
if ($cache) { |
|
131 |
|
|
132 |
# Get query |
|
133 |
my $q = $self->cache_method->($self, $source); |
|
134 |
|
|
135 |
# Create query |
|
136 |
$query = DBIx::Custom::Query->new($q) if $q; |
|
137 |
} |
|
138 |
|
|
139 |
unless ($query) { |
|
cleanup insert
|
140 | |
cleanup
|
141 |
# Create SQL object |
142 |
my $builder = $self->query_builder; |
|
143 |
|
|
144 |
# Create query |
|
145 |
$query = $builder->build_query($source); |
|
removed register_format()
|
146 | |
cleanup
|
147 |
# Cache query |
148 |
$self->cache_method->($self, $source, |
|
149 |
{sql => $query->sql, |
|
150 |
columns => $query->columns}) |
|
151 |
if $cache; |
|
cleanup insert
|
152 |
} |
153 |
|
|
cleanup
|
154 |
# Prepare statement handle |
155 |
my $sth; |
|
156 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
157 |
$self->_croak($@, qq{. SQL: "$query->{sql}"}) if $@; |
|
packaging one directory
|
158 |
|
cleanup
|
159 |
# Set statement handle |
160 |
$query->sth($sth); |
|
packaging one directory
|
161 |
|
cleanup
|
162 |
return $query; |
packaging one directory
|
163 |
} |
164 | ||
cleanup
|
165 |
our %VALID_DELETE_ARGS |
166 |
= map { $_ => 1 } qw/table where append filter allow_delete_all/; |
|
cleanup update and update_al...
|
167 | |
cleanup
|
168 |
sub delete { |
select, insert, update, upda...
|
169 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
170 |
|
171 |
# Check arguments |
|
select, insert, update, upda...
|
172 |
foreach my $name (keys %args) { |
add tests
|
173 |
croak qq{"$name" is invalid argument} |
cleanup
|
174 |
unless $VALID_DELETE_ARGS{$name}; |
cleanup update and update_al...
|
175 |
} |
176 |
|
|
177 |
# Arguments |
|
select, insert, update, upda...
|
178 |
my $table = $args{table} || ''; |
179 |
my $where = $args{where} || {}; |
|
cleanup
|
180 |
my $append = $args{append}; |
select, insert, update, upda...
|
181 |
my $filter = $args{filter}; |
cleanup
|
182 |
my $allow_delete_all = $args{allow_delete_all}; |
packaging one directory
|
183 |
|
184 |
# Where keys |
|
removed register_format()
|
185 |
my @where_keys = keys %$where; |
packaging one directory
|
186 |
|
187 |
# Not exists where keys |
|
add tests
|
188 |
croak qq{"where" argument must be specified and } . |
189 |
qq{contains the pairs of column name and value} |
|
cleanup
|
190 |
if !@where_keys && !$allow_delete_all; |
packaging one directory
|
191 |
|
192 |
# Where clause |
|
193 |
my $where_clause = ''; |
|
194 |
if (@where_keys) { |
|
195 |
$where_clause = 'where '; |
|
add tests
|
196 |
$where_clause .= "{= $_} and " for @where_keys; |
packaging one directory
|
197 |
$where_clause =~ s/ and $//; |
198 |
} |
|
199 |
|
|
add tests
|
200 |
# Source of SQL |
cleanup
|
201 |
my $source = "delete from $table $where_clause"; |
add tests
|
202 |
$source .= " $append" if $append; |
packaging one directory
|
203 |
|
204 |
# Execute query |
|
cleanup
|
205 |
my $ret_val = $self->execute($source, param => $where, |
add tests
|
206 |
filter => $filter); |
packaging one directory
|
207 |
|
208 |
return $ret_val; |
|
209 |
} |
|
210 | ||
cleanup
|
211 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
212 | |
added helper method
|
213 |
sub DESTROY { } |
214 | ||
cleanup
|
215 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter/; |
refactoring delete and delet...
|
216 | |
cleanup
|
217 |
sub execute{ |
218 |
my ($self, $query, %args) = @_; |
|
refactoring delete and delet...
|
219 |
|
220 |
# Check arguments |
|
select, insert, update, upda...
|
221 |
foreach my $name (keys %args) { |
add tests
|
222 |
croak qq{"$name" is invalid argument} |
cleanup
|
223 |
unless $VALID_EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
224 |
} |
225 |
|
|
cleanup
|
226 |
my $params = $args{param} || {}; |
packaging one directory
|
227 |
|
cleanup
|
228 |
# First argument is the soruce of SQL |
229 |
$query = $self->create_query($query) |
|
230 |
unless ref $query; |
|
packaging one directory
|
231 |
|
cleanup
|
232 |
my $filter = $args{filter} || $query->filter || {}; |
packaging one directory
|
233 |
|
cleanup
|
234 |
# Create bind value |
235 |
my $bind_values = $self->_build_bind_values($query, $params, $filter); |
|
236 |
|
|
237 |
# Execute |
|
238 |
my $sth = $query->sth; |
|
239 |
my $affected; |
|
240 |
eval {$affected = $sth->execute(@$bind_values)}; |
|
241 |
$self->_croak($@) if $@; |
|
242 |
|
|
243 |
# Return resultset if select statement is executed |
|
244 |
if ($sth->{NUM_OF_FIELDS}) { |
|
245 |
|
|
246 |
# Create result |
|
247 |
my $result = $self->result_class->new( |
|
248 |
sth => $sth, |
|
249 |
default_filter => $self->default_fetch_filter, |
|
250 |
filters => $self->filters, |
|
251 |
filter_check => $self->filter_check |
|
252 |
); |
|
253 | ||
254 |
return $result; |
|
255 |
} |
|
256 |
return $affected; |
|
257 |
} |
|
258 | ||
259 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append filter/; |
|
260 | ||
261 |
sub insert { |
|
262 |
my ($self, %args) = @_; |
|
263 | ||
264 |
# Check arguments |
|
265 |
foreach my $name (keys %args) { |
|
266 |
croak qq{"$name" is invalid argument} |
|
267 |
unless $VALID_INSERT_ARGS{$name}; |
|
packaging one directory
|
268 |
} |
269 |
|
|
cleanup
|
270 |
# Arguments |
271 |
my $table = $args{table} || ''; |
|
272 |
my $param = $args{param} || {}; |
|
273 |
my $append = $args{append} || ''; |
|
274 |
my $filter = $args{filter}; |
|
275 |
|
|
276 |
# Insert keys |
|
277 |
my @insert_keys = keys %$param; |
|
278 |
|
|
279 |
# Templte for insert |
|
280 |
my $source = "insert into $table {insert_param " |
|
281 |
. join(' ', @insert_keys) . '}'; |
|
add tests
|
282 |
$source .= " $append" if $append; |
packaging one directory
|
283 |
|
284 |
# Execute query |
|
cleanup
|
285 |
my $ret_val = $self->execute($source, param => $param, |
286 |
filter => $filter); |
|
packaging one directory
|
287 |
|
288 |
return $ret_val; |
|
289 |
} |
|
290 | ||
cleanup
|
291 |
sub register_filter { |
292 |
my $invocant = shift; |
|
293 |
|
|
294 |
# Register filter |
|
295 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
296 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
297 |
|
|
298 |
return $invocant; |
|
299 |
} |
|
packaging one directory
|
300 | |
refactoring select
|
301 |
our %VALID_SELECT_ARGS |
added commit method
|
302 |
= map { $_ => 1 } qw/table column where append relation filter param/; |
refactoring select
|
303 | |
packaging one directory
|
304 |
sub select { |
select, insert, update, upda...
|
305 |
my ($self, %args) = @_; |
packaging one directory
|
306 |
|
refactoring select
|
307 |
# Check arguments |
select, insert, update, upda...
|
308 |
foreach my $name (keys %args) { |
add tests
|
309 |
croak qq{"$name" is invalid argument} |
refactoring select
|
310 |
unless $VALID_SELECT_ARGS{$name}; |
311 |
} |
|
packaging one directory
|
312 |
|
refactoring select
|
313 |
# Arguments |
select, insert, update, upda...
|
314 |
my $tables = $args{table} || []; |
removed register_format()
|
315 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
select, insert, update, upda...
|
316 |
my $columns = $args{column} || []; |
update document
|
317 |
my $where = $args{where}; |
select, insert, update, upda...
|
318 |
my $relation = $args{relation}; |
319 |
my $append = $args{append}; |
|
320 |
my $filter = $args{filter}; |
|
packaging one directory
|
321 |
|
add tests
|
322 |
# Source of SQL |
renamed default_query_filter...
|
323 |
my $source = 'select '; |
packaging one directory
|
324 |
|
added commit method
|
325 |
# Column clause |
packaging one directory
|
326 |
if (@$columns) { |
327 |
foreach my $column (@$columns) { |
|
renamed default_query_filter...
|
328 |
$source .= "$column, "; |
packaging one directory
|
329 |
} |
renamed default_query_filter...
|
330 |
$source =~ s/, $/ /; |
packaging one directory
|
331 |
} |
332 |
else { |
|
renamed default_query_filter...
|
333 |
$source .= '* '; |
packaging one directory
|
334 |
} |
335 |
|
|
added commit method
|
336 |
# Table |
renamed default_query_filter...
|
337 |
$source .= 'from '; |
packaging one directory
|
338 |
foreach my $table (@$tables) { |
renamed default_query_filter...
|
339 |
$source .= "$table, "; |
packaging one directory
|
340 |
} |
renamed default_query_filter...
|
341 |
$source =~ s/, $/ /; |
packaging one directory
|
342 |
|
added commit method
|
343 |
# Where clause |
update document
|
344 |
my $param; |
345 |
if (ref $where eq 'HASH') { |
|
346 |
$param = $where; |
|
347 |
$source .= 'where ('; |
|
348 |
foreach my $where_key (keys %$where) { |
|
renamed default_query_filter...
|
349 |
$source .= "{= $where_key} and "; |
packaging one directory
|
350 |
} |
update document
|
351 |
$source =~ s/ and $//; |
352 |
$source .= ') '; |
|
353 |
} |
|
354 |
elsif (ref $where eq 'ARRAY') { |
|
355 |
my$where_str = $where->[0] || ''; |
|
356 |
$param = $where->[1]; |
|
357 |
|
|
358 |
$source .= "where ($where_str) "; |
|
packaging one directory
|
359 |
} |
360 |
|
|
added commit method
|
361 |
# Relation |
362 |
if ($relation) { |
|
update document
|
363 |
$source .= $where ? "and " : "where "; |
added commit method
|
364 |
foreach my $rkey (keys %$relation) { |
renamed default_query_filter...
|
365 |
$source .= "$rkey = " . $relation->{$rkey} . " and "; |
packaging one directory
|
366 |
} |
367 |
} |
|
renamed default_query_filter...
|
368 |
$source =~ s/ and $//; |
added commit method
|
369 |
|
370 |
# Append some statement |
|
renamed default_query_filter...
|
371 |
$source .= " $append" if $append; |
packaging one directory
|
372 |
|
373 |
# Execute query |
|
update document
|
374 |
my $result = $self->execute($source, param => $param, |
375 |
filter => $filter); |
|
packaging one directory
|
376 |
|
377 |
return $result; |
|
378 |
} |
|
379 | ||
cleanup
|
380 |
our %VALID_UPDATE_ARGS |
381 |
= map { $_ => 1 } qw/table param where append filter allow_update_all/; |
|
382 | ||
383 |
sub update { |
|
384 |
my ($self, %args) = @_; |
|
version 0.0901
|
385 |
|
cleanup
|
386 |
# Check arguments |
387 |
foreach my $name (keys %args) { |
|
388 |
croak qq{"$name" is invalid argument} |
|
389 |
unless $VALID_UPDATE_ARGS{$name}; |
|
removed reconnect method
|
390 |
} |
added cache_method attribute
|
391 |
|
cleanup
|
392 |
# Arguments |
393 |
my $table = $args{table} || ''; |
|
394 |
my $param = $args{param} || {}; |
|
395 |
my $where = $args{where} || {}; |
|
396 |
my $append = $args{append} || ''; |
|
397 |
my $filter = $args{filter}; |
|
398 |
my $allow_update_all = $args{allow_update_all}; |
|
version 0.0901
|
399 |
|
cleanup
|
400 |
# Update keys |
401 |
my @update_keys = keys %$param; |
|
renamed fetch_rows to fetch_...
|
402 |
|
cleanup
|
403 |
# Where keys |
404 |
my @where_keys = keys %$where; |
|
removed reconnect method
|
405 |
|
cleanup
|
406 |
# Not exists where keys |
407 |
croak qq{"where" argument must be specified and } . |
|
408 |
qq{contains the pairs of column name and value} |
|
409 |
if !@where_keys && !$allow_update_all; |
|
removed experimental registe...
|
410 |
|
cleanup
|
411 |
# Update clause |
412 |
my $update_clause = '{update_param ' . join(' ', @update_keys) . '}'; |
|
removed experimental registe...
|
413 |
|
cleanup
|
414 |
# Where clause |
415 |
my $where_clause = ''; |
|
416 |
my $new_where = {}; |
|
removed reconnect method
|
417 |
|
cleanup
|
418 |
if (@where_keys) { |
419 |
$where_clause = 'where '; |
|
420 |
$where_clause .= "{= $_} and " for @where_keys; |
|
421 |
$where_clause =~ s/ and $//; |
|
removed reconnect method
|
422 |
} |
423 |
|
|
cleanup
|
424 |
# Source of SQL |
425 |
my $source = "update $table $update_clause $where_clause"; |
|
426 |
$source .= " $append" if $append; |
|
removed reconnect method
|
427 |
|
cleanup
|
428 |
# Rearrange parameters |
429 |
foreach my $wkey (@where_keys) { |
|
removed reconnect method
|
430 |
|
cleanup
|
431 |
if (exists $param->{$wkey}) { |
432 |
$param->{$wkey} = [$param->{$wkey}] |
|
433 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
434 |
|
|
435 |
push @{$param->{$wkey}}, $where->{$wkey}; |
|
436 |
} |
|
437 |
else { |
|
438 |
$param->{$wkey} = $where->{$wkey}; |
|
439 |
} |
|
removed reconnect method
|
440 |
} |
cleanup
|
441 |
|
442 |
# Execute query |
|
443 |
my $ret_val = $self->execute($source, param => $param, |
|
444 |
filter => $filter); |
|
445 |
|
|
446 |
return $ret_val; |
|
removed reconnect method
|
447 |
} |
448 | ||
cleanup
|
449 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
450 | ||
removed reconnect method
|
451 |
sub _build_bind_values { |
452 |
my ($self, $query, $params, $filter) = @_; |
|
453 |
|
|
454 |
# binding values |
|
455 |
my @bind_values; |
|
add tests
|
456 | |
457 |
# Filter |
|
458 |
$filter ||= {}; |
|
459 |
|
|
460 |
# Parameter |
|
461 |
$params ||= {}; |
|
462 |
|
|
463 |
# Check filter |
|
464 |
$self->_check_filter($self->filters, $filter, |
|
465 |
$self->default_bind_filter, $params) |
|
466 |
if $self->filter_check; |
|
removed reconnect method
|
467 |
|
468 |
# Build bind values |
|
469 |
my $count = {}; |
|
470 |
foreach my $column (@{$query->columns}) { |
|
471 |
|
|
472 |
# Value |
|
473 |
my $value = ref $params->{$column} eq 'ARRAY' |
|
474 |
? $params->{$column}->[$count->{$column} || 0] |
|
475 |
: $params->{$column}; |
|
476 |
|
|
add tests
|
477 |
# Filtering |
renamed default_query_filter...
|
478 |
my $fname = $filter->{$column} || $self->default_bind_filter || ''; |
add tests
|
479 |
my $filter_func = $fname ? $self->filters->{$fname} : undef; |
removed reconnect method
|
480 |
push @bind_values, $filter_func |
481 |
? $filter_func->($value) |
|
482 |
: $value; |
|
483 |
|
|
484 |
# Count up |
|
485 |
$count->{$column}++; |
|
486 |
} |
|
487 |
|
|
488 |
return \@bind_values; |
|
489 |
} |
|
490 | ||
add tests
|
491 |
sub _check_filter { |
492 |
my ($self, $filters, $filter, $default_filter, $params) = @_; |
|
493 |
|
|
494 |
# Filter name not exists |
|
495 |
foreach my $fname (values %$filter) { |
|
496 |
croak qq{Bind filter "$fname" is not registered} |
|
497 |
unless exists $filters->{$fname}; |
|
498 |
} |
|
499 |
|
|
500 |
# Default filter name not exists |
|
501 |
croak qq{Default bind filter "$default_filter" is not registered} |
|
502 |
if $default_filter && ! exists $filters->{$default_filter}; |
|
503 |
|
|
504 |
# Column name not exists |
|
505 |
foreach my $column (keys %$filter) { |
|
506 |
|
|
507 |
croak qq{Column name "$column" in bind filter is not found in paramters} |
|
508 |
unless exists $params->{$column}; |
|
509 |
} |
|
510 |
} |
|
511 | ||
cleanup
|
512 |
sub _croak { |
513 |
my ($self, $error, $append) = @_; |
|
514 |
$append ||= ""; |
|
515 |
|
|
516 |
# Verbose |
|
517 |
if ($Carp::Verbose) { croak $error } |
|
518 |
|
|
519 |
# Not verbose |
|
520 |
else { |
|
521 |
|
|
522 |
# Remove line and module infromation |
|
523 |
my $at_pos = rindex($error, ' at '); |
|
524 |
$error = substr($error, 0, $at_pos); |
|
525 |
$error =~ s/\s+$//; |
|
526 |
|
|
527 |
croak "$error$append"; |
|
528 |
} |
|
529 |
} |
|
530 | ||
fixed DBIx::Custom::QueryBui...
|
531 |
1; |
532 | ||
removed reconnect method
|
533 |
=head1 NAME |
534 | ||
renamed build_query to creat...
|
535 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
536 | |
537 |
=head1 SYNOPSYS |
|
cleanup
|
538 | |
renamed build_query to creat...
|
539 |
Connect to the database. |
540 |
|
|
541 |
use DBIx::Custom; |
|
renamed update tag to update...
|
542 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
removed reconnect method
|
543 |
user => 'ken', password => '!LFKD%$&'); |
cleanup
|
544 | |
renamed build_query to creat...
|
545 |
Insert, update, and delete |
cleanup
|
546 | |
removed reconnect method
|
547 |
# Insert |
548 |
$dbi->insert(table => 'books', |
|
renamed update tag to update...
|
549 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
550 |
filter => {title => 'encode_utf8'}); |
551 |
|
|
552 |
# Update |
|
553 |
$dbi->update(table => 'books', |
|
renamed update tag to update...
|
554 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
555 |
where => {id => 5}, |
556 |
filter => {title => 'encode_utf8'}); |
|
557 |
|
|
558 |
# Update all |
|
559 |
$dbi->update_all(table => 'books', |
|
renamed update tag to update...
|
560 |
param => {title => 'Perl'}, |
removed reconnect method
|
561 |
filter => {title => 'encode_utf8'}); |
562 |
|
|
563 |
# Delete |
|
564 |
$dbi->delete(table => 'books', |
|
565 |
where => {author => 'Ken'}, |
|
566 |
filter => {title => 'encode_utf8'}); |
|
567 |
|
|
568 |
# Delete all |
|
569 |
$dbi->delete_all(table => 'books'); |
|
cleanup
|
570 | |
renamed build_query to creat...
|
571 |
Select |
cleanup
|
572 | |
removed reconnect method
|
573 |
# Select |
574 |
my $result = $dbi->select(table => 'books'); |
|
renamed fetch_rows to fetch_...
|
575 |
|
renamed build_query to creat...
|
576 |
# Select, more complex |
renamed fetch_rows to fetch_...
|
577 |
my $result = $dbi->select( |
update document
|
578 |
table => 'books', |
579 |
column => [qw/author title/], |
|
580 |
where => {author => 'Ken'}, |
|
updated document
|
581 |
append => 'order by id limit 5', |
renamed build_query to creat...
|
582 |
filter => {title => 'encode_utf8'} |
renamed fetch_rows to fetch_...
|
583 |
); |
added commit method
|
584 |
|
renamed build_query to creat...
|
585 |
# Select, join table |
added commit method
|
586 |
my $result = $dbi->select( |
renamed build_query to creat...
|
587 |
table => ['books', 'rental'], |
588 |
column => ['books.name as book_name'] |
|
added commit method
|
589 |
relation => {'books.id' => 'rental.book_id'} |
590 |
); |
|
updated document
|
591 |
|
592 |
# Select, more flexible where |
|
593 |
my $result = $dbi->select( |
|
594 |
table => 'books', |
|
595 |
where => ['{= author} and {like title}', |
|
596 |
{author => 'Ken', title => '%Perl%'}] |
|
597 |
); |
|
cleanup
|
598 | |
renamed build_query to creat...
|
599 |
Execute SQL |
cleanup
|
600 | |
renamed build_query to creat...
|
601 |
# Execute SQL |
removed register_format()
|
602 |
$dbi->execute("select title from books"); |
603 |
|
|
renamed build_query to creat...
|
604 |
# Execute SQL with hash binding and filtering |
updated document
|
605 |
$dbi->execute("select id from books where {= author} and {like title}", |
removed register_format()
|
606 |
param => {author => 'ken', title => '%Perl%'}, |
renamed build_query to creat...
|
607 |
filter => {title => 'encode_utf8'}); |
removed reconnect method
|
608 | |
609 |
# Create query and execute it |
|
renamed build_query to creat...
|
610 |
my $query = $dbi->create_query( |
updated document
|
611 |
"select id from books where {= author} and {like title}" |
removed reconnect method
|
612 |
); |
updated document
|
613 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
614 | |
updated document
|
615 |
Other features. |
cleanup
|
616 | |
removed register_format()
|
617 |
# Default filter |
renamed default_query_filter...
|
618 |
$dbi->default_bind_filter('encode_utf8'); |
removed register_format()
|
619 |
$dbi->default_fetch_filter('decode_utf8'); |
cleanup
|
620 | |
621 |
# Get DBI object |
|
622 |
my $dbh = $dbi->dbh; |
|
623 | ||
624 |
Fetch row. |
|
625 | ||
removed register_format()
|
626 |
# Fetch |
627 |
while (my $row = $result->fetch) { |
|
628 |
# ... |
|
629 |
} |
|
630 |
|
|
631 |
# Fetch hash |
|
632 |
while (my $row = $result->fetch_hash) { |
|
633 |
|
|
634 |
} |
|
635 |
|
|
renamed update tag to update...
|
636 |
=head1 DESCRIPTIONS |
removed reconnect method
|
637 | |
renamed build_query to creat...
|
638 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
639 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
640 | |
renamed build_query to creat...
|
641 |
This module is not O/R mapper. O/R mapper is useful, |
642 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
643 |
which is almost another language. |
644 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
645 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
646 | |
renamed build_query to creat...
|
647 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
648 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
649 |
and suger methods, such as C<select()>, C<update()>, C<delete()>, C<select()> |
|
650 |
to execute SQL easily. |
|
removed reconnect method
|
651 | |
updated document
|
652 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
653 |
but de-facto standard, |
|
654 |
so all people learing database know it. |
|
renamed update tag to update...
|
655 |
If you already know SQL, |
656 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
657 | |
added DBIx::Custom::Guides
|
658 |
See L<DBIx::Custom::Guides> for more details. |
updated document
|
659 | |
update document
|
660 |
=head1 ATTRIBUTES |
packaging one directory
|
661 | |
cleanup
|
662 |
=head2 C<cache> |
packaging one directory
|
663 | |
cleanup
|
664 |
my $cache = $dbi->cache; |
665 |
$dbi = $dbi->cache(1); |
|
removed DESTROY method(not b...
|
666 | |
cleanup
|
667 |
Enable parsed L<DBIx::Custom::Query> object caching. |
668 |
Default to 1. |
|
packaging one directory
|
669 | |
cleanup
|
670 |
=head2 C<cache_method> |
packaging one directory
|
671 | |
cleanup
|
672 |
$dbi = $dbi->cache_method(\&cache_method); |
673 |
$cache_method = $dbi->cache_method |
|
674 | ||
675 |
Method to set and get caches. |
|
676 | ||
677 |
B<Example:> |
|
678 | ||
679 |
$dbi->cache_method( |
|
680 |
sub { |
|
681 |
my $self = shift; |
|
682 |
|
|
683 |
$self->{_cached} ||= {}; |
|
684 |
|
|
685 |
if (@_ > 1) { |
|
686 |
$self->{_cached}{$_[0]} = $_[1] |
|
687 |
} |
|
688 |
else { |
|
689 |
return $self->{_cached}{$_[0]} |
|
690 |
} |
|
691 |
} |
|
692 |
); |
|
removed DESTROY method(not b...
|
693 | |
removed DBIx::Custom commit ...
|
694 |
=head2 C<data_source> |
packaging one directory
|
695 | |
cleanup
|
696 |
my $data_source = $dbi->data_source; |
cleanup
|
697 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
698 | |
cleanup
|
699 |
Data source. |
700 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
701 | |
removed DBIx::Custom commit ...
|
702 |
=head2 C<dbh> |
packaging one directory
|
703 | |
cleanup
|
704 |
my $dbh = $dbi->dbh; |
705 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
706 | |
cleanup
|
707 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
708 | |
renamed default_query_filter...
|
709 |
=head2 C<default_bind_filter> |
packaging one directory
|
710 | |
cleanup
|
711 |
my $default_bind_filter = $dbi->default_bind_filter |
712 |
$dbi = $dbi->default_bind_filter('encode_utf8'); |
|
packaging one directory
|
713 | |
cleanup
|
714 |
Default filter when parameter binding is executed. |
packaging one directory
|
715 | |
removed DESTROY method(not b...
|
716 |
=head2 C<default_fetch_filter> |
bind_filter argument is chan...
|
717 | |
cleanup
|
718 |
my $default_fetch_filter = $dbi->default_fetch_filter; |
719 |
$dbi = $dbi->default_fetch_filter('decode_utf8'); |
|
bind_filter argument is chan...
|
720 | |
cleanup
|
721 |
Default filter when row is fetched. |
packaging one directory
|
722 | |
cleanup
|
723 |
=head2 C<filters> |
bind_filter argument is chan...
|
724 | |
cleanup
|
725 |
my $filters = $dbi->filters; |
726 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
727 | |
cleanup
|
728 |
Filter functions. |
729 |
"encode_utf8" and "decode_utf8" is registered by default. |
|
730 | ||
731 |
=head2 C<filter_check> |
|
732 | ||
733 |
my $filter_check = $dbi->filter_check; |
|
734 |
$dbi = $dbi->filter_check(0); |
|
735 | ||
736 |
Enable filter check. |
|
737 |
Default to 1. |
|
738 |
This check maybe damege performance. |
|
739 |
If you require performance, set C<filter_check> attribute to 0. |
|
740 | ||
741 |
=head2 C<password> |
|
742 | ||
743 |
my $password = $dbi->password; |
|
744 |
$dbi = $dbi->password('lkj&le`@s'); |
|
745 | ||
746 |
Password. |
|
747 |
C<connect()> method use this value to connect the database. |
|
update document
|
748 | |
renamed update tag to update...
|
749 |
=head2 C<query_builder> |
added commit method
|
750 | |
renamed update tag to update...
|
751 |
my $sql_class = $dbi->query_builder; |
752 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
753 | |
renamed update tag to update...
|
754 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
755 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
756 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
757 | |
cleanup
|
758 |
=head2 C<result_class> |
cleanup
|
759 | |
cleanup
|
760 |
my $result_class = $dbi->result_class; |
761 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
762 | |
cleanup
|
763 |
Result class for select statement. |
764 |
Default to L<DBIx::Custom::Result>. |
|
cleanup
|
765 | |
cleanup
|
766 |
=head2 C<user> |
cleanup
|
767 | |
cleanup
|
768 |
my $user = $dbi->user; |
769 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
770 | |
cleanup
|
771 |
User name. |
772 |
C<connect()> method use this value to connect the database. |
|
773 |
|
|
774 |
=head1 METHODS |
|
added commit method
|
775 | |
cleanup
|
776 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
777 |
and implements the following new ones. |
|
added check_filter attribute
|
778 | |
cleanup
|
779 |
=head2 begin_work |
added check_filter attribute
|
780 | |
cleanup
|
781 |
$dbi->begin_work; |
added check_filter attribute
|
782 | |
cleanup
|
783 |
Start transaction. |
784 |
This is same as L<DBI>'s C<begin_work>. |
|
added commit method
|
785 | |
cleanup
|
786 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
787 |
and implements the following new ones. |
|
added commit method
|
788 | |
cleanup
|
789 |
=head2 commit |
790 | ||
791 |
$dbi->commit; |
|
792 | ||
793 |
Commit transaction. |
|
794 |
This is same as L<DBI>'s C<commit>. |
|
795 | ||
removed DBIx::Custom commit ...
|
796 |
=head2 C<connect> |
packaging one directory
|
797 | |
cleanup
|
798 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
799 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
800 | |
cleanup
|
801 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
802 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
803 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
804 |
and C<PrintError> option is false by default. |
packaging one directory
|
805 | |
cleanup
|
806 |
=head2 C<create_query> |
807 |
|
|
808 |
my $query = $dbi->create_query( |
|
809 |
"select * from books where {= author} and {like title};" |
|
810 |
); |
|
update document
|
811 | |
cleanup
|
812 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
813 |
If you want to get high performance, |
|
814 |
use C<create_query()> method and execute it by C<execute()> method |
|
815 |
instead of suger methods. |
|
bind_filter argument is chan...
|
816 | |
cleanup
|
817 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
818 | |
cleanup
|
819 |
=head2 C<execute> |
packaging one directory
|
820 | |
cleanup
|
821 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
822 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
|
update document
|
823 | |
cleanup
|
824 |
Execute query or the source of SQL. |
825 |
Query is L<DBIx::Custom::Query> object. |
|
826 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
827 |
or the count of affected rows if insert, update, delete statement is executed. |
|
version 0.0901
|
828 | |
removed DESTROY method(not b...
|
829 |
B<Example:> |
update document
|
830 | |
cleanup
|
831 |
my $result = $dbi->execute( |
832 |
"select * from books where {= author} and {like title}", |
|
833 |
param => {author => 'Ken', title => '%Perl%'} |
|
834 |
); |
|
835 |
|
|
836 |
while (my $row = $result->fetch) { |
|
837 |
my $author = $row->[0]; |
|
838 |
my $title = $row->[1]; |
|
839 |
} |
|
packaging one directory
|
840 | |
removed DBIx::Custom commit ...
|
841 |
=head2 C<delete> |
packaging one directory
|
842 | |
cleanup
|
843 |
$dbi->delete(table => $table, |
844 |
where => \%where, |
|
845 |
append => $append, |
|
846 |
filter => \%filter); |
|
bind_filter argument is chan...
|
847 | |
renamed build_query to creat...
|
848 |
Execute delete statement. |
849 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
850 |
C<table> is a table name. |
|
851 |
C<where> is where clause. this must be hash reference. |
|
852 |
C<append> is a string added at the end of the SQL statement. |
|
853 |
C<filter> is filters when parameter binding is executed. |
|
cleanup
|
854 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
855 | |
removed DESTROY method(not b...
|
856 |
B<Example:> |
packaging one directory
|
857 | |
removed register_format()
|
858 |
$dbi->delete(table => 'books', |
859 |
where => {id => 5}, |
|
860 |
append => 'some statement', |
|
removed reconnect method
|
861 |
filter => {id => 'encode_utf8'}); |
version 0.0901
|
862 | |
removed DBIx::Custom commit ...
|
863 |
=head2 C<delete_all> |
packaging one directory
|
864 | |
cleanup
|
865 |
$dbi->delete_all(table => $table); |
packaging one directory
|
866 | |
renamed build_query to creat...
|
867 |
Execute delete statement to delete all rows. |
868 |
Arguments is same as C<delete> method, |
|
869 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
870 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
871 | |
removed DESTROY method(not b...
|
872 |
B<Example:> |
removed register_format()
|
873 |
|
removed reconnect method
|
874 |
$dbi->delete_all(table => 'books'); |
packaging one directory
|
875 | |
added helper method
|
876 |
=head2 C<(experimental) helper> |
877 | ||
878 |
$dbi->helper( |
|
879 |
update_or_insert => sub { |
|
880 |
my $self = shift; |
|
881 |
# do something |
|
882 |
}, |
|
883 |
find_or_create => sub { |
|
884 |
my $self = shift; |
|
885 |
# do something |
|
886 |
} |
|
887 |
); |
|
888 | ||
889 |
Register helper methods. These method is called from L<DBIx::Custom> object directory. |
|
890 | ||
891 |
$dbi->update_or_insert; |
|
892 |
$dbi->find_or_create; |
|
893 | ||
cleanup
|
894 |
=head2 C<insert> |
895 | ||
896 |
$dbi->insert(table => $table, |
|
897 |
param => \%param, |
|
898 |
append => $append, |
|
899 |
filter => \%filter); |
|
900 | ||
901 |
Execute insert statement. |
|
902 |
C<insert> method have C<table>, C<param>, C<append> |
|
903 |
and C<filter> arguments. |
|
904 |
C<table> is a table name. |
|
905 |
C<param> is the pairs of column name value. this must be hash reference. |
|
906 |
C<append> is a string added at the end of the SQL statement. |
|
907 |
C<filter> is filters when parameter binding is executed. |
|
908 |
This is overwrites C<default_bind_filter>. |
|
909 |
Return value of C<insert()> is the count of affected rows. |
|
910 | ||
911 |
B<Example:> |
|
912 | ||
913 |
$dbi->insert(table => 'books', |
|
914 |
param => {title => 'Perl', author => 'Taro'}, |
|
915 |
append => "some statement", |
|
916 |
filter => {title => 'encode_utf8'}) |
|
917 | ||
918 |
=head2 C<register_filter> |
|
919 | ||
920 |
$dbi->register_filter(%filters); |
|
921 |
$dbi->register_filter(\%filters); |
|
922 |
|
|
923 |
Register filter. Registered filters is available in the following attributes |
|
924 |
or arguments. |
|
925 | ||
926 |
=over 4 |
|
927 | ||
928 |
=item * |
|
929 | ||
930 |
C<default_bind_filter>, C<default_fetch_filter> |
|
931 | ||
932 |
=item * |
|
933 | ||
934 |
C<filter> argument of C<insert()>, C<update()>, |
|
935 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
|
936 |
methods |
|
937 | ||
938 |
=item * |
|
939 | ||
940 |
C<execute()> method |
|
941 | ||
942 |
=item * |
|
943 | ||
944 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
|
945 | ||
946 |
=item * |
|
947 | ||
948 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
|
949 | ||
950 |
=back |
|
951 | ||
952 |
B<Example:> |
|
953 | ||
954 |
$dbi->register_filter( |
|
955 |
encode_utf8 => sub { |
|
956 |
my $value = shift; |
|
957 |
|
|
958 |
require Encode; |
|
959 |
|
|
960 |
return Encode::encode('UTF-8', $value); |
|
961 |
}, |
|
962 |
decode_utf8 => sub { |
|
963 |
my $value = shift; |
|
964 |
|
|
965 |
require Encode; |
|
966 |
|
|
967 |
return Encode::decode('UTF-8', $value) |
|
968 |
} |
|
969 |
); |
|
970 | ||
971 |
=head2 rollback |
|
972 | ||
973 |
$dbi->rollback; |
|
974 | ||
975 |
Rollback transaction. |
|
976 |
This is same as L<DBI>'s C<rollback>. |
|
977 | ||
removed DBIx::Custom commit ...
|
978 |
=head2 C<select> |
packaging one directory
|
979 |
|
cleanup
|
980 |
my $result = $dbi->select(table => $table, |
981 |
column => [@column], |
|
982 |
where => \%where, |
|
983 |
append => $append, |
|
984 |
relation => \%relation, |
|
985 |
filter => \%filter); |
|
update document
|
986 | |
renamed build_query to creat...
|
987 |
Execute select statement. |
cleanup
|
988 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
989 |
C<relation> and C<filter> arguments. |
990 |
C<table> is a table name. |
|
cleanup
|
991 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
992 |
C<append> is a string added at the end of the SQL statement. |
993 |
C<filter> is filters when parameter binding is executed. |
|
update document
|
994 | |
removed DESTROY method(not b...
|
995 |
B<Example:> |
update document
|
996 | |
added commit method
|
997 |
# select * from books; |
cleanup
|
998 |
my $result = $dbi->select(table => 'books'); |
packaging one directory
|
999 |
|
renamed build_query to creat...
|
1000 |
# select * from books where title = ?; |
1001 |
my $result = $dbi->select(table => 'books', where => {title => 'Perl'}); |
|
update document
|
1002 |
|
renamed build_query to creat...
|
1003 |
# select title, author from books where id = ? for update; |
cleanup
|
1004 |
my $result = $dbi->select( |
removed register_format()
|
1005 |
table => 'books', |
removed reconnect method
|
1006 |
column => ['title', 'author'], |
removed register_format()
|
1007 |
where => {id => 1}, |
1008 |
appned => 'for update' |
|
update document
|
1009 |
); |
1010 |
|
|
renamed update tag to update...
|
1011 |
# select books.name as book_name from books, rental |
added commit method
|
1012 |
# where books.id = rental.book_id; |
1013 |
my $result = $dbi->select( |
|
removed reconnect method
|
1014 |
table => ['books', 'rental'], |
1015 |
column => ['books.name as book_name'] |
|
added commit method
|
1016 |
relation => {'books.id' => 'rental.book_id'} |
update document
|
1017 |
); |
1018 | ||
cleanup
|
1019 |
If you use more complex condition, |
1020 |
you can specify a array reference to C<where> argument. |
|
1021 | ||
1022 |
my $result = $dbi->select( |
|
1023 |
table => 'books', |
|
1024 |
column => ['title', 'author'], |
|
1025 |
where => ['{= title} or {like author}', |
|
1026 |
{title => '%Perl%', author => 'Ken'}] |
|
1027 |
); |
|
1028 | ||
1029 |
First element is a string. it contains tags, |
|
1030 |
such as "{= title} or {like author}". |
|
1031 |
Second element is paramters. |
|
1032 | ||
cleanup
|
1033 |
=head2 C<update> |
removed reconnect method
|
1034 | |
cleanup
|
1035 |
$dbi->update(table => $table, |
1036 |
param => \%params, |
|
1037 |
where => \%where, |
|
1038 |
append => $append, |
|
1039 |
filter => \%filter) |
|
removed reconnect method
|
1040 | |
cleanup
|
1041 |
Execute update statement. |
1042 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1043 |
and C<filter> arguments. |
|
1044 |
C<table> is a table name. |
|
1045 |
C<param> is column-value pairs. this must be hash reference. |
|
1046 |
C<where> is where clause. this must be hash reference. |
|
1047 |
C<append> is a string added at the end of the SQL statement. |
|
1048 |
C<filter> is filters when parameter binding is executed. |
|
1049 |
This is overwrites C<default_bind_filter>. |
|
1050 |
Return value of C<update()> is the count of affected rows. |
|
removed reconnect method
|
1051 | |
removed DBIx::Custom commit ...
|
1052 |
B<Example:> |
removed reconnect method
|
1053 | |
cleanup
|
1054 |
$dbi->update(table => 'books', |
1055 |
param => {title => 'Perl', author => 'Taro'}, |
|
1056 |
where => {id => 5}, |
|
1057 |
append => "some statement", |
|
1058 |
filter => {title => 'encode_utf8'}); |
|
renamed build_query to creat...
|
1059 | |
cleanup
|
1060 |
=head2 C<update_all> |
renamed build_query to creat...
|
1061 | |
cleanup
|
1062 |
$dbi->update_all(table => $table, |
1063 |
param => \%params, |
|
1064 |
filter => \%filter, |
|
1065 |
append => $append); |
|
renamed build_query to creat...
|
1066 | |
cleanup
|
1067 |
Execute update statement to update all rows. |
1068 |
Arguments is same as C<update> method, |
|
1069 |
except that C<update_all> don't have C<where> argument. |
|
1070 |
Return value of C<update_all()> is the count of affected rows. |
|
removed DBIx::Custom commit ...
|
1071 | |
1072 |
B<Example:> |
|
packaging one directory
|
1073 | |
cleanup
|
1074 |
$dbi->update_all(table => 'books', |
1075 |
param => {author => 'taro'}, |
|
1076 |
filter => {author => 'encode_utf8'}); |
|
removed reconnect method
|
1077 | |
DBIx::Custom is now stable
|
1078 |
=head1 STABILITY |
1079 | ||
1080 |
L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature. |
|
1081 | ||
removed DESTROY method(not b...
|
1082 |
=head1 BUGS |
1083 | ||
renamed build_query to creat...
|
1084 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1085 | |
1086 |
C<< <kimoto.yuki at gmail.com> >> |
|
1087 | ||
1088 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1089 | ||
removed reconnect method
|
1090 |
=head1 AUTHOR |
1091 | ||
1092 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1093 | |
packaging one directory
|
1094 |
=head1 COPYRIGHT & LICENSE |
1095 | ||
1096 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
1097 | ||
1098 |
This program is free software; you can redistribute it and/or modify it |
|
1099 |
under the same terms as Perl itself. |
|
1100 | ||
1101 |
=cut |
|
added cache_method attribute
|
1102 | |
1103 |