cleanup
|
1 |
package DBIx::Custom; |
2 | ||
fixed DBIx::Custom::QueryBui...
|
3 |
our $VERSION = '0.1615'; |
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 | |
catch up with Object::Simple...
|
18 |
__PACKAGE__->attr('dbh'); |
cleanup
|
19 |
__PACKAGE__->attr([qw/user password data_source/]); |
renamed default_query_filter...
|
20 |
__PACKAGE__->attr([qw/default_bind_filter default_fetch_filter/]); |
packaging one directory
|
21 | |
removed register_format()
|
22 |
__PACKAGE__->dual_attr('filters', default => sub { {} }, |
23 |
inherit => 'hash_copy'); |
|
24 |
__PACKAGE__->register_filter( |
|
update document
|
25 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
26 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
removed register_format()
|
27 |
); |
packaging one directory
|
28 | |
cleanup
|
29 |
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result'); |
renamed update tag to update...
|
30 |
__PACKAGE__->attr(query_builder => sub {DBIx::Custom::QueryBuilder->new}); |
added cache_method attribute
|
31 | |
add cache attribute
|
32 |
__PACKAGE__->attr(cache => 1); |
added cache_method attribute
|
33 |
__PACKAGE__->attr(cache_method => sub { |
34 |
sub { |
|
35 |
my $self = shift; |
|
36 |
|
|
37 |
$self->{_cached} ||= {}; |
|
38 |
|
|
39 |
if (@_ > 1) { |
|
40 |
$self->{_cached}{$_[0]} = $_[1] |
|
41 |
} |
|
42 |
else { |
|
43 |
return $self->{_cached}{$_[0]} |
|
44 |
} |
|
45 |
} |
|
46 |
}); |
|
removed register_format()
|
47 | |
added check_filter attribute
|
48 |
__PACKAGE__->attr(filter_check => 1); |
49 | ||
packaging one directory
|
50 |
sub connect { |
removed register_format()
|
51 |
my $proto = shift; |
52 |
|
|
53 |
# Create |
|
54 |
my $self = ref $proto ? $proto : $proto->new(@_); |
|
update document
|
55 |
|
56 |
# Information |
|
packaging one directory
|
57 |
my $data_source = $self->data_source; |
58 |
my $user = $self->user; |
|
59 |
my $password = $self->password; |
|
60 |
|
|
update document
|
61 |
# Connect |
select, insert, update, upda...
|
62 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
63 |
$data_source, |
64 |
$user, |
|
65 |
$password, |
|
66 |
{ |
|
67 |
RaiseError => 1, |
|
68 |
PrintError => 0, |
|
69 |
AutoCommit => 1, |
|
70 |
} |
|
71 |
)}; |
|
72 |
|
|
update document
|
73 |
# Connect error |
packaging one directory
|
74 |
croak $@ if $@; |
75 |
|
|
update document
|
76 |
# Database handle |
packaging one directory
|
77 |
$self->dbh($dbh); |
update document
|
78 |
|
packaging one directory
|
79 |
return $self; |
80 |
} |
|
81 | ||
removed DESTROY method(not b...
|
82 |
sub register_filter { |
83 |
my $invocant = shift; |
|
update document
|
84 |
|
changed argument of tag proc...
|
85 |
# Register filter |
removed DESTROY method(not b...
|
86 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
87 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
update document
|
88 |
|
removed DESTROY method(not b...
|
89 |
return $invocant; |
packaging one directory
|
90 |
} |
91 | ||
removed register_format()
|
92 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append filter/; |
cleanup insert
|
93 | |
packaging one directory
|
94 |
sub insert { |
select, insert, update, upda...
|
95 |
my ($self, %args) = @_; |
removed register_format()
|
96 | |
cleanup insert
|
97 |
# Check arguments |
select, insert, update, upda...
|
98 |
foreach my $name (keys %args) { |
add tests
|
99 |
croak qq{"$name" is invalid argument} |
cleanup insert
|
100 |
unless $VALID_INSERT_ARGS{$name}; |
101 |
} |
|
102 |
|
|
removed register_format()
|
103 |
# Arguments |
select, insert, update, upda...
|
104 |
my $table = $args{table} || ''; |
105 |
my $param = $args{param} || {}; |
|
106 |
my $append = $args{append} || ''; |
|
107 |
my $filter = $args{filter}; |
|
packaging one directory
|
108 |
|
109 |
# Insert keys |
|
removed register_format()
|
110 |
my @insert_keys = keys %$param; |
packaging one directory
|
111 |
|
112 |
# Templte for insert |
|
renamed update tag to update...
|
113 |
my $source = "insert into $table {insert_param " |
update document
|
114 |
. join(' ', @insert_keys) . '}'; |
renamed default_query_filter...
|
115 |
$source .= " $append" if $append; |
packaging one directory
|
116 |
|
117 |
# Execute query |
|
renamed default_query_filter...
|
118 |
my $ret_val = $self->execute($source, param => $param, |
removed register_format()
|
119 |
filter => $filter); |
packaging one directory
|
120 |
|
121 |
return $ret_val; |
|
122 |
} |
|
123 | ||
cleanup update and update_al...
|
124 |
our %VALID_UPDATE_ARGS |
removed register_format()
|
125 |
= map { $_ => 1 } qw/table param where append filter allow_update_all/; |
cleanup update and update_al...
|
126 | |
packaging one directory
|
127 |
sub update { |
select, insert, update, upda...
|
128 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
129 |
|
130 |
# Check arguments |
|
select, insert, update, upda...
|
131 |
foreach my $name (keys %args) { |
add tests
|
132 |
croak qq{"$name" is invalid argument} |
cleanup update and update_al...
|
133 |
unless $VALID_UPDATE_ARGS{$name}; |
134 |
} |
|
135 |
|
|
136 |
# Arguments |
|
select, insert, update, upda...
|
137 |
my $table = $args{table} || ''; |
138 |
my $param = $args{param} || {}; |
|
139 |
my $where = $args{where} || {}; |
|
add tests
|
140 |
my $append = $args{append} || ''; |
select, insert, update, upda...
|
141 |
my $filter = $args{filter}; |
142 |
my $allow_update_all = $args{allow_update_all}; |
|
packaging one directory
|
143 |
|
144 |
# Update keys |
|
removed register_format()
|
145 |
my @update_keys = keys %$param; |
packaging one directory
|
146 |
|
147 |
# Where keys |
|
removed register_format()
|
148 |
my @where_keys = keys %$where; |
packaging one directory
|
149 |
|
150 |
# Not exists where keys |
|
add tests
|
151 |
croak qq{"where" argument must be specified and } . |
152 |
qq{contains the pairs of column name and value} |
|
cleanup update and update_al...
|
153 |
if !@where_keys && !$allow_update_all; |
packaging one directory
|
154 |
|
155 |
# Update clause |
|
renamed update tag to update...
|
156 |
my $update_clause = '{update_param ' . join(' ', @update_keys) . '}'; |
packaging one directory
|
157 |
|
158 |
# Where clause |
|
159 |
my $where_clause = ''; |
|
simplify filtering system
|
160 |
my $new_where = {}; |
many change
|
161 |
|
packaging one directory
|
162 |
if (@where_keys) { |
163 |
$where_clause = 'where '; |
|
add tests
|
164 |
$where_clause .= "{= $_} and " for @where_keys; |
packaging one directory
|
165 |
$where_clause =~ s/ and $//; |
166 |
} |
|
167 |
|
|
add tests
|
168 |
# Source of SQL |
renamed default_query_filter...
|
169 |
my $source = "update $table $update_clause $where_clause"; |
add tests
|
170 |
$source .= " $append" if $append; |
packaging one directory
|
171 |
|
changed argument of tag proc...
|
172 |
# Rearrange parameters |
removed register_format()
|
173 |
foreach my $wkey (@where_keys) { |
simplify filtering system
|
174 |
|
removed register_format()
|
175 |
if (exists $param->{$wkey}) { |
176 |
$param->{$wkey} = [$param->{$wkey}] |
|
177 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
simplify filtering system
|
178 |
|
removed register_format()
|
179 |
push @{$param->{$wkey}}, $where->{$wkey}; |
simplify filtering system
|
180 |
} |
add tests
|
181 |
else { |
removed register_format()
|
182 |
$param->{$wkey} = $where->{$wkey}; |
add tests
|
183 |
} |
simplify filtering system
|
184 |
} |
packaging one directory
|
185 |
|
186 |
# Execute query |
|
renamed default_query_filter...
|
187 |
my $ret_val = $self->execute($source, param => $param, |
add tests
|
188 |
filter => $filter); |
packaging one directory
|
189 |
|
190 |
return $ret_val; |
|
191 |
} |
|
192 | ||
select, insert, update, upda...
|
193 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
packaging one directory
|
194 | |
refactoring delete and delet...
|
195 |
our %VALID_DELETE_ARGS |
removed register_format()
|
196 |
= map { $_ => 1 } qw/table where append filter allow_delete_all/; |
refactoring delete and delet...
|
197 | |
packaging one directory
|
198 |
sub delete { |
select, insert, update, upda...
|
199 |
my ($self, %args) = @_; |
refactoring delete and delet...
|
200 |
|
201 |
# Check arguments |
|
select, insert, update, upda...
|
202 |
foreach my $name (keys %args) { |
add tests
|
203 |
croak qq{"$name" is invalid argument} |
refactoring delete and delet...
|
204 |
unless $VALID_DELETE_ARGS{$name}; |
205 |
} |
|
206 |
|
|
207 |
# Arguments |
|
select, insert, update, upda...
|
208 |
my $table = $args{table} || ''; |
209 |
my $where = $args{where} || {}; |
|
add tests
|
210 |
my $append = $args{append}; |
select, insert, update, upda...
|
211 |
my $filter = $args{filter}; |
212 |
my $allow_delete_all = $args{allow_delete_all}; |
|
packaging one directory
|
213 |
|
214 |
# Where keys |
|
removed register_format()
|
215 |
my @where_keys = keys %$where; |
packaging one directory
|
216 |
|
217 |
# Not exists where keys |
|
add tests
|
218 |
croak qq{"where" argument must be specified and } . |
219 |
qq{contains the pairs of column name and value} |
|
refactoring delete and delet...
|
220 |
if !@where_keys && !$allow_delete_all; |
packaging one directory
|
221 |
|
222 |
# Where clause |
|
223 |
my $where_clause = ''; |
|
224 |
if (@where_keys) { |
|
225 |
$where_clause = 'where '; |
|
add tests
|
226 |
$where_clause .= "{= $_} and " for @where_keys; |
packaging one directory
|
227 |
$where_clause =~ s/ and $//; |
228 |
} |
|
229 |
|
|
add tests
|
230 |
# Source of SQL |
renamed default_query_filter...
|
231 |
my $source = "delete from $table $where_clause"; |
add tests
|
232 |
$source .= " $append" if $append; |
packaging one directory
|
233 |
|
234 |
# Execute query |
|
renamed default_query_filter...
|
235 |
my $ret_val = $self->execute($source, param => $where, |
add tests
|
236 |
filter => $filter); |
packaging one directory
|
237 |
|
238 |
return $ret_val; |
|
239 |
} |
|
240 | ||
select, insert, update, upda...
|
241 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
242 | |
refactoring select
|
243 |
our %VALID_SELECT_ARGS |
added commit method
|
244 |
= map { $_ => 1 } qw/table column where append relation filter param/; |
refactoring select
|
245 | |
packaging one directory
|
246 |
sub select { |
select, insert, update, upda...
|
247 |
my ($self, %args) = @_; |
packaging one directory
|
248 |
|
refactoring select
|
249 |
# Check arguments |
select, insert, update, upda...
|
250 |
foreach my $name (keys %args) { |
add tests
|
251 |
croak qq{"$name" is invalid argument} |
refactoring select
|
252 |
unless $VALID_SELECT_ARGS{$name}; |
253 |
} |
|
packaging one directory
|
254 |
|
refactoring select
|
255 |
# Arguments |
select, insert, update, upda...
|
256 |
my $tables = $args{table} || []; |
removed register_format()
|
257 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
select, insert, update, upda...
|
258 |
my $columns = $args{column} || []; |
update document
|
259 |
my $where = $args{where}; |
select, insert, update, upda...
|
260 |
my $relation = $args{relation}; |
261 |
my $append = $args{append}; |
|
262 |
my $filter = $args{filter}; |
|
packaging one directory
|
263 |
|
add tests
|
264 |
# Source of SQL |
renamed default_query_filter...
|
265 |
my $source = 'select '; |
packaging one directory
|
266 |
|
added commit method
|
267 |
# Column clause |
packaging one directory
|
268 |
if (@$columns) { |
269 |
foreach my $column (@$columns) { |
|
renamed default_query_filter...
|
270 |
$source .= "$column, "; |
packaging one directory
|
271 |
} |
renamed default_query_filter...
|
272 |
$source =~ s/, $/ /; |
packaging one directory
|
273 |
} |
274 |
else { |
|
renamed default_query_filter...
|
275 |
$source .= '* '; |
packaging one directory
|
276 |
} |
277 |
|
|
added commit method
|
278 |
# Table |
renamed default_query_filter...
|
279 |
$source .= 'from '; |
packaging one directory
|
280 |
foreach my $table (@$tables) { |
renamed default_query_filter...
|
281 |
$source .= "$table, "; |
packaging one directory
|
282 |
} |
renamed default_query_filter...
|
283 |
$source =~ s/, $/ /; |
packaging one directory
|
284 |
|
added commit method
|
285 |
# Where clause |
update document
|
286 |
my $param; |
287 |
if (ref $where eq 'HASH') { |
|
288 |
$param = $where; |
|
289 |
$source .= 'where ('; |
|
290 |
foreach my $where_key (keys %$where) { |
|
renamed default_query_filter...
|
291 |
$source .= "{= $where_key} and "; |
packaging one directory
|
292 |
} |
update document
|
293 |
$source =~ s/ and $//; |
294 |
$source .= ') '; |
|
295 |
} |
|
296 |
elsif (ref $where eq 'ARRAY') { |
|
297 |
my$where_str = $where->[0] || ''; |
|
298 |
$param = $where->[1]; |
|
299 |
|
|
300 |
$source .= "where ($where_str) "; |
|
packaging one directory
|
301 |
} |
302 |
|
|
added commit method
|
303 |
# Relation |
304 |
if ($relation) { |
|
update document
|
305 |
$source .= $where ? "and " : "where "; |
added commit method
|
306 |
foreach my $rkey (keys %$relation) { |
renamed default_query_filter...
|
307 |
$source .= "$rkey = " . $relation->{$rkey} . " and "; |
packaging one directory
|
308 |
} |
309 |
} |
|
renamed default_query_filter...
|
310 |
$source =~ s/ and $//; |
added commit method
|
311 |
|
312 |
# Append some statement |
|
renamed default_query_filter...
|
313 |
$source .= " $append" if $append; |
packaging one directory
|
314 |
|
315 |
# Execute query |
|
update document
|
316 |
my $result = $self->execute($source, param => $param, |
317 |
filter => $filter); |
|
packaging one directory
|
318 |
|
319 |
return $result; |
|
320 |
} |
|
321 | ||
renamed build_query to creat...
|
322 |
sub create_query { |
renamed default_query_filter...
|
323 |
my ($self, $source) = @_; |
removed register_format()
|
324 |
|
renamed default_query_filter...
|
325 |
# Cache |
added cache_method attribute
|
326 |
my $cache = $self->cache; |
version 0.0901
|
327 |
|
removed reconnect method
|
328 |
# Create query |
329 |
my $query; |
|
added cache_method attribute
|
330 |
if ($cache) { |
331 |
|
|
renamed default_query_filter...
|
332 |
# Get query |
333 |
my $q = $self->cache_method->($self, $source); |
|
added cache_method attribute
|
334 |
|
335 |
# Create query |
|
336 |
$query = DBIx::Custom::Query->new($q) if $q; |
|
removed reconnect method
|
337 |
} |
added cache_method attribute
|
338 |
|
339 |
unless ($query) { |
|
renamed default_query_filter...
|
340 | |
341 |
# Create SQL object |
|
renamed update tag to update...
|
342 |
my $builder = $self->query_builder; |
added cache_method attribute
|
343 |
|
344 |
# Create query |
|
fixed Carp trast relationshi...
|
345 |
$query = $builder->build_query($source); |
346 | ||
added cache_method attribute
|
347 |
# Cache query |
renamed default_query_filter...
|
348 |
$self->cache_method->($self, $source, |
added cache_method attribute
|
349 |
{sql => $query->sql, |
350 |
columns => $query->columns}) |
|
351 |
if $cache; |
|
removed reconnect method
|
352 |
} |
version 0.0901
|
353 |
|
removed reconnect method
|
354 |
# Prepare statement handle |
add tests
|
355 |
my $sth; |
356 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
357 |
if ($@) { |
|
358 |
my $error = $@; |
|
359 |
$error =~ s/\s+at\s+.*?\s+line\s+\d+.*$//s; |
|
360 |
croak qq{$error. SQL: "$query->{sql}"}; |
|
361 |
} |
|
renamed fetch_rows to fetch_...
|
362 |
|
removed reconnect method
|
363 |
# Set statement handle |
364 |
$query->sth($sth); |
|
365 |
|
|
366 |
return $query; |
|
367 |
} |
|
368 | ||
369 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter/; |
|
370 | ||
371 |
sub execute{ |
|
select, insert, update, upda...
|
372 |
my ($self, $query, %args) = @_; |
removed reconnect method
|
373 |
|
374 |
# Check arguments |
|
select, insert, update, upda...
|
375 |
foreach my $name (keys %args) { |
add tests
|
376 |
croak qq{"$name" is invalid argument} |
removed reconnect method
|
377 |
unless $VALID_EXECUTE_ARGS{$name}; |
378 |
} |
|
379 |
|
|
select, insert, update, upda...
|
380 |
my $params = $args{param} || {}; |
removed reconnect method
|
381 |
|
add tests
|
382 |
# First argument is the soruce of SQL |
renamed build_query to creat...
|
383 |
$query = $self->create_query($query) |
changed argument of tag proc...
|
384 |
unless ref $query; |
removed reconnect method
|
385 |
|
select, insert, update, upda...
|
386 |
my $filter = $args{filter} || $query->filter || {}; |
removed reconnect method
|
387 |
|
388 |
# Create bind value |
|
389 |
my $bind_values = $self->_build_bind_values($query, $params, $filter); |
|
390 |
|
|
391 |
# Execute |
|
392 |
my $sth = $query->sth; |
|
add tests
|
393 |
my $affected; |
394 |
eval {$affected = $sth->execute(@$bind_values)}; |
|
395 |
if ($@) { |
|
396 |
my $error = $@; |
|
397 |
$error =~ s/\s+at\s+.*?\s+line\s+\d+.*$//s; |
|
398 |
croak $error; |
|
399 |
} |
|
removed reconnect method
|
400 |
|
401 |
# Return resultset if select statement is executed |
|
402 |
if ($sth->{NUM_OF_FIELDS}) { |
|
403 |
|
|
404 |
# Create result |
|
renamed default_query_filter...
|
405 |
my $result = $self->result_class->new( |
406 |
sth => $sth, |
|
407 |
default_filter => $self->default_fetch_filter, |
|
added check_filter attribute
|
408 |
filters => $self->filters, |
409 |
filter_check => $self->filter_check |
|
renamed default_query_filter...
|
410 |
); |
411 | ||
removed reconnect method
|
412 |
return $result; |
413 |
} |
|
414 |
return $affected; |
|
415 |
} |
|
416 | ||
417 |
sub _build_bind_values { |
|
418 |
my ($self, $query, $params, $filter) = @_; |
|
419 |
|
|
420 |
# binding values |
|
421 |
my @bind_values; |
|
add tests
|
422 | |
423 |
# Filter |
|
424 |
$filter ||= {}; |
|
425 |
|
|
426 |
# Parameter |
|
427 |
$params ||= {}; |
|
428 |
|
|
429 |
# Check filter |
|
430 |
$self->_check_filter($self->filters, $filter, |
|
431 |
$self->default_bind_filter, $params) |
|
432 |
if $self->filter_check; |
|
removed reconnect method
|
433 |
|
434 |
# Build bind values |
|
435 |
my $count = {}; |
|
436 |
foreach my $column (@{$query->columns}) { |
|
437 |
|
|
438 |
# Value |
|
439 |
my $value = ref $params->{$column} eq 'ARRAY' |
|
440 |
? $params->{$column}->[$count->{$column} || 0] |
|
441 |
: $params->{$column}; |
|
442 |
|
|
add tests
|
443 |
# Filtering |
renamed default_query_filter...
|
444 |
my $fname = $filter->{$column} || $self->default_bind_filter || ''; |
add tests
|
445 |
my $filter_func = $fname ? $self->filters->{$fname} : undef; |
removed reconnect method
|
446 |
push @bind_values, $filter_func |
447 |
? $filter_func->($value) |
|
448 |
: $value; |
|
449 |
|
|
450 |
# Count up |
|
451 |
$count->{$column}++; |
|
452 |
} |
|
453 |
|
|
454 |
return \@bind_values; |
|
455 |
} |
|
456 | ||
add tests
|
457 |
sub _check_filter { |
458 |
my ($self, $filters, $filter, $default_filter, $params) = @_; |
|
459 |
|
|
460 |
# Filter name not exists |
|
461 |
foreach my $fname (values %$filter) { |
|
462 |
croak qq{Bind filter "$fname" is not registered} |
|
463 |
unless exists $filters->{$fname}; |
|
464 |
} |
|
465 |
|
|
466 |
# Default filter name not exists |
|
467 |
croak qq{Default bind filter "$default_filter" is not registered} |
|
468 |
if $default_filter && ! exists $filters->{$default_filter}; |
|
469 |
|
|
470 |
# Column name not exists |
|
471 |
foreach my $column (keys %$filter) { |
|
472 |
|
|
473 |
croak qq{Column name "$column" in bind filter is not found in paramters} |
|
474 |
unless exists $params->{$column}; |
|
475 |
} |
|
476 |
} |
|
477 | ||
added register_method() meth...
|
478 |
__PACKAGE__->attr('methods' => sub { {} }); |
479 | ||
480 |
sub register_method { |
|
481 |
my $self = shift; |
|
482 |
|
|
483 |
# Register method |
|
484 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
485 |
$self->methods({%{$self->methods}, %$methods}); |
|
486 |
|
|
487 |
return $self; |
|
488 |
} |
|
489 | ||
490 |
our $AUTOLOAD; |
|
491 |
sub AUTOLOAD { |
|
492 |
my $self = shift; |
|
493 |
my $method = $AUTOLOAD; |
|
494 |
$method =~ s/.*:://; |
|
495 |
|
|
496 |
return if $method eq 'DESTROY'; |
|
497 |
|
|
498 |
croak qq{Method "$method" is not registered"} |
|
499 |
unless $self->methods->{$method}; |
|
500 |
|
|
501 |
return $self->methods->{$method}->($self, @_); |
|
502 |
} |
|
503 | ||
fixed DBIx::Custom::QueryBui...
|
504 |
1; |
505 | ||
removed reconnect method
|
506 |
=head1 NAME |
507 | ||
renamed build_query to creat...
|
508 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
509 | |
510 |
=head1 STABILITY |
|
511 | ||
updated document
|
512 |
B<This module is not stable>. |
renamed build_query to creat...
|
513 |
Method name and implementations will be changed for a while. |
removed reconnect method
|
514 | |
515 |
=head1 SYNOPSYS |
|
cleanup
|
516 | |
renamed build_query to creat...
|
517 |
Connect to the database. |
518 |
|
|
519 |
use DBIx::Custom; |
|
renamed update tag to update...
|
520 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
removed reconnect method
|
521 |
user => 'ken', password => '!LFKD%$&'); |
cleanup
|
522 | |
renamed build_query to creat...
|
523 |
Insert, update, and delete |
cleanup
|
524 | |
removed reconnect method
|
525 |
# Insert |
526 |
$dbi->insert(table => 'books', |
|
renamed update tag to update...
|
527 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
528 |
filter => {title => 'encode_utf8'}); |
529 |
|
|
530 |
# Update |
|
531 |
$dbi->update(table => 'books', |
|
renamed update tag to update...
|
532 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
533 |
where => {id => 5}, |
534 |
filter => {title => 'encode_utf8'}); |
|
535 |
|
|
536 |
# Update all |
|
537 |
$dbi->update_all(table => 'books', |
|
renamed update tag to update...
|
538 |
param => {title => 'Perl'}, |
removed reconnect method
|
539 |
filter => {title => 'encode_utf8'}); |
540 |
|
|
541 |
# Delete |
|
542 |
$dbi->delete(table => 'books', |
|
543 |
where => {author => 'Ken'}, |
|
544 |
filter => {title => 'encode_utf8'}); |
|
545 |
|
|
546 |
# Delete all |
|
547 |
$dbi->delete_all(table => 'books'); |
|
cleanup
|
548 | |
renamed build_query to creat...
|
549 |
Select |
cleanup
|
550 | |
removed reconnect method
|
551 |
# Select |
552 |
my $result = $dbi->select(table => 'books'); |
|
renamed fetch_rows to fetch_...
|
553 |
|
renamed build_query to creat...
|
554 |
# Select, more complex |
renamed fetch_rows to fetch_...
|
555 |
my $result = $dbi->select( |
update document
|
556 |
table => 'books', |
557 |
column => [qw/author title/], |
|
558 |
where => {author => 'Ken'}, |
|
updated document
|
559 |
append => 'order by id limit 5', |
renamed build_query to creat...
|
560 |
filter => {title => 'encode_utf8'} |
renamed fetch_rows to fetch_...
|
561 |
); |
added commit method
|
562 |
|
renamed build_query to creat...
|
563 |
# Select, join table |
added commit method
|
564 |
my $result = $dbi->select( |
renamed build_query to creat...
|
565 |
table => ['books', 'rental'], |
566 |
column => ['books.name as book_name'] |
|
added commit method
|
567 |
relation => {'books.id' => 'rental.book_id'} |
568 |
); |
|
updated document
|
569 |
|
570 |
# Select, more flexible where |
|
571 |
my $result = $dbi->select( |
|
572 |
table => 'books', |
|
573 |
where => ['{= author} and {like title}', |
|
574 |
{author => 'Ken', title => '%Perl%'}] |
|
575 |
); |
|
cleanup
|
576 | |
renamed build_query to creat...
|
577 |
Execute SQL |
cleanup
|
578 | |
renamed build_query to creat...
|
579 |
# Execute SQL |
removed register_format()
|
580 |
$dbi->execute("select title from books"); |
581 |
|
|
renamed build_query to creat...
|
582 |
# Execute SQL with hash binding and filtering |
updated document
|
583 |
$dbi->execute("select id from books where {= author} and {like title}", |
removed register_format()
|
584 |
param => {author => 'ken', title => '%Perl%'}, |
renamed build_query to creat...
|
585 |
filter => {title => 'encode_utf8'}); |
removed reconnect method
|
586 | |
587 |
# Create query and execute it |
|
renamed build_query to creat...
|
588 |
my $query = $dbi->create_query( |
updated document
|
589 |
"select id from books where {= author} and {like title}" |
removed reconnect method
|
590 |
); |
updated document
|
591 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
592 | |
updated document
|
593 |
Other features. |
cleanup
|
594 | |
removed register_format()
|
595 |
# Default filter |
renamed default_query_filter...
|
596 |
$dbi->default_bind_filter('encode_utf8'); |
removed register_format()
|
597 |
$dbi->default_fetch_filter('decode_utf8'); |
cleanup
|
598 | |
599 |
# Get DBI object |
|
600 |
my $dbh = $dbi->dbh; |
|
601 | ||
602 |
Fetch row. |
|
603 | ||
removed register_format()
|
604 |
# Fetch |
605 |
while (my $row = $result->fetch) { |
|
606 |
# ... |
|
607 |
} |
|
608 |
|
|
609 |
# Fetch hash |
|
610 |
while (my $row = $result->fetch_hash) { |
|
611 |
|
|
612 |
} |
|
613 |
|
|
renamed update tag to update...
|
614 |
=head1 DESCRIPTIONS |
removed reconnect method
|
615 | |
renamed build_query to creat...
|
616 |
=head2 1. Features |
removed reconnect method
|
617 | |
renamed build_query to creat...
|
618 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
619 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
620 | |
renamed build_query to creat...
|
621 |
This module is not O/R mapper. O/R mapper is useful, |
622 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
623 |
which is almost another language. |
624 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
625 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
626 | |
renamed build_query to creat...
|
627 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
628 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
629 |
and suger methods, such as C<select()>, C<update()>, C<delete()>, C<select()> |
|
630 |
to execute SQL easily. |
|
removed reconnect method
|
631 | |
updated document
|
632 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
633 |
but de-facto standard, |
|
634 |
so all people learing database know it. |
|
renamed update tag to update...
|
635 |
If you already know SQL, |
636 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
637 | |
renamed update tag to update...
|
638 |
=head2 2. Connect to the database |
removed reconnect method
|
639 | |
renamed build_query to creat...
|
640 |
C<connect()> method create a new L<DBIx::Custom> |
641 |
object and connect to the database. |
|
removed reconnect method
|
642 | |
renamed build_query to creat...
|
643 |
use DBIx::Custom; |
renamed update tag to update...
|
644 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
renamed build_query to creat...
|
645 |
user => 'ken', password => '!LFKD%$&'); |
646 | ||
renamed update tag to update...
|
647 |
If database is SQLite, use L<DBIx::Custom::SQLite> instead. |
648 |
you connect database easily. |
|
update document
|
649 | |
650 |
use DBIx::Custom::SQLite; |
|
renamed update tag to update...
|
651 |
my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
update document
|
652 |
|
cleanup
|
653 |
If database is MySQL, use L<DBIx::Custom::MySQL>. |
update document
|
654 | |
655 |
use DBIx::Custom::MySQL; |
|
renamed update tag to update...
|
656 |
my $dbi = DBIx::Custom::MySQL->connect( |
657 |
database => 'dbname', |
|
658 |
user => 'ken', |
|
659 |
password => '!LFKD%$&' |
|
660 |
); |
|
update document
|
661 | |
renamed update tag to update...
|
662 |
=head2 3. Suger methods |
renamed build_query to creat...
|
663 | |
664 |
L<DBIx::Custom> has suger methods, such as C<insert()>, C<update()>, |
|
renamed update tag to update...
|
665 |
C<delete()> or C<select()>. If you want to do small works, |
updated document
|
666 |
You don't have to create SQL statements. |
renamed build_query to creat...
|
667 | |
update document
|
668 |
=head3 insert() |
669 | ||
updated document
|
670 |
Execute insert statement. |
671 | ||
update document
|
672 |
$dbi->insert(table => 'books', |
renamed update tag to update...
|
673 |
param => {title => 'Perl', author => 'Ken'}); |
update document
|
674 | |
675 |
The following SQL is executed. |
|
676 | ||
updated document
|
677 |
insert into (title, author) values (?, ?); |
update document
|
678 | |
renamed update tag to update...
|
679 |
The values of C<title> and C<author> is embedded into the placeholders. |
update document
|
680 | |
renamed update tag to update...
|
681 |
C<append> and C<filter> argument can be specified. |
682 |
See also "METHODS" section. |
|
update document
|
683 | |
684 |
=head3 update() |
|
685 | ||
updated document
|
686 |
Execute update statement. |
687 | ||
update document
|
688 |
$dbi->update(table => 'books', |
renamed update tag to update...
|
689 |
param => {title => 'Perl', author => 'Ken'}, |
update document
|
690 |
where => {id => 5}); |
691 | ||
692 |
The following SQL is executed. |
|
693 | ||
694 |
update books set title = ?, author = ?; |
|
695 | ||
renamed update tag to update...
|
696 |
The values of C<title> and C<author> is embedded into the placeholders. |
update document
|
697 | |
renamed update tag to update...
|
698 |
C<append> and C<filter> argument can be specified. |
699 |
See also "METHOD" section. |
|
update document
|
700 | |
renamed update tag to update...
|
701 |
If you want to update all rows, use C<update_all()> method. |
update document
|
702 | |
703 |
=head3 delete() |
|
704 | ||
updated document
|
705 |
Execute delete statement. |
706 | ||
update document
|
707 |
$dbi->delete(table => 'books', |
708 |
where => {author => 'Ken'}); |
|
709 | ||
710 |
The following SQL is executed. |
|
711 | ||
712 |
delete from books where id = ?; |
|
713 | ||
updated document
|
714 |
The value of C<id> is embedded into the placehodler. |
update document
|
715 | |
renamed update tag to update...
|
716 |
C<append> and C<filter> argument can be specified. |
717 |
see also "METHODS" section. |
|
update document
|
718 | |
renamed update tag to update...
|
719 |
If you want to delete all rows, use C<delete_all()> method. |
update document
|
720 | |
721 |
=head3 select() |
|
722 | ||
updated document
|
723 |
Execute select statement, only C<table> argument specified : |
update document
|
724 | |
725 |
my $result = $dbi->select(table => 'books'); |
|
726 | ||
727 |
The following SQL is executed. |
|
728 | ||
729 |
select * from books; |
|
730 | ||
731 |
the result of C<select()> method is L<DBIx::Custom::Result> object. |
|
renamed update tag to update...
|
732 |
You can fetch a row by C<fetch()> method. |
update document
|
733 | |
734 |
while (my $row = $result->fetch) { |
|
735 |
my $title = $row->[0]; |
|
736 |
my $author = $row->[1]; |
|
737 |
} |
|
738 | ||
739 |
L<DBIx::Custom::Result> has various methods to fetch row. |
|
renamed update tag to update...
|
740 |
See "4. Fetch row". |
update document
|
741 | |
renamed update tag to update...
|
742 |
C<column> and C<where> arguments specified. |
update document
|
743 | |
744 |
my $result = $dbi->select( |
|
745 |
table => 'books', |
|
746 |
column => [qw/author title/], |
|
renamed update tag to update...
|
747 |
where => {author => 'Ken'} |
748 |
); |
|
update document
|
749 | |
750 |
The following SQL is executed. |
|
751 | ||
752 |
select author, title from books where author = ?; |
|
753 | ||
renamed update tag to update...
|
754 |
the value of C<author> is embdded into the placeholder. |
update document
|
755 | |
updated document
|
756 |
If you want to join tables, specify C<relation> argument. |
update document
|
757 | |
758 |
my $result = $dbi->select( |
|
759 |
table => ['books', 'rental'], |
|
760 |
column => ['books.name as book_name'] |
|
761 |
relation => {'books.id' => 'rental.book_id'} |
|
762 |
); |
|
763 | ||
764 |
The following SQL is executed. |
|
765 | ||
renamed update tag to update...
|
766 |
select books.name as book_name from books, rental |
update document
|
767 |
where books.id = rental.book_id; |
768 | ||
renamed update tag to update...
|
769 |
If you want to add some string to the end of SQL statement, |
770 |
use C<append> argument. |
|
update document
|
771 | |
772 |
my $result = $dbi->select( |
|
773 |
table => 'books', |
|
774 |
where => {author => 'Ken'}, |
|
775 |
append => 'order by price limit 5', |
|
776 |
); |
|
777 | ||
778 |
The following SQL is executed. |
|
779 | ||
780 |
select * books where author = ? order by price limit 5; |
|
781 | ||
renamed update tag to update...
|
782 |
C<filter> argument can be specified. |
783 |
see also "METHODS" section. |
|
update document
|
784 | |
renamed update tag to update...
|
785 |
=head2 4. Fetch row |
update document
|
786 | |
updated document
|
787 |
C<select()> method return L<DBIx::Custom::Result> object. |
788 |
You can fetch row by various methods. |
|
renamed update tag to update...
|
789 |
Note that in this section, array means array reference, |
790 |
and hash meanse hash reference. |
|
update document
|
791 | |
792 |
Fetch row into array. |
|
793 |
|
|
794 |
while (my $row = $result->fetch) { |
|
795 |
my $author = $row->[0]; |
|
796 |
my $title = $row->[1]; |
|
797 |
|
|
798 |
} |
|
799 | ||
800 |
Fetch only a first row into array. |
|
801 | ||
802 |
my $row = $result->fetch_first; |
|
803 | ||
804 |
Fetch multiple rows into array of array. |
|
805 | ||
806 |
while (my $rows = $result->fetch_multi(5)) { |
|
807 |
my $first_author = $rows->[0][0]; |
|
808 |
my $first_title = $rows->[0][1]; |
|
809 |
my $second_author = $rows->[1][0]; |
|
810 |
my $second_value = $rows->[1][1]; |
|
811 |
|
|
812 |
} |
|
813 |
|
|
814 |
Fetch all rows into array of array. |
|
815 | ||
816 |
my $rows = $result->fetch_all; |
|
817 | ||
818 |
Fetch row into hash. |
|
819 | ||
820 |
# Fetch a row into hash |
|
821 |
while (my $row = $result->fetch_hash) { |
|
822 |
my $title = $row->{title}; |
|
823 |
my $author = $row->{author}; |
|
824 |
|
|
825 |
} |
|
826 | ||
827 |
Fetch only a first row into hash |
|
828 | ||
829 |
my $row = $result->fetch_hash_first; |
|
830 |
|
|
831 |
Fetch multiple rows into array of hash |
|
832 | ||
833 |
while (my $rows = $result->fetch_hash_multi(5)) { |
|
834 |
my $first_title = $rows->[0]{title}; |
|
835 |
my $first_author = $rows->[0]{author}; |
|
836 |
my $second_title = $rows->[1]{title}; |
|
837 |
my $second_author = $rows->[1]{author}; |
|
838 |
|
|
839 |
} |
|
840 |
|
|
841 |
Fetch all rows into array of hash |
|
842 | ||
843 |
my $rows = $result->fetch_hash_all; |
|
removed DESTROY method(not b...
|
844 | |
cleanup
|
845 |
If you want to access statement handle of L<DBI>, use C<sth> attribute. |
removed DESTROY method(not b...
|
846 | |
update document
|
847 |
my $sth = $result->sth; |
removed DESTROY method(not b...
|
848 | |
renamed update tag to update...
|
849 |
=head2 5. Hash parameter binding |
removed reconnect method
|
850 | |
update document
|
851 |
L<DBIx::Custom> provides hash parameter binding. |
852 | ||
renamed update tag to update...
|
853 |
At frist, I show normal parameter binding. |
update document
|
854 | |
855 |
use DBI; |
|
856 |
my $dbh = DBI->connect(...); |
|
857 |
my $sth = $dbh->prepare( |
|
858 |
"select * from books where author = ? and title like ?;" |
|
859 |
); |
|
860 |
$sth->execute('Ken', '%Perl%'); |
|
861 | ||
updated document
|
862 |
This is very good way because database system can enable SQL caching, |
renamed update tag to update...
|
863 |
and parameter is quoted automatically. this is secure. |
update document
|
864 | |
updated document
|
865 |
L<DBIx::Custom> hash parameter binding system improve |
renamed update tag to update...
|
866 |
normal parameter binding to use hash parameter. |
update document
|
867 | |
868 |
my $result = $dbi->execute( |
|
869 |
"select * from books where {= author} and {like title};" |
|
870 |
param => {author => 'Ken', title => '%Perl%'} |
|
871 |
); |
|
872 | ||
873 |
This is same as the normal way, execpt that the parameter is hash. |
|
renamed update tag to update...
|
874 |
{= author} and {like title} is called C<tag>. |
875 |
tag is expand to placeholder string internally. |
|
update document
|
876 | |
877 |
select * from books where {= author} and {like title} |
|
878 |
-> select * from books where author = ? and title like ?; |
|
879 | ||
updated document
|
880 |
The following tags is available. |
881 | ||
882 |
[TAG] [REPLACED] |
|
883 |
{? NAME} -> ? |
|
884 |
{= NAME} -> NAME = ? |
|
885 |
{<> NAME} -> NAME <> ? |
|
886 |
|
|
887 |
{< NAME} -> NAME < ? |
|
888 |
{> NAME} -> NAME > ? |
|
889 |
{>= NAME} -> NAME >= ? |
|
890 |
{<= NAME} -> NAME <= ? |
|
891 |
|
|
892 |
{like NAME} -> NAME like ? |
|
893 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
894 |
|
|
renamed update tag to update...
|
895 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
896 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
updated document
|
897 | |
898 |
See also L<DBIx::Custom::QueryBuilder>. |
|
899 | ||
removed DBIx::Custom::Query ...
|
900 |
C<{> and C<}> is reserved. If you use these charactors, |
901 |
you must escape them using '\'. Note that '\' is |
|
902 |
already perl escaped charactor, so you must write '\\'. |
|
updated document
|
903 | |
removed DBIx::Custom::Query ...
|
904 |
'select * from books \\{ something statement \\}' |
update document
|
905 | |
renamed update tag to update...
|
906 |
=head2 6. Filtering |
update document
|
907 | |
908 |
Usually, Perl string is kept as internal string. |
|
909 |
If you want to save the string to database, You must encode the string. |
|
910 |
Filtering system help you to convert a data to another data |
|
911 |
when you save to the data and get the data form database. |
|
912 | ||
updated document
|
913 |
If you want to register filter, use C<register_filter()> method. |
update document
|
914 | |
915 |
$dbi->register_filter( |
|
916 |
to_upper_case => sub { |
|
917 |
my $value = shift; |
|
918 |
return uc $value; |
|
919 |
} |
|
920 |
); |
|
921 | ||
922 |
C<encode_utf8> and C<decode_utf8> filter is registerd by default. |
|
923 | ||
924 |
You can specify these filters to C<filter> argument of C<execute()> method. |
|
925 | ||
926 |
my $result = $dbi->execute( |
|
927 |
"select * from books where {= author} and {like title};" |
|
updated document
|
928 |
param => {author => 'Ken', title => '%Perl%'}, |
update document
|
929 |
filter => {author => 'to_upper_case, title => 'encode_utf8'} |
930 |
); |
|
931 | ||
renamed update tag to update...
|
932 |
C<filter> argument can be specified to suger methods, such as |
cleanup
|
933 |
C<insert()>, C<update()>, C<update_all()>, |
renamed update tag to update...
|
934 |
C<delete()>, C<delete_all()>, C<select()>. |
update document
|
935 | |
renamed update tag to update...
|
936 |
# insert(), having filter argument |
update document
|
937 |
$dbi->insert(table => 'books', |
renamed update tag to update...
|
938 |
param => {title => 'Perl', author => 'Ken'}, |
update document
|
939 |
filter => {title => 'encode_utf8'}); |
renamed update tag to update...
|
940 |
|
941 |
# select(), having filter argument |
|
update document
|
942 |
my $result = $dbi->select( |
943 |
table => 'books', |
|
944 |
column => [qw/author title/], |
|
945 |
where => {author => 'Ken'}, |
|
946 |
append => 'order by id limit 1', |
|
947 |
filter => {title => 'encode_utf8'} |
|
948 |
); |
|
949 | ||
updated document
|
950 |
Filter works each parmeter, but you prepare default filter for all parameters. |
update document
|
951 | |
952 |
$dbi->default_bind_filter('encode_utf8'); |
|
953 | ||
renamed update tag to update...
|
954 |
C<filter()> argument overwrites this default filter. |
update document
|
955 |
|
956 |
$dbi->default_bind_filter('encode_utf8'); |
|
957 |
$dbi->insert( |
|
958 |
table => 'books', |
|
renamed update tag to update...
|
959 |
param => {title => 'Perl', author => 'Ken', price => 1000}, |
update document
|
960 |
filter => {author => 'to_upper_case', price => undef} |
961 |
); |
|
962 | ||
renamed update tag to update...
|
963 |
This is same as the following example. |
update document
|
964 | |
965 |
$dbi->insert( |
|
966 |
table => 'books', |
|
renamed update tag to update...
|
967 |
param => {title => 'Perl', author => 'Ken', price => 1000}, |
update document
|
968 |
filter => {title => 'encode_uft8' author => 'to_upper_case'} |
969 |
); |
|
970 | ||
updated document
|
971 |
You can also specify filter when the row is fetched. This is reverse of bind filter. |
update document
|
972 | |
973 |
my $result = $dbi->select(table => 'books'); |
|
974 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
|
975 | ||
renamed update tag to update...
|
976 |
Filter works each column value, but you prepare a default filter |
977 |
for all clumn value. |
|
update document
|
978 | |
979 |
$dbi->default_fetch_filter('decode_utf8'); |
|
980 | ||
renamed update tag to update...
|
981 |
C<filter()> method of L<DBIx::Custom::Result> |
982 |
overwrites this default filter. |
|
update document
|
983 | |
984 |
$dbi->default_fetch_filter('decode_utf8'); |
|
985 |
my $result = $dbi->select( |
|
986 |
table => 'books', |
|
987 |
columns => ['title', 'author', 'price'] |
|
988 |
); |
|
989 |
$result->filter({author => 'to_upper_case', price => undef}); |
|
990 | ||
991 |
This is same as the following one. |
|
992 | ||
993 |
my $result = $dbi->select( |
|
994 |
table => 'books', |
|
995 |
columns => ['title', 'author', 'price'] |
|
996 |
); |
|
997 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
|
removed reconnect method
|
998 | |
renamed update tag to update...
|
999 |
Note that in fetch filter, column names must be lower case |
1000 |
even if the column name conatains upper case charactors. |
|
1001 |
This is requirment not to depend database systems. |
|
added check_filter attribute
|
1002 | |
cleanup
|
1003 |
=head2 7. Get high performance |
updated document
|
1004 | |
updated document
|
1005 |
=head3 Disable filter checking |
1006 | ||
renamed update tag to update...
|
1007 |
Filter checking is executed by default. |
1008 |
This is done to check right filter name is specified, |
|
1009 |
but sometimes damage performance. |
|
updated document
|
1010 | |
renamed update tag to update...
|
1011 |
If you disable this filter checking, |
1012 |
Set C<filter_check> attribute to 0. |
|
updated document
|
1013 | |
renamed update tag to update...
|
1014 |
$dbi->filter_check(0); |
updated document
|
1015 | |
renamed update tag to update...
|
1016 |
=head3 Use execute() method instead suger methods |
1017 | ||
1018 |
If you execute insert statement by C<insert()> method, |
|
1019 |
you sometimes can't get required performance. |
|
updated document
|
1020 | |
1021 |
C<insert()> method is a little slow because SQL statement and statement handle |
|
1022 |
is created every time. |
|
1023 | ||
1024 |
In that case, you can prepare a query by C<create_query()> method. |
|
1025 |
|
|
1026 |
my $query = $dbi->create_query( |
|
renamed update tag to update...
|
1027 |
"insert into books {insert_param title author};" |
updated document
|
1028 |
); |
cleanup
|
1029 | |
1030 |
Return value of C<create_query()> is L<DBIx::Custom::Query> object. |
|
1031 |
This keep the information of SQL and column names. |
|
1032 | ||
1033 |
{ |
|
1034 |
sql => 'insert into books (title, author) values (?, ?);', |
|
1035 |
columns => ['title', 'author'] |
|
1036 |
} |
|
1037 | ||
1038 |
Execute query repeatedly. |
|
updated document
|
1039 |
|
1040 |
my $inputs = [ |
|
1041 |
{title => 'Perl', author => 'Ken'}, |
|
1042 |
{title => 'Good days', author => 'Mike'} |
|
1043 |
]; |
|
1044 |
|
|
1045 |
foreach my $input (@$inputs) { |
|
1046 |
$dbi->execute($query, $input); |
|
1047 |
} |
|
1048 | ||
cleanup
|
1049 |
This is faster than C<insert()> method. |
updated document
|
1050 | |
cleanup
|
1051 |
=head3 caching |
updated document
|
1052 | |
cleanup
|
1053 |
C<execute()> method caches the parsed result of the source of SQL. |
updated document
|
1054 |
Default to 1 |
1055 | ||
1056 |
$dbi->cache(1); |
|
1057 | ||
1058 |
Caching is on memory, but you can change this by C<cache_method()>. |
|
1059 |
First argument is L<DBIx::Custom> object. |
|
cleanup
|
1060 |
Second argument is a source of SQL, |
1061 |
such as "select * from books where {= title} and {= author};"; |
|
updated document
|
1062 |
Third argument is parsed result, such as |
1063 |
{sql => "select * from books where title = ? and author = ?", |
|
1064 |
columns => ['title', 'author']}, this is hash reference. |
|
cleanup
|
1065 |
If arguments is more than two, this method is called to set cache. |
1066 |
If not, this method is called to get cache. |
|
updated document
|
1067 | |
cleanup
|
1068 |
$dbi->cache_method(sub { |
updated document
|
1069 |
sub { |
1070 |
my $self = shift; |
|
1071 |
|
|
1072 |
$self->{_cached} ||= {}; |
|
1073 |
|
|
1074 |
# Set cache |
|
1075 |
if (@_ > 1) { |
|
1076 |
$self->{_cached}{$_[0]} = $_[1] |
|
1077 |
} |
|
1078 |
|
|
1079 |
# Get cache |
|
1080 |
else { |
|
1081 |
return $self->{_cached}{$_[0]} |
|
1082 |
} |
|
1083 |
} |
|
1084 |
}); |
|
1085 | ||
renamed update tag to update...
|
1086 |
=head2 8. More features |
updated document
|
1087 | |
1088 |
=head3 Get DBI object |
|
1089 | ||
1090 |
You can get L<DBI> object and call any method of L<DBI>. |
|
1091 | ||
1092 |
$dbi->dbh->begin_work; |
|
1093 |
$dbi->dbh->commit; |
|
1094 |
$dbi->dbh->rollback; |
|
1095 | ||
1096 |
=head3 Change Result class |
|
1097 | ||
1098 |
You can change Result class if you need. |
|
1099 | ||
1100 |
package Your::Result; |
|
1101 |
use base 'DBIx::Custom::Result'; |
|
1102 |
|
|
1103 |
sub some_method { ... } |
|
1104 | ||
1105 |
1; |
|
1106 |
|
|
1107 |
package main; |
|
1108 |
|
|
1109 |
use Your::Result; |
|
1110 |
|
|
1111 |
my $dbi = DBIx::Custom->connect(...); |
|
1112 |
$dbi->result_class('Your::Result'); |
|
1113 | ||
1114 |
=head3 Custamize SQL builder object |
|
1115 | ||
1116 |
You can custamize SQL builder object |
|
1117 | ||
1118 |
my $dbi = DBIx::Custom->connect(...); |
|
1119 |
$dbi->query_builder->register_tag_processor( |
|
1120 |
name => sub { |
|
1121 |
... |
|
1122 |
} |
|
1123 |
); |
|
1124 | ||
update document
|
1125 |
=head1 ATTRIBUTES |
packaging one directory
|
1126 | |
removed DBIx::Custom commit ...
|
1127 |
=head2 C<user> |
packaging one directory
|
1128 | |
cleanup
|
1129 |
my $user = $dbi->user; |
1130 |
$dbi = $dbi->user('Ken'); |
|
removed DESTROY method(not b...
|
1131 | |
cleanup
|
1132 |
User name. |
1133 |
C<connect()> method use this value to connect the database. |
|
bind_filter argument is chan...
|
1134 |
|
removed DBIx::Custom commit ...
|
1135 |
=head2 C<password> |
packaging one directory
|
1136 | |
cleanup
|
1137 |
my $password = $dbi->password; |
1138 |
$dbi = $dbi->password('lkj&le`@s'); |
|
packaging one directory
|
1139 | |
cleanup
|
1140 |
Password. |
1141 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1142 | |
removed DBIx::Custom commit ...
|
1143 |
=head2 C<data_source> |
packaging one directory
|
1144 | |
cleanup
|
1145 |
my $data_source = $dbi->data_source; |
cleanup
|
1146 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1147 | |
cleanup
|
1148 |
Data source. |
1149 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1150 | |
removed DBIx::Custom commit ...
|
1151 |
=head2 C<dbh> |
packaging one directory
|
1152 | |
cleanup
|
1153 |
my $dbh = $dbi->dbh; |
1154 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
1155 | |
cleanup
|
1156 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
1157 | |
removed DBIx::Custom commit ...
|
1158 |
=head2 C<filters> |
packaging one directory
|
1159 | |
cleanup
|
1160 |
my $filters = $dbi->filters; |
cleanup
|
1161 |
$dbi = $dbi->filters(\%filters); |
version 0.0901
|
1162 | |
removed DESTROY method(not b...
|
1163 |
Filter functions. |
renamed build_query to creat...
|
1164 |
"encode_utf8" and "decode_utf8" is registered by default. |
version 0.0901
|
1165 | |
renamed default_query_filter...
|
1166 |
=head2 C<default_bind_filter> |
packaging one directory
|
1167 | |
cleanup
|
1168 |
my $default_bind_filter = $dbi->default_bind_filter |
1169 |
$dbi = $dbi->default_bind_filter('encode_utf8'); |
|
packaging one directory
|
1170 | |
cleanup
|
1171 |
Default filter when parameter binding is executed. |
packaging one directory
|
1172 | |
removed DESTROY method(not b...
|
1173 |
=head2 C<default_fetch_filter> |
bind_filter argument is chan...
|
1174 | |
cleanup
|
1175 |
my $default_fetch_filter = $dbi->default_fetch_filter; |
1176 |
$dbi = $dbi->default_fetch_filter('decode_utf8'); |
|
bind_filter argument is chan...
|
1177 | |
cleanup
|
1178 |
Default filter when row is fetched. |
packaging one directory
|
1179 | |
removed DESTROY method(not b...
|
1180 |
=head2 C<result_class> |
bind_filter argument is chan...
|
1181 | |
cleanup
|
1182 |
my $result_class = $dbi->result_class; |
1183 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
packaging one directory
|
1184 | |
removed DESTROY method(not b...
|
1185 |
Result class for select statement. |
renamed default_query_filter...
|
1186 |
Default to L<DBIx::Custom::Result>. |
update document
|
1187 | |
renamed update tag to update...
|
1188 |
=head2 C<query_builder> |
added commit method
|
1189 | |
renamed update tag to update...
|
1190 |
my $sql_class = $dbi->query_builder; |
1191 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1192 | |
renamed update tag to update...
|
1193 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
1194 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1195 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
1196 | |
1197 |
=head2 C<cache> |
|
1198 | ||
1199 |
my $cache = $dbi->cache; |
|
1200 |
$dbi = $dbi->cache(1); |
|
1201 | ||
renamed build_query to creat...
|
1202 |
Enable parsed L<DBIx::Custom::Query> object caching. |
cleanup
|
1203 |
Default to 1. |
1204 | ||
1205 |
=head2 C<cache_method> |
|
1206 | ||
1207 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1208 |
$cache_method = $dbi->cache_method |
|
1209 | ||
renamed build_query to creat...
|
1210 |
Method to set and get caches. |
cleanup
|
1211 | |
1212 |
B<Example:> |
|
1213 | ||
1214 |
$dbi->cache_method( |
|
1215 |
sub { |
|
1216 |
my $self = shift; |
|
1217 |
|
|
1218 |
$self->{_cached} ||= {}; |
|
1219 |
|
|
1220 |
if (@_ > 1) { |
|
1221 |
$self->{_cached}{$_[0]} = $_[1] |
|
1222 |
} |
|
1223 |
else { |
|
1224 |
return $self->{_cached}{$_[0]} |
|
1225 |
} |
|
1226 |
} |
|
1227 |
); |
|
added commit method
|
1228 | |
added check_filter attribute
|
1229 |
=head2 C<filter_check> |
1230 | ||
1231 |
my $filter_check = $dbi->filter_check; |
|
1232 |
$dbi = $dbi->filter_check(0); |
|
1233 | ||
1234 |
Enable filter check. |
|
1235 |
Default to 1. |
|
1236 |
This check maybe damege performance. |
|
cleanup
|
1237 |
If you require performance, set C<filter_check> attribute to 0. |
added check_filter attribute
|
1238 | |
added register_method() meth...
|
1239 |
=head2 C<(experimental) methods> |
1240 | ||
1241 |
my $methods = $dbi->methods; |
|
1242 |
$dbi = $dbi->methods(\%methods); |
|
1243 | ||
1244 |
Additional methods. |
|
1245 | ||
removed reconnect method
|
1246 |
=head1 METHODS |
added commit method
|
1247 | |
cleanup
|
1248 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
1249 |
and implements the following new ones. |
|
added commit method
|
1250 | |
removed DBIx::Custom commit ...
|
1251 |
=head2 C<connect> |
packaging one directory
|
1252 | |
cleanup
|
1253 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
1254 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
1255 | |
cleanup
|
1256 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
1257 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1258 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
1259 |
and C<PrintError> option is false by default. |
packaging one directory
|
1260 | |
removed DBIx::Custom commit ...
|
1261 |
=head2 C<insert> |
packaging one directory
|
1262 | |
cleanup
|
1263 |
$dbi->insert(table => $table, |
1264 |
param => \%param, |
|
1265 |
append => $append, |
|
1266 |
filter => \%filter); |
|
update document
|
1267 | |
renamed build_query to creat...
|
1268 |
Execute insert statement. |
1269 |
C<insert> method have C<table>, C<param>, C<append> |
|
1270 |
and C<filter> arguments. |
|
1271 |
C<table> is a table name. |
|
cleanup
|
1272 |
C<param> is the pairs of column name value. this must be hash reference. |
renamed build_query to creat...
|
1273 |
C<append> is a string added at the end of the SQL statement. |
1274 |
C<filter> is filters when parameter binding is executed. |
|
1275 |
This is overwrites C<default_bind_filter>. |
|
cleanup
|
1276 |
Return value of C<insert()> is the count of affected rows. |
renamed build_query to creat...
|
1277 | |
removed DESTROY method(not b...
|
1278 |
B<Example:> |
version 0.0901
|
1279 | |
removed register_format()
|
1280 |
$dbi->insert(table => 'books', |
1281 |
param => {title => 'Perl', author => 'Taro'}, |
|
1282 |
append => "some statement", |
|
1283 |
filter => {title => 'encode_utf8'}) |
|
version 0.0901
|
1284 | |
removed DBIx::Custom commit ...
|
1285 |
=head2 C<update> |
packaging one directory
|
1286 | |
cleanup
|
1287 |
$dbi->update(table => $table, |
1288 |
param => \%params, |
|
1289 |
where => \%where, |
|
1290 |
append => $append, |
|
1291 |
filter => \%filter) |
|
version 0.0901
|
1292 | |
renamed build_query to creat...
|
1293 |
Execute update statement. |
1294 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1295 |
and C<filter> arguments. |
|
1296 |
C<table> is a table name. |
|
1297 |
C<param> is column-value pairs. this must be hash reference. |
|
1298 |
C<where> is where clause. this must be hash reference. |
|
1299 |
C<append> is a string added at the end of the SQL statement. |
|
1300 |
C<filter> is filters when parameter binding is executed. |
|
1301 |
This is overwrites C<default_bind_filter>. |
|
cleanup
|
1302 |
Return value of C<update()> is the count of affected rows. |
update document
|
1303 | |
removed DESTROY method(not b...
|
1304 |
B<Example:> |
bind_filter argument is chan...
|
1305 | |
removed register_format()
|
1306 |
$dbi->update(table => 'books', |
1307 |
param => {title => 'Perl', author => 'Taro'}, |
|
1308 |
where => {id => 5}, |
|
cleanup
|
1309 |
append => "some statement", |
added commit method
|
1310 |
filter => {title => 'encode_utf8'}); |
version 0.0901
|
1311 | |
removed DBIx::Custom commit ...
|
1312 |
=head2 C<update_all> |
packaging one directory
|
1313 | |
cleanup
|
1314 |
$dbi->update_all(table => $table, |
1315 |
param => \%params, |
|
1316 |
filter => \%filter, |
|
1317 |
append => $append); |
|
update document
|
1318 | |
renamed build_query to creat...
|
1319 |
Execute update statement to update all rows. |
1320 |
Arguments is same as C<update> method, |
|
1321 |
except that C<update_all> don't have C<where> argument. |
|
cleanup
|
1322 |
Return value of C<update_all()> is the count of affected rows. |
version 0.0901
|
1323 | |
removed DESTROY method(not b...
|
1324 |
B<Example:> |
update document
|
1325 | |
removed register_format()
|
1326 |
$dbi->update_all(table => 'books', |
1327 |
param => {author => 'taro'}, |
|
1328 |
filter => {author => 'encode_utf8'}); |
|
packaging one directory
|
1329 | |
removed DBIx::Custom commit ...
|
1330 |
=head2 C<delete> |
packaging one directory
|
1331 | |
cleanup
|
1332 |
$dbi->delete(table => $table, |
1333 |
where => \%where, |
|
1334 |
append => $append, |
|
1335 |
filter => \%filter); |
|
bind_filter argument is chan...
|
1336 | |
renamed build_query to creat...
|
1337 |
Execute delete statement. |
1338 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
1339 |
C<table> is a table name. |
|
1340 |
C<where> is where clause. this must be hash reference. |
|
1341 |
C<append> is a string added at the end of the SQL statement. |
|
1342 |
C<filter> is filters when parameter binding is executed. |
|
cleanup
|
1343 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
1344 | |
removed DESTROY method(not b...
|
1345 |
B<Example:> |
packaging one directory
|
1346 | |
removed register_format()
|
1347 |
$dbi->delete(table => 'books', |
1348 |
where => {id => 5}, |
|
1349 |
append => 'some statement', |
|
removed reconnect method
|
1350 |
filter => {id => 'encode_utf8'}); |
version 0.0901
|
1351 | |
removed DBIx::Custom commit ...
|
1352 |
=head2 C<delete_all> |
packaging one directory
|
1353 | |
cleanup
|
1354 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1355 | |
renamed build_query to creat...
|
1356 |
Execute delete statement to delete all rows. |
1357 |
Arguments is same as C<delete> method, |
|
1358 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
1359 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
1360 | |
removed DESTROY method(not b...
|
1361 |
B<Example:> |
removed register_format()
|
1362 |
|
removed reconnect method
|
1363 |
$dbi->delete_all(table => 'books'); |
packaging one directory
|
1364 | |
removed DBIx::Custom commit ...
|
1365 |
=head2 C<select> |
packaging one directory
|
1366 |
|
cleanup
|
1367 |
my $result = $dbi->select(table => $table, |
1368 |
column => [@column], |
|
1369 |
where => \%where, |
|
1370 |
append => $append, |
|
1371 |
relation => \%relation, |
|
1372 |
filter => \%filter); |
|
update document
|
1373 | |
renamed build_query to creat...
|
1374 |
Execute select statement. |
cleanup
|
1375 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
1376 |
C<relation> and C<filter> arguments. |
1377 |
C<table> is a table name. |
|
cleanup
|
1378 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
1379 |
C<append> is a string added at the end of the SQL statement. |
1380 |
C<filter> is filters when parameter binding is executed. |
|
update document
|
1381 | |
removed DESTROY method(not b...
|
1382 |
B<Example:> |
update document
|
1383 | |
added commit method
|
1384 |
# select * from books; |
cleanup
|
1385 |
my $result = $dbi->select(table => 'books'); |
packaging one directory
|
1386 |
|
renamed build_query to creat...
|
1387 |
# select * from books where title = ?; |
1388 |
my $result = $dbi->select(table => 'books', where => {title => 'Perl'}); |
|
update document
|
1389 |
|
renamed build_query to creat...
|
1390 |
# select title, author from books where id = ? for update; |
cleanup
|
1391 |
my $result = $dbi->select( |
removed register_format()
|
1392 |
table => 'books', |
removed reconnect method
|
1393 |
column => ['title', 'author'], |
removed register_format()
|
1394 |
where => {id => 1}, |
1395 |
appned => 'for update' |
|
update document
|
1396 |
); |
1397 |
|
|
renamed update tag to update...
|
1398 |
# select books.name as book_name from books, rental |
added commit method
|
1399 |
# where books.id = rental.book_id; |
1400 |
my $result = $dbi->select( |
|
removed reconnect method
|
1401 |
table => ['books', 'rental'], |
1402 |
column => ['books.name as book_name'] |
|
added commit method
|
1403 |
relation => {'books.id' => 'rental.book_id'} |
update document
|
1404 |
); |
1405 | ||
cleanup
|
1406 |
If you use more complex condition, |
1407 |
you can specify a array reference to C<where> argument. |
|
1408 | ||
1409 |
my $result = $dbi->select( |
|
1410 |
table => 'books', |
|
1411 |
column => ['title', 'author'], |
|
1412 |
where => ['{= title} or {like author}', |
|
1413 |
{title => '%Perl%', author => 'Ken'}] |
|
1414 |
); |
|
1415 | ||
1416 |
First element is a string. it contains tags, |
|
1417 |
such as "{= title} or {like author}". |
|
1418 |
Second element is paramters. |
|
1419 | ||
renamed build_query to creat...
|
1420 |
=head2 C<create_query> |
removed reconnect method
|
1421 |
|
renamed build_query to creat...
|
1422 |
my $query = $dbi->create_query( |
cleanup
|
1423 |
"select * from books where {= author} and {like title};" |
removed DBIx::Custom commit ...
|
1424 |
); |
1425 | ||
cleanup
|
1426 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
1427 |
If you want to get high performance, |
|
1428 |
use C<create_query()> method and execute it by C<execute()> method |
|
1429 |
instead of suger methods. |
|
1430 | ||
1431 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
|
packaging one directory
|
1432 | |
removed DBIx::Custom commit ...
|
1433 |
=head2 C<execute> |
removed reconnect method
|
1434 | |
cleanup
|
1435 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
1436 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
|
removed reconnect method
|
1437 | |
cleanup
|
1438 |
Execute query or the source of SQL. |
1439 |
Query is L<DBIx::Custom::Query> object. |
|
1440 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
1441 |
or the count of affected rows if insert, update, delete statement is executed. |
|
removed reconnect method
|
1442 | |
removed DBIx::Custom commit ...
|
1443 |
B<Example:> |
removed reconnect method
|
1444 | |
cleanup
|
1445 |
my $result = $dbi->execute( |
1446 |
"select * from books where {= author} and {like title}", |
|
1447 |
param => {author => 'Ken', title => '%Perl%'} |
|
1448 |
); |
|
removed reconnect method
|
1449 |
|
1450 |
while (my $row = $result->fetch) { |
|
cleanup
|
1451 |
my $author = $row->[0]; |
1452 |
my $title = $row->[1]; |
|
removed reconnect method
|
1453 |
} |
1454 | ||
removed DBIx::Custom commit ...
|
1455 |
=head2 C<register_filter> |
removed reconnect method
|
1456 | |
1457 |
$dbi->register_filter(%filters); |
|
removed DESTROY method(not b...
|
1458 |
$dbi->register_filter(\%filters); |
removed reconnect method
|
1459 |
|
cleanup
|
1460 |
Register filter. Registered filters is available in the following attributes |
renamed build_query to creat...
|
1461 |
or arguments. |
1462 | ||
1463 |
=over 4 |
|
1464 | ||
1465 |
=item * |
|
1466 | ||
cleanup
|
1467 |
C<default_bind_filter>, C<default_fetch_filter> |
renamed build_query to creat...
|
1468 | |
1469 |
=item * |
|
1470 | ||
1471 |
C<filter> argument of C<insert()>, C<update()>, |
|
cleanup
|
1472 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
1473 |
methods |
|
renamed build_query to creat...
|
1474 | |
1475 |
=item * |
|
1476 | ||
cleanup
|
1477 |
C<execute()> method |
renamed build_query to creat...
|
1478 | |
1479 |
=item * |
|
1480 | ||
cleanup
|
1481 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
renamed build_query to creat...
|
1482 | |
1483 |
=item * |
|
1484 | ||
cleanup
|
1485 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
renamed build_query to creat...
|
1486 | |
1487 |
=back |
|
removed DBIx::Custom commit ...
|
1488 | |
1489 |
B<Example:> |
|
packaging one directory
|
1490 | |
removed reconnect method
|
1491 |
$dbi->register_filter( |
1492 |
encode_utf8 => sub { |
|
1493 |
my $value = shift; |
|
1494 |
|
|
1495 |
require Encode; |
|
1496 |
|
|
1497 |
return Encode::encode('UTF-8', $value); |
|
1498 |
}, |
|
1499 |
decode_utf8 => sub { |
|
1500 |
my $value = shift; |
|
1501 |
|
|
1502 |
require Encode; |
|
1503 |
|
|
1504 |
return Encode::decode('UTF-8', $value) |
|
1505 |
} |
|
1506 |
); |
|
1507 | ||
added register_method() meth...
|
1508 |
=head2 C<(experimental) register_method> |
1509 | ||
1510 |
$dbi->register_method( |
|
1511 |
begin_work => sub { shift->dbh->begin_work }, |
|
1512 |
commit => sub { shift->dbh->commit }, |
|
1513 |
rollback => sub { shift->dbh->rollback} |
|
1514 |
); |
|
1515 | ||
1516 |
Register methods to the object. You can call these methods |
|
1517 |
from the object. |
|
1518 | ||
1519 |
$dbi->begin_work; |
|
1520 |
$dbi->commit; |
|
1521 |
$dbi->rollback; |
|
1522 | ||
removed DESTROY method(not b...
|
1523 |
=head1 BUGS |
1524 | ||
renamed build_query to creat...
|
1525 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1526 | |
1527 |
C<< <kimoto.yuki at gmail.com> >> |
|
1528 | ||
1529 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1530 | ||
removed reconnect method
|
1531 |
=head1 AUTHOR |
1532 | ||
1533 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1534 | |
packaging one directory
|
1535 |
=head1 COPYRIGHT & LICENSE |
1536 | ||
1537 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
1538 | ||
1539 |
This program is free software; you can redistribute it and/or modify it |
|
1540 |
under the same terms as Perl itself. |
|
1541 | ||
1542 |
=cut |
|
added cache_method attribute
|
1543 | |
1544 |