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