cleanup
|
1 |
package DBIx::Custom; |
2 | ||
where can recieve array refr...
|
3 |
our $VERSION = '0.1664'; |
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; |
added experimental DBIx::Cus...
|
16 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
17 |
use DBIx::Custom::Model; |
cleanup
|
18 |
use DBIx::Custom::Tag; |
all filter can receive array...
|
19 |
use DBIx::Custom::Util; |
update document
|
20 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
21 | |
- added EXPERIMENTAL type() ...
|
22 |
our @COMMON_ARGS = qw/table query filter type/; |
cleanup
|
23 | |
fix tests
|
24 |
__PACKAGE__->attr( |
EXPERIMETAL fork safety impl...
|
25 |
[qw/data_source password pid user/], |
fix tests
|
26 |
cache => 1, |
many changed
|
27 |
cache_method => sub { |
28 |
sub { |
|
29 |
my $self = shift; |
|
30 |
|
|
31 |
$self->{_cached} ||= {}; |
|
32 |
|
|
33 |
if (@_ > 1) { |
|
update pod
|
34 |
$self->{_cached}{$_[0]} = $_[1]; |
many changed
|
35 |
} |
36 |
else { |
|
update pod
|
37 |
return $self->{_cached}{$_[0]}; |
many changed
|
38 |
} |
39 |
} |
|
update pod
|
40 |
}, |
41 |
dbi_option => sub { {} }, |
|
42 |
default_dbi_option => sub { |
|
43 |
{ |
|
44 |
RaiseError => 1, |
|
45 |
PrintError => 0, |
|
46 |
AutoCommit => 1 |
|
47 |
} |
|
48 |
}, |
|
fix tests
|
49 |
filters => sub { |
50 |
{ |
|
51 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
52 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
53 |
} |
|
update pod
|
54 |
}, |
55 |
models => sub { {} }, |
|
56 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
|
57 |
result_class => 'DBIx::Custom::Result', |
|
58 |
safety_character => '\w', |
|
59 |
stash => sub { {} } |
|
fix tests
|
60 |
); |
cleanup
|
61 | |
added helper method
|
62 |
our $AUTOLOAD; |
63 |
sub AUTOLOAD { |
|
64 |
my $self = shift; |
|
65 | ||
renamed helper to method.
|
66 |
# Method name |
67 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
68 | |
renamed helper to method.
|
69 |
# Method |
70 |
$self->{_methods} ||= {}; |
|
add feture. all model class ...
|
71 |
if (my $method = $self->{_methods}->{$mname}) { |
72 |
return $self->$method(@_) |
|
73 |
} |
|
- added EXPERIMENTAL DBIx::C...
|
74 |
elsif (my $dbh_method = $self->dbh->can($mname)) { |
75 |
$self->dbh->$dbh_method(@_); |
|
add feture. all model class ...
|
76 |
} |
77 |
else { |
|
78 |
croak qq/Can't locate object method "$mname" via "$package"/ |
|
79 |
} |
|
added helper method
|
80 |
} |
81 | ||
renamed auto_filter to apply...
|
82 |
sub apply_filter { |
many changed
|
83 |
my ($self, $table, @cinfos) = @_; |
84 | ||
85 |
# Initialize filters |
|
cleanup
|
86 |
$self->{filter} ||= {}; |
many changed
|
87 |
$self->{filter}{out} ||= {}; |
88 |
$self->{filter}{in} ||= {}; |
|
all filter can receive array...
|
89 |
$self->{filter}{end} ||= {}; |
cleanup
|
90 |
|
many changed
|
91 |
# Create filters |
92 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
fix bug : filter can't over...
|
93 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
94 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
many changed
|
95 | |
96 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
added auto_filter method
|
97 |
|
many changed
|
98 |
# Column |
99 |
my $column = $cinfos[$i]; |
|
added auto_filter method
|
100 |
|
all filter can receive array...
|
101 |
if (ref $column eq 'ARRAY') { |
102 |
foreach my $c (@$column) { |
|
103 |
push @cinfos, $c, $cinfos[$i + 1]; |
|
104 |
} |
|
105 |
next; |
|
106 |
} |
|
107 |
|
|
fix bug : filter can't over...
|
108 |
# Filter info |
109 |
my $finfo = $cinfos[$i + 1] || {}; |
|
all filter can receive array...
|
110 |
croak "$usage (table: $table)" unless ref $finfo eq 'HASH'; |
fix bug : filter can't over...
|
111 |
foreach my $ftype (keys %$finfo) { |
all filter can receive array...
|
112 |
croak "$usage (table: $table 2)" unless $ftype eq 'in' || $ftype eq 'out' |
fix bug : filter can't over...
|
113 |
|| $ftype eq 'end'; |
many changed
|
114 |
} |
115 |
|
|
fix bug : filter can't over...
|
116 |
foreach my $way (qw/in out end/) { |
117 |
my $filter = $finfo->{$way}; |
|
cleanup
|
118 |
|
fix bug : filter can't over...
|
119 |
# State |
120 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
121 |
: !defined $filter ? 'not_defined' |
|
122 |
: ref $filter eq 'CODE' ? 'code' |
|
123 |
: 'name'; |
|
124 |
|
|
125 |
next if $state eq 'not_exists'; |
|
126 |
|
|
127 |
# Check filter |
|
128 |
croak qq{Filter "$filter" is not registered} |
|
129 |
if $state eq 'name' |
|
130 |
&& ! exists $self->filters->{$filter}; |
|
131 |
|
|
132 |
# Filter |
|
133 |
my $f = $state eq 'not_defined' ? undef |
|
134 |
: $state eq 'code' ? $filter |
|
135 |
: $self->filters->{$filter}; |
|
136 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
137 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
138 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
many changed
|
139 |
} |
added auto_filter method
|
140 |
} |
141 |
|
|
many changed
|
142 |
return $self; |
added auto_filter method
|
143 |
} |
144 | ||
cleanup
|
145 |
sub column { |
146 |
my ($self, $table, $columns) = @_; |
|
added helper method
|
147 |
|
cleanup
|
148 |
$columns ||= []; |
added helper method
|
149 |
|
cleanup
|
150 |
my @column; |
151 |
push @column, "$table.$_ as ${table}__$_" for @$columns; |
|
152 |
|
|
153 |
return join (', ', @column); |
|
added helper method
|
154 |
} |
155 | ||
packaging one directory
|
156 |
sub connect { |
cleanup
|
157 |
my $self = ref $_[0] ? shift : shift->new(@_);; |
removed register_format()
|
158 |
|
EXPERIMETAL fork safety impl...
|
159 |
my $dbh = $self->_connect; |
packaging one directory
|
160 |
|
update document
|
161 |
# Database handle |
packaging one directory
|
162 |
$self->dbh($dbh); |
update document
|
163 |
|
EXPERIMETAL fork safety impl...
|
164 |
# Process ID |
165 |
$self->pid($$); |
|
166 |
|
|
packaging one directory
|
167 |
return $self; |
168 |
} |
|
169 | ||
cleanup
|
170 |
sub create_query { |
171 |
my ($self, $source) = @_; |
|
update document
|
172 |
|
cleanup
|
173 |
# Cache |
174 |
my $cache = $self->cache; |
|
update document
|
175 |
|
cleanup
|
176 |
# Create query |
177 |
my $query; |
|
178 |
if ($cache) { |
|
179 |
|
|
180 |
# Get query |
|
181 |
my $q = $self->cache_method->($self, $source); |
|
182 |
|
|
183 |
# Create query |
|
add table tag
|
184 |
if ($q) { |
185 |
$query = DBIx::Custom::Query->new($q); |
|
186 |
$query->filters($self->filters); |
|
187 |
} |
|
cleanup
|
188 |
} |
189 |
|
|
190 |
unless ($query) { |
|
cleanup insert
|
191 | |
cleanup
|
192 |
# Create SQL object |
193 |
my $builder = $self->query_builder; |
|
194 |
|
|
195 |
# Create query |
|
196 |
$query = $builder->build_query($source); |
|
removed register_format()
|
197 | |
cleanup
|
198 |
# Cache query |
199 |
$self->cache_method->($self, $source, |
|
200 |
{sql => $query->sql, |
|
add table tag
|
201 |
columns => $query->columns, |
202 |
tables => $query->tables}) |
|
cleanup
|
203 |
if $cache; |
cleanup insert
|
204 |
} |
205 |
|
|
cleanup
|
206 |
# Prepare statement handle |
207 |
my $sth; |
|
208 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
renamed DBIx::Custom::TagPro...
|
209 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
packaging one directory
|
210 |
|
cleanup
|
211 |
# Set statement handle |
212 |
$query->sth($sth); |
|
packaging one directory
|
213 |
|
cleanup
|
214 |
# Set filters |
215 |
$query->filters($self->filters); |
|
216 |
|
|
cleanup
|
217 |
return $query; |
packaging one directory
|
218 |
} |
219 | ||
update pod
|
220 |
sub dbh { |
221 |
my $self = shift; |
|
222 | ||
223 |
if (@_) { |
|
224 |
$self->{dbh} = $_[0]; |
|
225 |
return $self; |
|
226 |
} |
|
227 |
else { |
|
228 |
my $pid = $$; |
|
229 |
if ($self->pid eq $pid) { |
|
230 |
return $self->{dbh}; |
|
231 |
} |
|
232 |
else { |
|
233 |
# Create new connection in child process |
|
234 |
croak "Process is forked in transaction" |
|
235 |
unless $self->{dbh}->{AutoCommit}; |
|
236 |
$self->pid($pid); |
|
237 |
$self->{dbh}->{InactiveDestroy} = 1; |
|
238 |
return $self->{dbh} = $self->_connect; |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 | ||
cleanup
|
243 |
our %DELETE_ARGS |
cleanup
|
244 |
= map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all/; |
cleanup update and update_al...
|
245 | |
cleanup
|
246 |
sub delete { |
select, insert, update, upda...
|
247 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
248 |
|
cleanup
|
249 |
# Check argument names |
select, insert, update, upda...
|
250 |
foreach my $name (keys %args) { |
cleanup
|
251 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
252 |
unless $DELETE_ARGS{$name}; |
cleanup update and update_al...
|
253 |
} |
254 |
|
|
255 |
# Arguments |
|
cleanup
|
256 |
my $table = $args{table} || ''; |
added table not specified ex...
|
257 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
258 |
my $where = delete $args{where} || {}; |
259 |
my $append = delete $args{append}; |
|
260 |
my $allow_delete_all = delete $args{allow_delete_all}; |
|
added auto_filter method
|
261 | |
make delete() using where ob...
|
262 |
# Where |
where can recieve array refr...
|
263 |
my $w = $self->_where($where); |
264 |
$where = $w->param; |
|
make delete() using where ob...
|
265 |
|
select() where can't receive...
|
266 |
# String where |
267 |
my $swhere = "$w"; |
|
improved delete() and update...
|
268 |
|
make delete() using where ob...
|
269 |
croak qq{"where" must be specified} |
select() where can't receive...
|
270 |
if $swhere eq '' && !$allow_delete_all; |
make delete() using where ob...
|
271 | |
cleanup
|
272 |
# SQL stack |
273 |
my @sql; |
|
274 | ||
275 |
# Delete |
|
276 |
push @sql, "delete from $table $swhere"; |
|
277 |
push @sql, $append if $append; |
|
278 |
|
|
279 |
my $sql = join(' ', @sql); |
|
packaging one directory
|
280 |
|
added experimental sugar met...
|
281 |
# Create query |
cleanup
|
282 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
283 |
return $query if $args{query}; |
284 |
|
|
packaging one directory
|
285 |
# Execute query |
added auto_filter method
|
286 |
my $ret_val = $self->execute( |
cleanup
|
287 |
$query, |
288 |
param => $where, |
|
289 |
table => $table, |
|
290 |
%args |
|
291 |
); |
|
packaging one directory
|
292 |
|
293 |
return $ret_val; |
|
294 |
} |
|
295 | ||
cleanup
|
296 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
297 | |
cleanup
|
298 |
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1); |
add experimental update_at()...
|
299 | |
300 |
sub delete_at { |
|
301 |
my ($self, %args) = @_; |
|
302 |
|
|
cleanup
|
303 |
# Check argument names |
add experimental update_at()...
|
304 |
foreach my $name (keys %args) { |
cleanup
|
305 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
306 |
unless $DELETE_AT_ARGS{$name}; |
add experimental update_at()...
|
307 |
} |
308 |
|
|
309 |
# Primary key |
|
310 |
my $primary_keys = delete $args{primary_key}; |
|
311 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
312 |
|
|
313 |
# Where clause |
|
314 |
my $where = {}; |
|
315 |
if (exists $args{where}) { |
|
316 |
my $where_columns = delete $args{where}; |
|
317 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
- added experimental DBIx::C...
|
318 | |
319 |
croak qq{"where" must be constant value or array reference} |
|
320 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
add experimental update_at()...
|
321 |
|
322 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
323 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
324 |
} |
|
325 |
} |
|
- added experimental DBIx::C...
|
326 |
|
327 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
328 |
my $param = delete $args{param}; |
329 |
|
|
330 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
331 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
332 |
} |
333 |
} |
|
334 |
|
|
335 |
return $self->delete(where => $where, %args); |
|
336 |
} |
|
337 | ||
added helper method
|
338 |
sub DESTROY { } |
339 | ||
cleanup
|
340 |
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param'; |
refactoring delete and delet...
|
341 | |
cleanup
|
342 |
sub execute{ |
343 |
my ($self, $query, %args) = @_; |
|
refactoring delete and delet...
|
344 |
|
cleanup
|
345 |
# Check argument names |
select, insert, update, upda...
|
346 |
foreach my $name (keys %args) { |
cleanup
|
347 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
348 |
unless $EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
349 |
} |
350 |
|
|
cleanup
|
351 |
my $params = $args{param} || {}; |
packaging one directory
|
352 |
|
cleanup
|
353 |
# First argument is the soruce of SQL |
354 |
$query = $self->create_query($query) |
|
355 |
unless ref $query; |
|
packaging one directory
|
356 |
|
add table tag
|
357 |
# Applied filter |
cleanup
|
358 |
my $filter = {}; |
all filter can receive array...
|
359 |
|
add table tag
|
360 |
my $tables = $query->tables; |
361 |
my $arg_tables = $args{table} || []; |
|
362 |
$arg_tables = [$arg_tables] |
|
363 |
unless ref $arg_tables eq 'ARRAY'; |
|
364 |
push @$tables, @$arg_tables; |
|
cleanup
|
365 | |
366 |
# Organize tables |
|
367 |
my %table_set = map {defined $_ ? ($_ => 1) : ()} @$tables; |
|
368 |
my $main_table = pop @$tables; |
|
369 |
delete $table_set{$main_table} if $main_table; |
|
- added EXPERIMENTAL DBIx::C...
|
370 |
foreach my $table (keys %table_set) { |
371 |
push @$tables, $table; |
|
372 |
|
|
373 |
if (my $dist = $self->{_table_alias}->{$table}) { |
|
374 |
$self->{filter} ||= {}; |
|
375 |
|
|
376 |
unless ($self->{filter}{out}{$table}) { |
|
377 |
$self->{filter}{out} ||= {}; |
|
378 |
$self->{filter}{in} ||= {}; |
|
379 |
$self->{filter}{end} ||= {}; |
|
380 |
|
|
381 |
foreach my $type (qw/out in end/) { |
|
382 |
|
|
383 |
foreach my $filter_name (keys %{$self->{filter}{$type}{$dist} || {}}) { |
|
384 |
my $filter_name_alias = $filter_name; |
|
385 |
$filter_name_alias =~ s/^$dist\./$table\./; |
|
386 |
$filter_name_alias =~ s/^${dist}__/${table}__/; |
|
387 |
|
|
388 |
$self->{filter}{$type}{$table}{$filter_name_alias} |
|
389 |
= $self->{filter}{$type}{$dist}{$filter_name} |
|
390 |
} |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
cleanup
|
396 |
$tables = [keys %table_set]; |
397 |
push @$tables, $main_table if $main_table; |
|
remove experimental DBIx::Cu...
|
398 |
|
renamed auto_filter to apply...
|
399 |
foreach my $table (@$tables) { |
remove experimental DBIx::Cu...
|
400 |
next unless $table; |
cleanup
|
401 |
$filter = { |
402 |
%$filter, |
|
403 |
%{$self->{filter}{out}->{$table} || {}} |
|
added auto_filter method
|
404 |
} |
405 |
} |
|
406 |
|
|
cleanup
|
407 |
# Filter argument |
cleanup
|
408 |
my $f = DBIx::Custom::Util::array_to_hash($args{filter}) |
all filter can receive array...
|
409 |
|| $query->filter || {}; |
cleanup
|
410 |
foreach my $column (keys %$f) { |
411 |
my $fname = $f->{$column}; |
|
renamed auto_filter to apply...
|
412 |
if (!defined $fname) { |
cleanup
|
413 |
$f->{$column} = undef; |
renamed auto_filter to apply...
|
414 |
} |
415 |
elsif (ref $fname ne 'CODE') { |
|
many changed
|
416 |
croak qq{Filter "$fname" is not registered"} |
cleanup
|
417 |
unless exists $self->filters->{$fname}; |
418 |
|
|
cleanup
|
419 |
$f->{$column} = $self->filters->{$fname}; |
cleanup
|
420 |
} |
421 |
} |
|
cleanup
|
422 |
$filter = {%$filter, %$f}; |
packaging one directory
|
423 |
|
- added EXPERIMENTAL type() ...
|
424 |
# Type |
425 |
my $type = DBIx::Custom::Util::array_to_hash($args{type}); |
|
426 |
|
|
added experimental not_exist...
|
427 |
# Bind |
- added EXPERIMENTAL type() ...
|
428 |
my $bind = $self->_bind($params, $query->columns, $filter, $type); |
cleanup
|
429 |
|
430 |
# Execute |
|
added experimental not_exist...
|
431 |
my $sth = $query->sth; |
cleanup
|
432 |
my $affected; |
cleanup
|
433 |
eval { |
434 |
for (my $i = 0; $i < @$bind; $i++) { |
|
- added EXPERIMENTAL type() ...
|
435 |
if (my $type = $bind->[$i]->{type}) { |
436 |
$sth->bind_param($i + 1, $bind->[$i]->{value}, $type); |
|
437 |
} |
|
438 |
else { |
|
439 |
$sth->bind_param($i + 1, $bind->[$i]->{value}); |
|
440 |
} |
|
cleanup
|
441 |
} |
442 |
$affected = $sth->execute; |
|
443 |
}; |
|
renamed DBIx::Custom::TagPro...
|
444 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
cleanup
|
445 |
|
446 |
# Return resultset if select statement is executed |
|
447 |
if ($sth->{NUM_OF_FIELDS}) { |
|
448 |
|
|
fix bug : filter can't over...
|
449 |
# Result in and end filter |
450 |
my $in_filter = {}; |
|
451 |
my $end_filter = {}; |
|
cleanup
|
452 |
foreach my $table (@$tables) { |
remove experimental DBIx::Cu...
|
453 |
next unless $table; |
cleanup
|
454 |
$in_filter = { |
455 |
%$in_filter, |
|
456 |
%{$self->{filter}{in}{$table} || {}} |
|
fix bug : filter can't over...
|
457 |
}; |
458 |
$end_filter = { |
|
459 |
%$end_filter, |
|
460 |
%{$self->{filter}{end}{$table} || {}} |
|
461 |
}; |
|
cleanup
|
462 |
} |
463 |
|
|
464 |
# Result |
|
465 |
my $result = $self->result_class->new( |
|
cleanup
|
466 |
sth => $sth, |
467 |
filters => $self->filters, |
|
468 |
filter_check => $self->filter_check, |
|
cleanup
|
469 |
default_filter => $self->{default_in_filter}, |
fix bug : filter can't over...
|
470 |
filter => $in_filter || {}, |
471 |
end_filter => $end_filter || {} |
|
cleanup
|
472 |
); |
473 | ||
474 |
return $result; |
|
475 |
} |
|
476 |
return $affected; |
|
477 |
} |
|
478 | ||
cleanup
|
479 |
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param append/; |
update pod
|
480 | |
cleanup
|
481 |
sub insert { |
482 |
my ($self, %args) = @_; |
|
483 | ||
cleanup
|
484 |
# Check argument names |
cleanup
|
485 |
foreach my $name (keys %args) { |
cleanup
|
486 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
487 |
unless $INSERT_ARGS{$name}; |
packaging one directory
|
488 |
} |
489 |
|
|
cleanup
|
490 |
# Arguments |
cleanup
|
491 |
my $table = delete $args{table}; |
added table not specified ex...
|
492 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
493 |
my $param = delete $args{param} || {}; |
494 |
my $append = delete $args{append} || ''; |
|
cleanup
|
495 |
|
select() where can't receive...
|
496 |
# Columns |
497 |
my @columns; |
|
- remaned experimental safty...
|
498 |
my $safety = $self->safety_character; |
select() where can't receive...
|
499 |
foreach my $column (keys %$param) { |
500 |
croak qq{"$column" is not safety column name} |
|
- remaned experimental safty...
|
501 |
unless $column =~ /^[$safety\.]+$/; |
select() where can't receive...
|
502 |
push @columns, $column; |
503 |
} |
|
cleanup
|
504 |
|
cleanup
|
505 |
# SQL stack |
506 |
my @sql; |
|
507 |
|
|
508 |
# Insert |
|
509 |
push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}'; |
|
510 |
push @sql, $append if $append; |
|
511 |
|
|
select() where can't receive...
|
512 |
# SQL |
cleanup
|
513 |
my $sql = join (' ', @sql); |
packaging one directory
|
514 |
|
added experimental sugar met...
|
515 |
# Create query |
cleanup
|
516 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
517 |
return $query if $args{query}; |
518 |
|
|
packaging one directory
|
519 |
# Execute query |
added auto_filter method
|
520 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
521 |
$query, |
added auto_filter method
|
522 |
param => $param, |
cleanup
|
523 |
table => $table, |
524 |
%args |
|
added auto_filter method
|
525 |
); |
packaging one directory
|
526 |
|
527 |
return $ret_val; |
|
528 |
} |
|
529 | ||
cleanup
|
530 |
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1); |
- added experimental DBIx::C...
|
531 | |
532 |
sub insert_at { |
|
533 |
my ($self, %args) = @_; |
|
534 |
|
|
cleanup
|
535 |
# Check argument names |
- added experimental DBIx::C...
|
536 |
foreach my $name (keys %args) { |
cleanup
|
537 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
538 |
unless $INSERT_AT_ARGS{$name}; |
- added experimental DBIx::C...
|
539 |
} |
540 |
|
|
541 |
# Primary key |
|
542 |
my $primary_keys = delete $args{primary_key}; |
|
543 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
544 |
|
|
545 |
# Where clause |
|
546 |
my $where = {}; |
|
547 |
my $param = {}; |
|
548 |
|
|
549 |
if (exists $args{where}) { |
|
550 |
my $where_columns = delete $args{where}; |
|
551 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
552 | ||
553 |
croak qq{"where" must be constant value or array reference} |
|
554 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
555 |
|
|
556 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
557 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
558 |
} |
|
559 |
} |
|
560 |
|
|
561 |
if (exists $args{param}) { |
|
562 |
$param = delete $args{param}; |
|
563 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
564 |
delete $param->{$primary_keys->[$i]}; |
|
565 |
} |
|
566 |
} |
|
567 |
|
|
568 |
$param = {%$param, %$where}; |
|
569 |
|
|
570 |
return $self->insert(param => $param, %args); |
|
571 |
} |
|
572 | ||
remove experimental DBIx::Cu...
|
573 |
sub insert_param { |
574 |
my ($self, $param) = @_; |
|
575 |
|
|
update pod
|
576 |
# Insert parameter tag |
remove experimental DBIx::Cu...
|
577 |
my @tag; |
578 |
push @tag, '{insert_param'; |
|
- remaned experimental safty...
|
579 |
my $safety = $self->safety_character; |
remove experimental DBIx::Cu...
|
580 |
foreach my $column (keys %$param) { |
added experimental update_pa...
|
581 |
croak qq{"$column" is not safety column name} |
- remaned experimental safty...
|
582 |
unless $column =~ /^[$safety\.]+$/; |
remove experimental DBIx::Cu...
|
583 |
push @tag, $column; |
584 |
} |
|
585 |
push @tag, '}'; |
|
586 |
|
|
587 |
return join ' ', @tag; |
|
588 |
} |
|
589 | ||
pod fix
|
590 |
sub each_column { |
added experimental iterate_a...
|
591 |
my ($self, $cb) = @_; |
592 |
|
|
593 |
# Iterate all tables |
|
594 |
my $sth_tables = $self->dbh->table_info; |
|
595 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
596 |
|
|
597 |
# Table |
|
598 |
my $table = $table_info->{TABLE_NAME}; |
|
599 |
|
|
600 |
# Iterate all columns |
|
601 |
my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
602 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
603 |
my $column = $column_info->{COLUMN_NAME}; |
|
removed experimental txn_sco...
|
604 |
$self->$cb($table, $column, $column_info); |
added experimental iterate_a...
|
605 |
} |
606 |
} |
|
607 |
} |
|
608 | ||
- added EXPERIMENTAL DBIx::C...
|
609 |
sub include_model { |
610 |
my ($self, $name_space, $model_infos) = @_; |
|
611 |
|
|
612 |
$name_space ||= ''; |
|
613 |
unless ($model_infos) { |
|
614 |
# Load name space module |
|
615 |
croak qq{"$name_space" is invalid class name} |
|
616 |
if $name_space =~ /[^\w:]/; |
|
617 |
eval "use $name_space"; |
|
618 |
croak qq{Name space module "$name_space.pm" is needed. $@} if $@; |
|
619 |
|
|
620 |
# Search model modules |
|
621 |
my $path = $INC{"$name_space.pm"}; |
|
622 |
$path =~ s/\.pm$//; |
|
623 |
opendir my $dh, $path |
|
624 |
or croak qq{Can't open directory "$path": $!}; |
|
625 |
$model_infos = []; |
|
626 |
while (my $module = readdir $dh) { |
|
627 |
push @$model_infos, $module |
|
628 |
if $module =~ s/\.pm$//; |
|
629 |
} |
|
630 |
|
|
631 |
close $dh; |
|
632 |
} |
|
633 |
|
|
634 |
my $table_alias = {}; |
|
635 |
foreach my $model_info (@$model_infos) { |
|
636 |
|
|
637 |
# Model class, name, table |
|
638 |
my $model_class; |
|
639 |
my $model_name; |
|
640 |
my $model_table; |
|
641 |
if (ref $model_info eq 'HASH') { |
|
642 |
$model_class = $model_info->{class}; |
|
643 |
$model_name = $model_info->{name}; |
|
644 |
$model_table = $model_info->{table}; |
|
645 |
|
|
646 |
$model_name ||= $model_class; |
|
647 |
$model_table ||= $model_name; |
|
648 |
} |
|
649 |
else { $model_class =$model_name = $model_table = $model_info } |
|
650 |
my $mclass = "${name_space}::$model_class"; |
|
651 |
|
|
652 |
# Load |
|
653 |
croak qq{"$mclass" is invalid class name} |
|
654 |
if $mclass =~ /[^\w:]/; |
|
655 |
unless ($mclass->can('isa')) { |
|
656 |
eval "use $mclass"; |
|
657 |
croak $@ if $@; |
|
658 |
} |
|
659 |
|
|
660 |
# Instantiate |
|
661 |
my $model = $mclass->new(dbi => $self); |
|
662 |
$model->name($model_name) unless $model->name; |
|
663 |
$model->table($model_table) unless $model->table; |
|
664 |
|
|
665 |
# Set |
|
666 |
$self->model($model->name, $model); |
|
667 |
|
|
668 |
# Apply filter |
|
669 |
croak "${name_space}::$model_class filter must be array reference" |
|
670 |
unless ref $model->filter eq 'ARRAY'; |
|
671 |
$self->apply_filter($model->table, @{$model->filter}); |
|
672 |
|
|
673 |
# Table alias |
|
674 |
$table_alias = {%$table_alias, %{$model->table_alias}}; |
|
675 |
|
|
676 |
# Table - Model |
|
- added EXPERIMENTAL type() ...
|
677 |
croak "Table name is duplicated" |
678 |
if exists $self->{_model_from}->{$model->table}; |
|
- added EXPERIMENTAL DBIx::C...
|
679 |
$self->{_model_from}->{$model->table} = $model->name; |
680 |
} |
|
681 |
|
|
682 |
$self->{_table_alias} = $table_alias; |
|
683 |
|
|
684 |
return $self; |
|
685 |
} |
|
686 | ||
cleanup
|
687 |
sub method { |
688 |
my $self = shift; |
|
689 |
|
|
690 |
# Merge |
|
691 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
692 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
693 |
|
|
694 |
return $self; |
|
695 |
} |
|
696 | ||
- added EXPERIMENTAL DBIx::C...
|
697 |
sub model { |
698 |
my ($self, $name, $model) = @_; |
|
699 |
|
|
700 |
# Set |
|
701 |
if ($model) { |
|
702 |
$self->models->{$name} = $model; |
|
703 |
return $self; |
|
704 |
} |
|
705 |
|
|
706 |
# Check model existance |
|
707 |
croak qq{Model "$name" is not included} |
|
708 |
unless $self->models->{$name}; |
|
709 |
|
|
710 |
# Get |
|
711 |
return $self->models->{$name}; |
|
712 |
} |
|
713 | ||
cleanup
|
714 |
sub mycolumn { |
715 |
my ($self, $table, $columns) = @_; |
|
716 |
|
|
717 |
$columns ||= []; |
|
718 |
my @column; |
|
719 |
push @column, "$table.$_ as $_" for @$columns; |
|
720 |
|
|
721 |
return join (', ', @column); |
|
722 |
} |
|
723 | ||
added dbi_options attribute
|
724 |
sub new { |
725 |
my $self = shift->SUPER::new(@_); |
|
726 |
|
|
727 |
# Check attribute names |
|
728 |
my @attrs = keys %$self; |
|
729 |
foreach my $attr (@attrs) { |
|
730 |
croak qq{"$attr" is invalid attribute name} |
|
731 |
unless $self->can($attr); |
|
732 |
} |
|
cleanup
|
733 | |
734 |
$self->register_tag( |
|
735 |
'?' => \&DBIx::Custom::Tag::placeholder, |
|
736 |
'=' => \&DBIx::Custom::Tag::equal, |
|
737 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
738 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
739 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
740 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
741 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
742 |
'like' => \&DBIx::Custom::Tag::like, |
|
743 |
'in' => \&DBIx::Custom::Tag::in, |
|
744 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
745 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
746 |
); |
|
added dbi_options attribute
|
747 |
|
748 |
return $self; |
|
749 |
} |
|
750 | ||
added experimental not_exist...
|
751 |
sub not_exists { bless {}, 'DBIx::Custom::NotExists' } |
752 | ||
cleanup
|
753 |
sub register_filter { |
754 |
my $invocant = shift; |
|
755 |
|
|
756 |
# Register filter |
|
757 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
758 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
759 |
|
|
760 |
return $invocant; |
|
761 |
} |
|
packaging one directory
|
762 | |
renamed DBIx::Custom::TagPro...
|
763 |
sub register_tag { shift->query_builder->register_tag(@_) } |
added register_tag_processor
|
764 | |
cleanup
|
765 |
our %SELECT_ARGS |
cleanup
|
766 |
= map { $_ => 1 } @COMMON_ARGS, qw/column where append relation |
767 |
selection join/; |
|
refactoring select
|
768 | |
packaging one directory
|
769 |
sub select { |
select, insert, update, upda...
|
770 |
my ($self, %args) = @_; |
packaging one directory
|
771 |
|
cleanup
|
772 |
# Check argument names |
select, insert, update, upda...
|
773 |
foreach my $name (keys %args) { |
cleanup
|
774 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
775 |
unless $SELECT_ARGS{$name}; |
refactoring select
|
776 |
} |
packaging one directory
|
777 |
|
refactoring select
|
778 |
# Arguments |
cleanup
|
779 |
my $table = delete $args{table}; |
added table not specified ex...
|
780 |
my $tables = ref $table eq 'ARRAY' ? $table |
781 |
: defined $table ? [$table] |
|
782 |
: []; |
|
cleanup
|
783 |
my $columns = delete $args{column}; |
784 |
my $selection = delete $args{selection} || ''; |
|
785 |
my $where = delete $args{where} || {}; |
|
786 |
my $append = delete $args{append}; |
|
787 |
my $join = delete $args{join} || []; |
|
- added experimental DBIx::C...
|
788 |
croak qq{"join" must be array reference} |
789 |
unless ref $join eq 'ARRAY'; |
|
cleanup
|
790 |
my $relation = delete $args{relation}; |
remove experimental DBIx::Cu...
|
791 |
|
cleanup
|
792 |
# Add relation tables(DEPRECATED!); |
cleanup
|
793 |
$self->_add_relation_table($tables, $relation); |
packaging one directory
|
794 |
|
cleanup
|
795 |
# SQL stack |
796 |
my @sql; |
|
797 |
push @sql, 'select'; |
|
packaging one directory
|
798 |
|
cleanup
|
799 |
# Selection |
fixed some select() join opi...
|
800 |
if ($selection) { |
add experimental selection o...
|
801 |
push @sql, $selection; |
fixed some select() join opi...
|
802 |
if ($selection =~ /from\s+(?:\{table\s+)?([^\s\{]+?)\b/) { |
803 |
unshift @$tables, $1; |
|
804 |
} |
|
805 |
unshift @$tables, @{$self->_tables($selection)}; |
|
add experimental selection o...
|
806 |
} |
cleanup
|
807 |
|
- added EXPERIMENTAL DBIx::C...
|
808 |
# Column clause |
809 |
elsif ($columns) { |
|
810 | ||
811 |
$columns = [$columns] if ! ref $columns; |
|
812 |
|
|
813 |
if (ref $columns eq 'HASH') { |
|
814 |
# Find tables |
|
815 |
my $main_table; |
|
816 |
my %tables; |
|
817 |
if ($columns->{table}) { |
|
818 |
foreach my $table (@{$columns->{table}}) { |
|
819 |
if (($table || '') eq $tables->[-1]) { |
|
820 |
$main_table = $table; |
|
821 |
} |
|
822 |
else { |
|
823 |
$tables{$table} = 1; |
|
824 |
} |
|
- added EXPERIMENTAL DBIx::C...
|
825 |
} |
- added EXPERIMENTAL DBIx::C...
|
826 |
} |
827 |
elsif ($columns->{all}) { |
|
828 |
$main_table = $tables->[-1] || ''; |
|
829 |
foreach my $j (@$join) { |
|
830 |
my $tables = $self->_tables($j); |
|
831 |
foreach my $table (@$tables) { |
|
832 |
$tables{$table} = 1; |
|
833 |
} |
|
- added EXPERIMENTAL DBIx::C...
|
834 |
} |
- added EXPERIMENTAL DBIx::C...
|
835 |
delete $tables{$main_table}; |
836 |
} |
|
837 |
|
|
838 |
push @sql, $columns->{prepend} if $columns->{prepend}; |
|
839 |
|
|
840 |
# Column clause of main table |
|
841 |
if ($main_table) { |
|
cleanup
|
842 |
push @sql, $self->model($main_table)->mycolumn; |
- added EXPERIMENTAL DBIx::C...
|
843 |
push @sql, ','; |
- added EXPERIMENTAL DBIx::C...
|
844 |
} |
- added EXPERIMENTAL DBIx::C...
|
845 |
|
846 |
# Column cluase of other tables |
|
847 |
foreach my $table (keys %tables) { |
|
848 |
unshift @$tables, $table; |
|
cleanup
|
849 |
push @sql, $self->model($table)->column($table); |
- added EXPERIMENTAL DBIx::C...
|
850 |
push @sql, ','; |
851 |
} |
|
852 |
pop @sql if $sql[-1] eq ','; |
|
- added EXPERIMENTAL DBIx::C...
|
853 |
} |
854 |
else { |
|
- added EXPERIMENTAL DBIx::C...
|
855 |
foreach my $column (@$columns) { |
856 |
unshift @$tables, @{$self->_tables($column)}; |
|
857 |
push @sql, ($column, ','); |
|
add experimental selection o...
|
858 |
} |
- added EXPERIMENTAL DBIx::C...
|
859 |
pop @sql if $sql[-1] eq ','; |
added select() all_column op...
|
860 |
} |
861 |
} |
|
862 |
|
|
863 |
# "*" is default |
|
864 |
else { push @sql, '*' } |
|
865 |
|
|
866 |
# Table |
|
867 |
unless ($selection) { |
|
add experimental selection o...
|
868 |
push @sql, 'from'; |
cleanup
|
869 |
if ($relation) { |
fixed some select() join opi...
|
870 |
my $found = {}; |
871 |
foreach my $table (@$tables) { |
|
872 |
push @sql, ($table, ',') unless $found->{$table}; |
|
873 |
$found->{$table} = 1; |
|
874 |
} |
|
packaging one directory
|
875 |
} |
- added EXPERIMENTAL DBIx::C...
|
876 |
else { |
877 |
my $main_table = $tables->[-1] || ''; |
|
- added EXPERIMENTAL DBIx::C...
|
878 |
push @sql, $main_table; |
- added EXPERIMENTAL DBIx::C...
|
879 |
} |
fixed some select() join opi...
|
880 |
pop @sql if ($sql[-1] || '') eq ','; |
packaging one directory
|
881 |
} |
882 |
|
|
fixed some select() join opi...
|
883 |
# Main table |
884 |
croak "Not found table name" unless $tables->[-1]; |
|
885 |
|
|
select() where can't receive...
|
886 |
# Where |
where can recieve array refr...
|
887 |
my $w = $self->_where($where); |
888 |
$where = $w->param; |
|
select() where can't receive...
|
889 |
|
890 |
# String where |
|
891 |
my $swhere = "$w"; |
|
remove experimental DBIx::Cu...
|
892 |
|
fixed some select() join opi...
|
893 |
# Add table names in where clause |
894 |
unshift @$tables, @{$self->_tables($swhere)}; |
|
remove experimental DBIx::Cu...
|
895 |
|
fixed some select() join opi...
|
896 |
# Push join |
897 |
$self->_push_join(\@sql, $join, $tables); |
|
remove experimental DBIx::Cu...
|
898 |
|
cleanup
|
899 |
# Add where clause |
cleanup
|
900 |
push @sql, $swhere; |
select() where can't receive...
|
901 |
|
cleanup
|
902 |
# Relation(DEPRECATED!); |
cleanup
|
903 |
$self->_push_relation(\@sql, $tables, $relation, $swhere eq '' ? 1 : 0); |
cleanup
|
904 |
|
cleanup
|
905 |
# Append statement |
906 |
push @sql, $append if $append; |
|
907 |
|
|
908 |
# SQL |
|
909 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
910 |
|
added experimental sugar met...
|
911 |
# Create query |
cleanup
|
912 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
913 |
return $query if $args{query}; |
914 |
|
|
packaging one directory
|
915 |
# Execute query |
added auto_filter method
|
916 |
my $result = $self->execute( |
cleanup
|
917 |
$query, |
918 |
param => $where, |
|
919 |
table => $tables, |
|
920 |
%args |
|
921 |
); |
|
packaging one directory
|
922 |
|
923 |
return $result; |
|
924 |
} |
|
925 | ||
cleanup
|
926 |
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1); |
add experimental update_at()...
|
927 | |
928 |
sub select_at { |
|
929 |
my ($self, %args) = @_; |
|
930 |
|
|
cleanup
|
931 |
# Check argument names |
add experimental update_at()...
|
932 |
foreach my $name (keys %args) { |
cleanup
|
933 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
934 |
unless $SELECT_AT_ARGS{$name}; |
add experimental update_at()...
|
935 |
} |
936 |
|
|
937 |
# Primary key |
|
938 |
my $primary_keys = delete $args{primary_key}; |
|
939 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
940 |
|
|
DBIx::Custom::Model select()...
|
941 |
# Table |
942 |
croak qq{"table" option must be specified} unless $args{table}; |
|
943 |
my $table = ref $args{table} ? $args{table}->[-1] : $args{table}; |
|
944 |
|
|
add experimental update_at()...
|
945 |
# Where clause |
946 |
my $where = {}; |
|
947 |
if (exists $args{where}) { |
|
948 |
my $where_columns = delete $args{where}; |
|
- added experimental DBIx::C...
|
949 |
|
950 |
croak qq{"where" must be constant value or array reference} |
|
951 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
952 |
|
|
add experimental update_at()...
|
953 |
$where_columns = [$where_columns] unless ref $where_columns; |
954 |
|
|
955 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
DBIx::Custom::Model select()...
|
956 |
$where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i]; |
add experimental update_at()...
|
957 |
} |
958 |
} |
|
- added experimental DBIx::C...
|
959 |
|
960 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
961 |
my $param = delete $args{param}; |
962 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
963 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
964 |
} |
965 |
} |
|
966 |
|
|
967 |
return $self->select(where => $where, %args); |
|
968 |
} |
|
969 | ||
add experimental setup_model...
|
970 |
sub setup_model { |
971 |
my $self = shift; |
|
972 |
|
|
973 |
$self->each_column( |
|
974 |
sub { |
|
975 |
my ($self, $table, $column, $column_info) = @_; |
|
976 |
|
|
977 |
if (my $model = $self->models->{$table}) { |
|
978 |
push @{$model->columns}, $column; |
|
979 |
} |
|
980 |
} |
|
981 |
); |
|
add experimental DBIx::Custo...
|
982 |
return $self; |
add experimental setup_model...
|
983 |
} |
984 | ||
cleanup
|
985 |
our %UPDATE_ARGS |
986 |
= map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all/; |
|
cleanup
|
987 | |
988 |
sub update { |
|
989 |
my ($self, %args) = @_; |
|
version 0.0901
|
990 |
|
cleanup
|
991 |
# Check argument names |
cleanup
|
992 |
foreach my $name (keys %args) { |
cleanup
|
993 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
994 |
unless $UPDATE_ARGS{$name}; |
removed reconnect method
|
995 |
} |
added cache_method attribute
|
996 |
|
cleanup
|
997 |
# Arguments |
cleanup
|
998 |
my $table = delete $args{table} || ''; |
added table not specified ex...
|
999 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
1000 |
my $param = delete $args{param} || {}; |
1001 |
my $where = delete $args{where} || {}; |
|
1002 |
my $append = delete $args{append} || ''; |
|
1003 |
my $allow_update_all = delete $args{allow_update_all}; |
|
version 0.0901
|
1004 |
|
cleanup
|
1005 |
# Update keys |
select() where can't receive...
|
1006 |
my @clumns = keys %$param; |
1007 | ||
1008 |
# Columns |
|
1009 |
my @columns; |
|
- remaned experimental safty...
|
1010 |
my $safety = $self->safety_character; |
select() where can't receive...
|
1011 |
foreach my $column (keys %$param) { |
1012 |
croak qq{"$column" is not safety column name} |
|
- remaned experimental safty...
|
1013 |
unless $column =~ /^[$safety\.]+$/; |
select() where can't receive...
|
1014 |
push @columns, $column; |
1015 |
} |
|
1016 |
|
|
cleanup
|
1017 |
# Update clause |
select() where can't receive...
|
1018 |
my $update_clause = '{update_param ' . join(' ', @clumns) . '}'; |
improved delete() and update...
|
1019 | |
1020 |
# Where |
|
where can recieve array refr...
|
1021 |
my $w = $self->_where($where); |
1022 |
$where = $w->param; |
|
removed reconnect method
|
1023 |
|
select() where can't receive...
|
1024 |
# String where |
1025 |
my $swhere = "$w"; |
|
improved delete() and update...
|
1026 |
|
1027 |
croak qq{"where" must be specified} |
|
select() where can't receive...
|
1028 |
if "$swhere" eq '' && !$allow_update_all; |
removed reconnect method
|
1029 |
|
cleanup
|
1030 |
# SQL stack |
1031 |
my @sql; |
|
1032 |
|
|
1033 |
# Update |
|
1034 |
push @sql, "update $table $update_clause $swhere"; |
|
1035 |
push @sql, $append if $append; |
|
removed reconnect method
|
1036 |
|
cleanup
|
1037 |
# Rearrange parameters |
improved delete() and update...
|
1038 |
foreach my $wkey (keys %$where) { |
removed reconnect method
|
1039 |
|
cleanup
|
1040 |
if (exists $param->{$wkey}) { |
1041 |
$param->{$wkey} = [$param->{$wkey}] |
|
1042 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
1043 |
|
|
1044 |
push @{$param->{$wkey}}, $where->{$wkey}; |
|
1045 |
} |
|
1046 |
else { |
|
1047 |
$param->{$wkey} = $where->{$wkey}; |
|
1048 |
} |
|
removed reconnect method
|
1049 |
} |
cleanup
|
1050 |
|
cleanup
|
1051 |
# SQL |
1052 |
my $sql = join(' ', @sql); |
|
1053 |
|
|
added experimental sugar met...
|
1054 |
# Create query |
cleanup
|
1055 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
1056 |
return $query if $args{query}; |
1057 |
|
|
cleanup
|
1058 |
# Execute query |
cleanup
|
1059 |
my $ret_val = $self->execute( |
1060 |
$query, |
|
1061 |
param => $param, |
|
1062 |
table => $table, |
|
1063 |
%args |
|
1064 |
); |
|
cleanup
|
1065 |
|
1066 |
return $ret_val; |
|
removed reconnect method
|
1067 |
} |
1068 | ||
cleanup
|
1069 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
1070 | ||
cleanup
|
1071 |
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1); |
add experimental update_at()...
|
1072 | |
1073 |
sub update_at { |
|
1074 |
my ($self, %args) = @_; |
|
1075 |
|
|
cleanup
|
1076 |
# Check argument names |
add experimental update_at()...
|
1077 |
foreach my $name (keys %args) { |
cleanup
|
1078 |
croak qq{Argument "$name" is invalid name} |
cleanup
|
1079 |
unless $UPDATE_AT_ARGS{$name}; |
add experimental update_at()...
|
1080 |
} |
1081 |
|
|
1082 |
# Primary key |
|
1083 |
my $primary_keys = delete $args{primary_key}; |
|
1084 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
1085 |
|
|
1086 |
# Where clause |
|
1087 |
my $where = {}; |
|
1088 |
my $param = {}; |
|
1089 |
|
|
1090 |
if (exists $args{where}) { |
|
1091 |
my $where_columns = delete $args{where}; |
|
1092 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
- added experimental DBIx::C...
|
1093 | |
1094 |
croak qq{"where" must be constant value or array reference} |
|
1095 |
unless !ref $where_columns || ref $where_columns eq 'ARRAY'; |
|
add experimental update_at()...
|
1096 |
|
1097 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
1098 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
1099 |
} |
|
1100 |
} |
|
- added experimental DBIx::C...
|
1101 |
|
1102 |
if (exists $args{param}) { |
|
add experimental update_at()...
|
1103 |
$param = delete $args{param}; |
1104 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
- added experimental DBIx::C...
|
1105 |
delete $param->{$primary_keys->[$i]}; |
add experimental update_at()...
|
1106 |
} |
1107 |
} |
|
1108 |
|
|
1109 |
return $self->update(where => $where, param => $param, %args); |
|
1110 |
} |
|
1111 | ||
remove experimental DBIx::Cu...
|
1112 |
sub update_param { |
1113 |
my ($self, $param) = @_; |
|
1114 |
|
|
added experimental update_pa...
|
1115 |
# Update parameter tag |
remove experimental DBIx::Cu...
|
1116 |
my @tag; |
1117 |
push @tag, '{update_param'; |
|
- remaned experimental safty...
|
1118 |
my $safety = $self->safety_character; |
remove experimental DBIx::Cu...
|
1119 |
foreach my $column (keys %$param) { |
added experimental update_pa...
|
1120 |
croak qq{"$column" is not safety column name} |
- remaned experimental safty...
|
1121 |
unless $column =~ /^[$safety\.]+$/; |
remove experimental DBIx::Cu...
|
1122 |
push @tag, $column; |
1123 |
} |
|
1124 |
push @tag, '}'; |
|
1125 |
|
|
1126 |
return join ' ', @tag; |
|
1127 |
} |
|
1128 | ||
cleanup
|
1129 |
sub where { |
select() where can't receive...
|
1130 |
my $self = shift; |
1131 | ||
1132 |
return DBIx::Custom::Where->new( |
|
1133 |
query_builder => $self->query_builder, |
|
- remaned experimental safty...
|
1134 |
safety_character => $self->safety_character, |
cleanup
|
1135 |
@_ |
select() where can't receive...
|
1136 |
); |
cleanup
|
1137 |
} |
added experimental DBIx::Cus...
|
1138 | |
added experimental not_exist...
|
1139 |
sub _bind { |
- added EXPERIMENTAL type() ...
|
1140 |
my ($self, $params, $columns, $filter, $type) = @_; |
removed reconnect method
|
1141 |
|
cleanup
|
1142 |
# bind values |
- added EXPERIMENTAL type() ...
|
1143 |
my $bind = []; |
add tests
|
1144 |
|
removed reconnect method
|
1145 |
# Build bind values |
1146 |
my $count = {}; |
|
added experimental not_exist...
|
1147 |
my $not_exists = {}; |
cleanup
|
1148 |
foreach my $column (@$columns) { |
removed reconnect method
|
1149 |
|
1150 |
# Value |
|
added experimental not_exist...
|
1151 |
my $value; |
1152 |
if(ref $params->{$column} eq 'ARRAY') { |
|
1153 |
my $i = $count->{$column} || 0; |
|
1154 |
$i += $not_exists->{$column} || 0; |
|
1155 |
my $found; |
|
1156 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
1157 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
1158 |
$not_exists->{$column}++; |
|
1159 |
} |
|
1160 |
else { |
|
1161 |
$value = $params->{$column}->[$k]; |
|
1162 |
$found = 1; |
|
1163 |
last |
|
1164 |
} |
|
1165 |
} |
|
1166 |
next unless $found; |
|
1167 |
} |
|
1168 |
else { $value = $params->{$column} } |
|
removed reconnect method
|
1169 |
|
cleanup
|
1170 |
# Filter |
1171 |
my $f = $filter->{$column} || $self->{default_out_filter} || ''; |
|
cleanup
|
1172 |
|
- added EXPERIMENTAL type() ...
|
1173 |
# Type |
1174 |
push @$bind, { |
|
1175 |
value => $f ? $f->($value) : $value, |
|
1176 |
type => $type->{$column} |
|
1177 |
}; |
|
removed reconnect method
|
1178 |
|
1179 |
# Count up |
|
1180 |
$count->{$column}++; |
|
1181 |
} |
|
1182 |
|
|
- added EXPERIMENTAL type() ...
|
1183 |
return $bind; |
removed reconnect method
|
1184 |
} |
1185 | ||
EXPERIMETAL fork safety impl...
|
1186 |
sub _connect { |
1187 |
my $self = shift; |
|
1188 |
|
|
1189 |
# Attributes |
|
1190 |
my $data_source = $self->data_source; |
|
1191 |
croak qq{"data_source" must be specified to connect()"} |
|
1192 |
unless $data_source; |
|
1193 |
my $user = $self->user; |
|
1194 |
my $password = $self->password; |
|
1195 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
|
1196 |
|
|
1197 |
# Connect |
|
1198 |
my $dbh = eval {DBI->connect( |
|
1199 |
$data_source, |
|
1200 |
$user, |
|
1201 |
$password, |
|
1202 |
{ |
|
1203 |
%{$self->default_dbi_option}, |
|
1204 |
%$dbi_option |
|
1205 |
} |
|
1206 |
)}; |
|
1207 |
|
|
1208 |
# Connect error |
|
1209 |
croak $@ if $@; |
|
1210 |
|
|
1211 |
return $dbh; |
|
1212 |
} |
|
1213 | ||
cleanup
|
1214 |
sub _croak { |
1215 |
my ($self, $error, $append) = @_; |
|
1216 |
$append ||= ""; |
|
1217 |
|
|
1218 |
# Verbose |
|
1219 |
if ($Carp::Verbose) { croak $error } |
|
1220 |
|
|
1221 |
# Not verbose |
|
1222 |
else { |
|
1223 |
|
|
1224 |
# Remove line and module infromation |
|
1225 |
my $at_pos = rindex($error, ' at '); |
|
1226 |
$error = substr($error, 0, $at_pos); |
|
1227 |
$error =~ s/\s+$//; |
|
1228 |
|
|
1229 |
croak "$error$append"; |
|
1230 |
} |
|
1231 |
} |
|
1232 | ||
added select() all_column op...
|
1233 |
sub _need_tables { |
1234 |
my ($self, $tree, $need_tables, $tables) = @_; |
|
1235 |
|
|
1236 |
foreach my $table (@$tables) { |
|
1237 |
|
|
1238 |
if ($tree->{$table}) { |
|
1239 |
$need_tables->{$table} = 1; |
|
1240 |
$self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}]) |
|
1241 |
} |
|
1242 |
} |
|
1243 |
} |
|
1244 | ||
remove experimental DBIx::Cu...
|
1245 |
sub _tables { |
1246 |
my ($self, $source) = @_; |
|
1247 |
|
|
1248 |
my $tables = []; |
|
1249 |
|
|
- remaned experimental safty...
|
1250 |
my $safety_character = $self->safety_character; |
remove experimental DBIx::Cu...
|
1251 |
|
- remaned experimental safty...
|
1252 |
while ($source =~ /\b($safety_character+)\./g) { |
remove experimental DBIx::Cu...
|
1253 |
push @$tables, $1; |
1254 |
} |
|
1255 |
|
|
1256 |
return $tables; |
|
1257 |
} |
|
1258 | ||
fixed some select() join opi...
|
1259 |
sub _push_join { |
1260 |
my ($self, $sql, $join, $join_tables) = @_; |
|
1261 |
|
|
1262 |
return unless @$join; |
|
1263 |
|
|
1264 |
my $tree = {}; |
|
1265 |
|
|
1266 |
for (my $i = 0; $i < @$join; $i++) { |
|
1267 |
|
|
1268 |
my $join_clause = $join->[$i]; |
|
1269 |
|
|
- added experimental DBIx::C...
|
1270 |
if ($join_clause =~ /\s([^\.\s]+?)\..+\s([^\.\s]+?)\..+?$/) { |
fixed some select() join opi...
|
1271 |
|
1272 |
my $table1 = $1; |
|
1273 |
my $table2 = $2; |
|
1274 |
|
|
1275 |
croak qq{right side table of "$join_clause" must be uniq} |
|
1276 |
if exists $tree->{$table2}; |
|
1277 |
|
|
1278 |
$tree->{$table2} |
|
1279 |
= {position => $i, parent => $table1, join => $join_clause}; |
|
1280 |
} |
|
1281 |
else { |
|
1282 |
croak qq{join "$join_clause" must be two table name}; |
|
1283 |
} |
|
1284 |
} |
|
1285 |
|
|
1286 |
my $need_tables = {}; |
|
1287 |
$self->_need_tables($tree, $need_tables, $join_tables); |
|
1288 |
|
|
1289 |
my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables; |
|
cleanup
|
1290 | |
fixed some select() join opi...
|
1291 |
foreach my $need_table (@need_tables) { |
1292 |
push @$sql, $tree->{$need_table}{join}; |
|
1293 |
} |
|
1294 |
} |
|
cleanup
|
1295 | |
where can recieve array refr...
|
1296 |
sub _where { |
1297 |
my ($self, $where) = @_; |
|
1298 |
|
|
1299 |
my $w; |
|
1300 |
if (ref $where eq 'HASH') { |
|
1301 |
my $clause = ['and']; |
|
1302 |
push @$clause, "{= $_}" for keys %$where; |
|
1303 |
$w = $self->where(clause => $clause, param => $where); |
|
1304 |
} |
|
1305 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
|
1306 |
$w = $where; |
|
1307 |
} |
|
1308 |
elsif (ref $where eq 'ARRAY') { |
|
1309 |
$w = $self->where( |
|
1310 |
clause => $where->[0], |
|
1311 |
param => $where->[1] |
|
1312 |
); |
|
1313 |
} |
|
1314 |
|
|
1315 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} . |
|
1316 |
qq{or array reference, which contains where clause and paramter} |
|
1317 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
1318 |
|
|
1319 |
return $w; |
|
1320 |
} |
|
1321 | ||
cleanup
|
1322 |
# DEPRECATED! |
cleanup
|
1323 |
__PACKAGE__->attr( |
1324 |
dbi_options => sub { {} }, |
|
1325 |
filter_check => 1 |
|
1326 |
); |
|
renamed dbi_options to dbi_o...
|
1327 | |
cleanup
|
1328 |
# DEPRECATED! |
cleanup
|
1329 |
sub default_bind_filter { |
1330 |
my $self = shift; |
|
1331 |
|
|
1332 |
if (@_) { |
|
1333 |
my $fname = $_[0]; |
|
1334 |
|
|
1335 |
if (@_ && !$fname) { |
|
1336 |
$self->{default_out_filter} = undef; |
|
1337 |
} |
|
1338 |
else { |
|
many changed
|
1339 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1340 |
unless exists $self->filters->{$fname}; |
1341 |
|
|
1342 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1343 |
} |
|
1344 |
return $self; |
|
1345 |
} |
|
1346 |
|
|
1347 |
return $self->{default_out_filter}; |
|
1348 |
} |
|
1349 | ||
cleanup
|
1350 |
# DEPRECATED! |
cleanup
|
1351 |
sub default_fetch_filter { |
1352 |
my $self = shift; |
|
1353 |
|
|
1354 |
if (@_) { |
|
many changed
|
1355 |
my $fname = $_[0]; |
1356 | ||
cleanup
|
1357 |
if (@_ && !$fname) { |
1358 |
$self->{default_in_filter} = undef; |
|
1359 |
} |
|
1360 |
else { |
|
many changed
|
1361 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1362 |
unless exists $self->filters->{$fname}; |
1363 |
|
|
1364 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1365 |
} |
|
1366 |
|
|
1367 |
return $self; |
|
1368 |
} |
|
1369 |
|
|
many changed
|
1370 |
return $self->{default_in_filter}; |
cleanup
|
1371 |
} |
1372 | ||
cleanup
|
1373 |
# DEPRECATED! |
renamed DBIx::Custom::TagPro...
|
1374 |
sub register_tag_processor { |
1375 |
return shift->query_builder->register_tag_processor(@_); |
|
1376 |
} |
|
1377 | ||
cleanup
|
1378 |
# DEPRECATED! |
1379 |
sub _push_relation { |
|
1380 |
my ($self, $sql, $tables, $relation, $need_where) = @_; |
|
1381 |
|
|
1382 |
if (keys %{$relation || {}}) { |
|
1383 |
push @$sql, $need_where ? 'where' : 'and'; |
|
1384 |
foreach my $rcolumn (keys %$relation) { |
|
1385 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1386 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1387 |
push @$tables, ($table1, $table2); |
|
1388 |
push @$sql, ("$rcolumn = " . $relation->{$rcolumn}, 'and'); |
|
1389 |
} |
|
1390 |
} |
|
1391 |
pop @$sql if $sql->[-1] eq 'and'; |
|
1392 |
} |
|
1393 | ||
1394 |
# DEPRECATED! |
|
1395 |
sub _add_relation_table { |
|
cleanup
|
1396 |
my ($self, $tables, $relation) = @_; |
cleanup
|
1397 |
|
1398 |
if (keys %{$relation || {}}) { |
|
1399 |
foreach my $rcolumn (keys %$relation) { |
|
1400 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1401 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1402 |
my $table1_exists; |
|
1403 |
my $table2_exists; |
|
1404 |
foreach my $table (@$tables) { |
|
1405 |
$table1_exists = 1 if $table eq $table1; |
|
1406 |
$table2_exists = 1 if $table eq $table2; |
|
1407 |
} |
|
1408 |
unshift @$tables, $table1 unless $table1_exists; |
|
1409 |
unshift @$tables, $table2 unless $table2_exists; |
|
1410 |
} |
|
1411 |
} |
|
1412 |
} |
|
1413 | ||
fixed DBIx::Custom::QueryBui...
|
1414 |
1; |
1415 | ||
removed reconnect method
|
1416 |
=head1 NAME |
1417 | ||
- remaned experimental safty...
|
1418 |
DBIx::Custom - Useful database access, respecting SQL! |
removed reconnect method
|
1419 | |
1420 |
=head1 SYNOPSYS |
|
cleanup
|
1421 | |
renamed build_query to creat...
|
1422 |
use DBIx::Custom; |
- remaned experimental safty...
|
1423 |
|
1424 |
# Connect |
|
1425 |
my $dbi = DBIx::Custom->connect( |
|
1426 |
data_source => "dbi:mysql:database=dbname", |
|
1427 |
user => 'ken', |
|
1428 |
password => '!LFKD%$&', |
|
1429 |
dbi_option => {mysql_enable_utf8 => 1} |
|
1430 |
); |
|
cleanup
|
1431 | |
removed reconnect method
|
1432 |
# Insert |
- remaned experimental safty...
|
1433 |
$dbi->insert( |
1434 |
table => 'book', |
|
1435 |
param => {title => 'Perl', author => 'Ken'} |
|
1436 |
); |
|
removed reconnect method
|
1437 |
|
1438 |
# Update |
|
- remaned experimental safty...
|
1439 |
$dbi->update( |
1440 |
table => 'book', |
|
1441 |
param => {title => 'Perl', author => 'Ken'}, |
|
1442 |
where => {id => 5}, |
|
1443 |
); |
|
removed reconnect method
|
1444 |
|
1445 |
# Delete |
|
- remaned experimental safty...
|
1446 |
$dbi->delete( |
1447 |
table => 'book', |
|
1448 |
where => {author => 'Ken'}, |
|
1449 |
); |
|
cleanup
|
1450 | |
removed reconnect method
|
1451 |
# Select |
renamed fetch_rows to fetch_...
|
1452 |
my $result = $dbi->select( |
added insert, update, update...
|
1453 |
table => 'book', |
update document
|
1454 |
where => {author => 'Ken'}, |
added commit method
|
1455 |
); |
cleanup
|
1456 | |
- remaned experimental safty...
|
1457 |
# Select, more complex |
1458 |
my $result = $dbi->select( |
|
1459 |
table => 'book', |
|
1460 |
column => [ |
|
1461 |
'book.author as book__author', |
|
1462 |
'company.name as company__name' |
|
1463 |
], |
|
1464 |
where => {'book.author' => 'Ken'}, |
|
1465 |
join => ['left outer join company on book.company_id = company.id'], |
|
1466 |
append => 'order by id limit 5' |
|
removed reconnect method
|
1467 |
); |
- remaned experimental safty...
|
1468 |
|
removed register_format()
|
1469 |
# Fetch |
1470 |
while (my $row = $result->fetch) { |
|
- remaned experimental safty...
|
1471 |
|
removed register_format()
|
1472 |
} |
1473 |
|
|
- remaned experimental safty...
|
1474 |
# Fetch as hash |
removed register_format()
|
1475 |
while (my $row = $result->fetch_hash) { |
1476 |
|
|
1477 |
} |
|
1478 |
|
|
- remaned experimental safty...
|
1479 |
# Execute SQL with parameter. |
1480 |
$dbi->execute( |
|
1481 |
"select id from book where {= author} and {like title}", |
|
1482 |
param => {author => 'ken', title => '%Perl%'} |
|
1483 |
); |
|
1484 |
|
|
renamed update tag to update...
|
1485 |
=head1 DESCRIPTIONS |
removed reconnect method
|
1486 | |
- remaned experimental safty...
|
1487 |
L<DBIx::Custom> is L<DBI> wrapper module. |
1488 | ||
1489 |
=head1 FEATURES |
|
removed reconnect method
|
1490 | |
- remaned experimental safty...
|
1491 |
=over 4 |
removed reconnect method
|
1492 | |
- remaned experimental safty...
|
1493 |
=item * |
removed reconnect method
|
1494 | |
- remaned experimental safty...
|
1495 |
There are many basic methods to execute various queries. |
1496 |
C<insert()>, C<update()>, C<update_all()>,C<delete()>, |
|
1497 |
C<delete_all()>, C<select()>, |
|
1498 |
C<insert_at()>, C<update_at()>, |
|
1499 |
C<delete_at()>, C<select_at()>, C<execute()> |
|
removed reconnect method
|
1500 | |
- remaned experimental safty...
|
1501 |
=item * |
1502 | ||
1503 |
Filter when data is send or receive. |
|
1504 | ||
1505 |
=item * |
|
1506 | ||
1507 |
Data filtering system |
|
1508 | ||
1509 |
=item * |
|
1510 | ||
1511 |
Model support. |
|
1512 | ||
1513 |
=item * |
|
1514 | ||
1515 |
Generate where clause dinamically. |
|
1516 | ||
1517 |
=item * |
|
1518 | ||
1519 |
Generate join clause dinamically. |
|
1520 | ||
1521 |
=back |
|
pod fix
|
1522 | |
1523 |
=head1 GUIDE |
|
1524 | ||
- remaned experimental safty...
|
1525 |
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide |
pod fix
|
1526 | |
- remaned experimental safty...
|
1527 |
=head1 Wiki |
pod fix
|
1528 | |
- remaned experimental safty...
|
1529 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> |
updated document
|
1530 | |
update document
|
1531 |
=head1 ATTRIBUTES |
packaging one directory
|
1532 | |
cleanup
|
1533 |
=head2 C<cache> |
packaging one directory
|
1534 | |
cleanup
|
1535 |
my $cache = $dbi->cache; |
1536 |
$dbi = $dbi->cache(1); |
|
removed DESTROY method(not b...
|
1537 | |
update pod
|
1538 |
Enable caching L<DBIx::Custom::Query>, |
- remaned experimental safty...
|
1539 |
default to 1. |
packaging one directory
|
1540 | |
removed DBIx::Custom commit ...
|
1541 |
=head2 C<data_source> |
packaging one directory
|
1542 | |
cleanup
|
1543 |
my $data_source = $dbi->data_source; |
cleanup
|
1544 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1545 | |
- remaned experimental safty...
|
1546 |
Data source, used when C<connect()> is executed. |
removed DESTROY method(not b...
|
1547 | |
renamed dbi_options to dbi_o...
|
1548 |
=head2 C<dbi_option> |
added dbi_options attribute
|
1549 | |
renamed dbi_options to dbi_o...
|
1550 |
my $dbi_option = $dbi->dbi_option; |
- remaned experimental safty...
|
1551 |
$dbi = $dbi->dbi_option($dbi_option); |
add default_dbi_option()
|
1552 | |
- remaned experimental safty...
|
1553 |
L<DBI> option, used when C<connect()> is executed. |
1554 |
Each value in option override the value of C<default_dbi_option>. |
|
add default_dbi_option()
|
1555 | |
1556 |
=head2 C<default_dbi_option> |
|
1557 | ||
1558 |
my $default_dbi_option = $dbi->default_dbi_option; |
|
1559 |
$dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1560 | ||
- remaned experimental safty...
|
1561 |
L<DBI> default option, used when C<connect()> is executed, |
1562 |
default to the following values. |
|
add default_dbi_option()
|
1563 | |
- remaned experimental safty...
|
1564 |
{ |
1565 |
RaiseError => 1, |
|
1566 |
PrintError => 0, |
|
1567 |
AutoCommit => 1, |
|
1568 |
} |
|
packaging one directory
|
1569 | |
update pod
|
1570 |
You should not change C<AutoCommit> value directly, |
1571 |
the value is used to check if the process is in transaction. |
|
EXPERIMETAL fork safety impl...
|
1572 | |
cleanup
|
1573 |
=head2 C<filters> |
bind_filter argument is chan...
|
1574 | |
cleanup
|
1575 |
my $filters = $dbi->filters; |
1576 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
1577 | |
- remaned experimental safty...
|
1578 |
Filters, registered by C<register_filter()>. |
add models() attribute
|
1579 | |
update pod
|
1580 |
=head2 C<models> EXPERIMENTAL |
add models() attribute
|
1581 | |
1582 |
my $models = $dbi->models; |
|
1583 |
$dbi = $dbi->models(\%models); |
|
1584 | ||
- remaned experimental safty...
|
1585 |
Models, included by C<include_model()>. |
add models() attribute
|
1586 | |
cleanup
|
1587 |
=head2 C<password> |
1588 | ||
1589 |
my $password = $dbi->password; |
|
1590 |
$dbi = $dbi->password('lkj&le`@s'); |
|
1591 | ||
- remaned experimental safty...
|
1592 |
Password, used when C<connect()> is executed. |
update document
|
1593 | |
renamed update tag to update...
|
1594 |
=head2 C<query_builder> |
added commit method
|
1595 | |
renamed update tag to update...
|
1596 |
my $sql_class = $dbi->query_builder; |
1597 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1598 | |
- remaned experimental safty...
|
1599 |
Query builder, default to L<DBIx::Custom::QueryBuilder> object. |
cleanup
|
1600 | |
cleanup
|
1601 |
=head2 C<result_class> |
cleanup
|
1602 | |
cleanup
|
1603 |
my $result_class = $dbi->result_class; |
1604 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
1605 | |
- remaned experimental safty...
|
1606 |
Result class, default to L<DBIx::Custom::Result>. |
cleanup
|
1607 | |
update pod
|
1608 |
=head2 C<safety_character> EXPERIMENTAL |
update pod
|
1609 | |
- remaned experimental safty...
|
1610 |
my $safety_character = $self->safety_character; |
cleanup
|
1611 |
$dbi = $self->safety_character($character); |
update pod
|
1612 | |
update pod
|
1613 |
Regex of safety character for table and column name, default to '\w'. |
cleanup
|
1614 |
Note that you don't have to specify like '[\w]'. |
update pod
|
1615 | |
cleanup
|
1616 |
=head2 C<user> |
cleanup
|
1617 | |
cleanup
|
1618 |
my $user = $dbi->user; |
1619 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
1620 | |
cleanup
|
1621 |
User name, used when C<connect()> is executed. |
update pod
|
1622 | |
cleanup
|
1623 |
=head1 METHODS |
added commit method
|
1624 | |
cleanup
|
1625 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
cleanup
|
1626 |
and use all methods of L<DBI> |
cleanup
|
1627 |
and implements the following new ones. |
added check_filter attribute
|
1628 | |
update pod
|
1629 |
=head2 C<apply_filter> EXPERIMENTAL |
added auto_filter method
|
1630 | |
renamed auto_filter to apply...
|
1631 |
$dbi->apply_filter( |
cleanup
|
1632 |
'book', |
update pod
|
1633 |
'issue_date' => { |
1634 |
out => 'tp_to_date', |
|
1635 |
in => 'date_to_tp', |
|
1636 |
end => 'tp_to_displaydate' |
|
1637 |
}, |
|
1638 |
'write_date' => { |
|
1639 |
out => 'tp_to_date', |
|
1640 |
in => 'date_to_tp', |
|
1641 |
end => 'tp_to_displaydate' |
|
1642 |
} |
|
added auto_filter method
|
1643 |
); |
1644 | ||
update pod
|
1645 |
Apply filter to columns. |
1646 |
C<out> filter is executed before data is send to database. |
|
1647 |
C<in> filter is executed after a row is fetch. |
|
1648 |
C<end> filter is execute after C<in> filter is executed. |
|
1649 | ||
1650 |
Filter is applied to the follwoing tree column name pattern. |
|
cleanup
|
1651 | |
update pod
|
1652 |
PETTERN EXAMPLE |
1653 |
1. Column : author |
|
1654 |
2. Table.Column : book.author |
|
1655 |
3. Table__Column : book__author |
|
fix bug : filter can't over...
|
1656 | |
update pod
|
1657 |
If column name is duplicate with other table, |
1658 |
Main filter specified by C<table> option is used. |
|
1659 | ||
1660 |
You can set multiple filters at once. |
|
1661 | ||
1662 |
$dbi->apply_filter( |
|
1663 |
'book', |
|
1664 |
[qw/issue_date write_date/] => { |
|
1665 |
out => 'tp_to_date', |
|
1666 |
in => 'date_to_tp', |
|
1667 |
end => 'tp_to_displaydate' |
|
1668 |
} |
|
1669 |
); |
|
fix bug : filter can't over...
|
1670 | |
update pod
|
1671 |
=head2 C<cache_method> |
1672 | ||
1673 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1674 |
$cache_method = $dbi->cache_method |
|
1675 | ||
update pod
|
1676 |
Method to set and get cache. |
1677 |
Default to the following one. |
|
1678 | ||
1679 |
sub { |
|
1680 |
my $self = shift; |
|
1681 |
|
|
1682 |
$self->{_cached} ||= {}; |
|
1683 |
|
|
1684 |
if (@_ > 1) { |
|
1685 |
$self->{_cached}{$_[0]} = $_[1]; |
|
1686 |
} |
|
1687 |
else { |
|
1688 |
return $self->{_cached}{$_[0]}; |
|
1689 |
} |
|
1690 |
} |
|
update pod
|
1691 | |
removed DBIx::Custom commit ...
|
1692 |
=head2 C<connect> |
packaging one directory
|
1693 | |
update pod
|
1694 |
my $dbi = DBIx::Custom->connect( |
1695 |
data_source => "dbi:mysql:database=dbname", |
|
1696 |
user => 'ken', |
|
1697 |
password => '!LFKD%$&', |
|
1698 |
dbi_option => {mysql_enable_utf8 => 1} |
|
1699 |
); |
|
1700 | ||
1701 |
Connect to the database and create a new L<DBIx::Custom> object. |
|
bind_filter argument is chan...
|
1702 | |
renamed build_query to creat...
|
1703 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1704 |
C<AutoCommit> and C<RaiseError> options are true, |
update pod
|
1705 |
and C<PrintError> option is false by default. |
packaging one directory
|
1706 | |
cleanup
|
1707 |
=head2 C<create_query> |
1708 |
|
|
1709 |
my $query = $dbi->create_query( |
|
update pod
|
1710 |
"insert into book {insert_param title author};"; |
cleanup
|
1711 |
); |
update document
|
1712 | |
update pod
|
1713 |
Create L<DBIx::Custom::Query> object. |
1714 | ||
cleanup
|
1715 |
If you want to get high performance, |
update pod
|
1716 |
create L<DBIx::Custom::Query> object and execute the query by C<execute()> |
1717 |
instead of other methods, such as C<insert>, C<update>. |
|
bind_filter argument is chan...
|
1718 | |
cleanup
|
1719 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
1720 | |
EXPERIMETAL fork safety impl...
|
1721 |
=head2 C<dbh> |
1722 | ||
1723 |
my $dbh = $dbi->dbh; |
|
1724 |
$dbi = $dbi->dbh($dbh); |
|
1725 | ||
1726 |
Get and set database handle of L<DBI>. |
|
1727 | ||
update pod
|
1728 |
If process is spawn by forking, new connection is created automatically. |
1729 |
This feature is EXPERIMETNAL. |
|
EXPERIMETAL fork safety impl...
|
1730 | |
cleanup
|
1731 |
=head2 C<execute> |
packaging one directory
|
1732 | |
update pod
|
1733 |
my $result = $dbi->execute( |
1734 |
"select * from book where {= title} and {like author}", |
|
1735 |
param => {title => 'Perl', author => '%Ken%'} |
|
1736 |
); |
|
1737 | ||
1738 |
Execute SQL, containing tags. |
|
1739 |
Return value is L<DBIx::Custom::Result> in select statement, or |
|
1740 |
the count of affected rows in insert, update, delete statement. |
|
1741 | ||
1742 |
Tag is turned into the statement containing place holder |
|
1743 |
before SQL is executed. |
|
1744 | ||
1745 |
select * from where title = ? and author like ?; |
|
1746 | ||
1747 |
See also L<Tags/Tags>. |
|
1748 | ||
1749 |
The following opitons are currently available. |
|
1750 | ||
1751 |
=over 4 |
|
1752 | ||
1753 |
=item C<filter> |
|
1754 | ||
1755 |
Filter, executed before data is send to database. This is array reference. |
|
1756 |
Filter value is code reference or |
|
1757 |
filter name registerd by C<register_filter()>. |
|
1758 | ||
1759 |
# Basic |
|
1760 |
$dbi->execute( |
|
1761 |
$sql, |
|
1762 |
filter => [ |
|
1763 |
title => sub { uc $_[0] } |
|
1764 |
author => sub { uc $_[0] } |
|
1765 |
] |
|
1766 |
); |
|
1767 |
|
|
1768 |
# At once |
|
1769 |
$dbi->execute( |
|
1770 |
$sql, |
|
1771 |
filter => [ |
|
1772 |
[qw/title author/] => sub { uc $_[0] } |
|
1773 |
] |
|
1774 |
); |
|
1775 |
|
|
1776 |
# Filter name |
|
1777 |
$dbi->execute( |
|
1778 |
$sql, |
|
1779 |
filter => [ |
|
1780 |
title => 'upper_case', |
|
1781 |
author => 'upper_case' |
|
1782 |
] |
|
1783 |
); |
|
1784 | ||
1785 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
|
update document
|
1786 | |
update pod
|
1787 |
=back |
version 0.0901
|
1788 | |
removed DBIx::Custom commit ...
|
1789 |
=head2 C<delete> |
packaging one directory
|
1790 | |
update pod
|
1791 |
$dbi->delete(table => 'book', where => {title => 'Perl'}); |
1792 | ||
1793 |
Delete statement. |
|
1794 | ||
1795 |
The following opitons are currently available. |
|
1796 | ||
update pod
|
1797 |
=over 4 |
1798 | ||
update pod
|
1799 |
=item C<table> |
1800 | ||
1801 |
Table name. |
|
1802 | ||
1803 |
$dbi->delete(table => 'book'); |
|
1804 | ||
1805 |
=item C<where> |
|
1806 | ||
where can recieve array refr...
|
1807 |
Where clause. This is hash reference or L<DBIx::Custom::Where> object |
1808 |
or array refrence, which contains where clause and paramter. |
|
update pod
|
1809 |
|
1810 |
# Hash reference |
|
1811 |
$dbi->delete(where => {title => 'Perl'}); |
|
1812 |
|
|
1813 |
# DBIx::Custom::Where object |
|
1814 |
my $where = $dbi->where( |
|
1815 |
clause => ['and', '{= author}', '{like title}'], |
|
1816 |
param => {author => 'Ken', title => '%Perl%'} |
|
1817 |
); |
|
1818 |
$dbi->delete(where => $where); |
|
1819 | ||
where can recieve array refr...
|
1820 |
# Array refrendce (where clause and parameter) |
1821 |
$dbi->delete(where => |
|
1822 |
[ |
|
1823 |
['and', '{= author}', '{like title}'], |
|
1824 |
{author => 'Ken', title => '%Perl%'} |
|
1825 |
] |
|
1826 |
); |
|
1827 |
|
|
update pod
|
1828 |
=item C<append> |
1829 | ||
1830 |
Append statement to last of SQL. This is string. |
|
1831 | ||
1832 |
$dbi->delete(append => 'order by title'); |
|
1833 | ||
1834 |
=item C<filter> |
|
1835 | ||
1836 |
Filter, executed before data is send to database. This is array reference. |
|
1837 |
Filter value is code reference or |
|
1838 |
filter name registerd by C<register_filter()>. |
|
1839 | ||
1840 |
# Basic |
|
1841 |
$dbi->delete( |
|
1842 |
filter => [ |
|
1843 |
title => sub { uc $_[0] } |
|
1844 |
author => sub { uc $_[0] } |
|
1845 |
] |
|
1846 |
); |
|
1847 |
|
|
1848 |
# At once |
|
1849 |
$dbi->delete( |
|
1850 |
filter => [ |
|
1851 |
[qw/title author/] => sub { uc $_[0] } |
|
1852 |
] |
|
1853 |
); |
|
1854 |
|
|
1855 |
# Filter name |
|
1856 |
$dbi->delete( |
|
1857 |
filter => [ |
|
1858 |
title => 'upper_case', |
|
1859 |
author => 'upper_case' |
|
1860 |
] |
|
1861 |
); |
|
1862 | ||
1863 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
|
1864 | ||
cleanup
|
1865 |
=head2 C<column> EXPERIMENTAL |
1866 | ||
1867 |
my $column = $self->column(book => ['author', 'title']); |
|
1868 | ||
1869 |
Create column clause. The follwoing column clause is created. |
|
1870 | ||
1871 |
book.author as book__author, |
|
1872 |
book.title as book__title |
|
1873 | ||
update pod
|
1874 |
=item C<query> EXPERIMENTAL |
update pod
|
1875 | |
1876 |
Get L<DBIx::Custom::Query> object instead of executing SQL. |
|
1877 |
This is true or false value. |
|
1878 | ||
1879 |
my $query = $dbi->delete(query => 1); |
|
1880 | ||
1881 |
You can check SQL. |
|
1882 | ||
1883 |
my $sql = $query->sql; |
|
renamed build_query to creat...
|
1884 | |
update pod
|
1885 |
=back |
1886 | ||
removed DBIx::Custom commit ...
|
1887 |
=head2 C<delete_all> |
packaging one directory
|
1888 | |
cleanup
|
1889 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1890 | |
update pod
|
1891 |
Delete statement to delete all rows. |
1892 |
Options is same as C<delete()>. |
|
bind_filter argument is chan...
|
1893 | |
update pod
|
1894 |
=head2 C<delete_at()> EXPERIMENTAL |
add experimental update_at()...
|
1895 | |
update pod
|
1896 |
Delete statement, using primary key. |
add experimental update_at()...
|
1897 | |
1898 |
$dbi->delete_at( |
|
1899 |
table => 'book', |
|
update pod
|
1900 |
primary_key => 'id', |
1901 |
where => '5' |
|
add experimental update_at()...
|
1902 |
); |
1903 | ||
update pod
|
1904 |
This method is same as C<delete()> exept that |
1905 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
1906 |
all option of C<delete()> is available. |
|
add experimental update_at()...
|
1907 | |
update pod
|
1908 |
=over 4 |
1909 | ||
1910 |
=item C<primary_key> |
|
add experimental update_at()...
|
1911 | |
update pod
|
1912 |
Primary key. This is constant value or array reference. |
1913 |
|
|
1914 |
# Constant value |
|
1915 |
$dbi->delete(primary_key => 'id'); |
|
1916 | ||
1917 |
# Array reference |
|
1918 |
$dbi->delete(primary_key => ['id1', 'id2' ]); |
|
1919 | ||
1920 |
This is used to create where clause. |
|
1921 | ||
update pod
|
1922 |
=item C<where> |
update pod
|
1923 | |
1924 |
Where clause, created from primary key information. |
|
1925 |
This is constant value or array reference. |
|
1926 | ||
1927 |
# Constant value |
|
1928 |
$dbi->delete(where => 5); |
|
1929 | ||
1930 |
# Array reference |
|
1931 |
$dbi->delete(where => [3, 5]); |
|
1932 | ||
1933 |
In first examle, the following SQL is created. |
|
1934 | ||
1935 |
delete from book where id = ?; |
|
1936 | ||
1937 |
Place holder is set to 5. |
|
add experimental update_at()...
|
1938 | |
update pod
|
1939 |
=back |
1940 | ||
cleanup
|
1941 |
=head2 C<insert> |
1942 | ||
update pod
|
1943 |
$dbi->insert( |
1944 |
table => 'book', |
|
1945 |
param => {title => 'Perl', author => 'Ken'} |
|
1946 |
); |
|
1947 | ||
1948 |
Insert statement. |
|
1949 | ||
1950 |
The following opitons are currently available. |
|
1951 | ||
update pod
|
1952 |
=over 4 |
1953 | ||
update pod
|
1954 |
=item C<table> |
1955 | ||
1956 |
Table name. |
|
1957 | ||
1958 |
$dbi->insert(table => 'book'); |
|
1959 | ||
1960 |
=item C<param> |
|
1961 | ||
1962 |
Insert data. This is hash reference. |
|
1963 | ||
1964 |
$dbi->insert(param => {title => 'Perl'}); |
|
1965 | ||
1966 |
=item C<append> |
|
1967 | ||
1968 |
Append statement to last of SQL. This is string. |
|
1969 | ||
1970 |
$dbi->insert(append => 'order by title'); |
|
1971 | ||
1972 |
=item C<filter> |
|
1973 | ||
1974 |
Filter, executed before data is send to database. This is array reference. |
|
1975 |
Filter value is code reference or |
|
1976 |
filter name registerd by C<register_filter()>. |
|
1977 | ||
1978 |
# Basic |
|
1979 |
$dbi->insert( |
|
1980 |
filter => [ |
|
1981 |
title => sub { uc $_[0] } |
|
1982 |
author => sub { uc $_[0] } |
|
1983 |
] |
|
1984 |
); |
|
1985 |
|
|
1986 |
# At once |
|
1987 |
$dbi->insert( |
|
1988 |
filter => [ |
|
1989 |
[qw/title author/] => sub { uc $_[0] } |
|
1990 |
] |
|
1991 |
); |
|
1992 |
|
|
1993 |
# Filter name |
|
1994 |
$dbi->insert( |
|
1995 |
filter => [ |
|
1996 |
title => 'upper_case', |
|
1997 |
author => 'upper_case' |
|
1998 |
] |
|
1999 |
); |
|
2000 | ||
2001 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
|
2002 | ||
update pod
|
2003 |
=item C<query> EXPERIMENTAL |
update pod
|
2004 | |
2005 |
Get L<DBIx::Custom::Query> object instead of executing SQL. |
|
2006 |
This is true or false value. |
|
2007 | ||
2008 |
my $query = $dbi->insert(query => 1); |
|
cleanup
|
2009 | |
update pod
|
2010 |
You can check SQL. |
cleanup
|
2011 | |
update pod
|
2012 |
my $sql = $query->sql; |
2013 | ||
update pod
|
2014 |
=back |
2015 | ||
2016 |
=head2 C<insert_at()> EXPERIMENTAL |
|
added experimental DBIx::Cus...
|
2017 | |
update pod
|
2018 |
Insert statement, using primary key. |
added experimental DBIx::Cus...
|
2019 | |
2020 |
$dbi->insert_at( |
|
2021 |
table => 'book', |
|
update pod
|
2022 |
primary_key => 'id', |
2023 |
where => '5', |
|
2024 |
param => {title => 'Perl'} |
|
added experimental DBIx::Cus...
|
2025 |
); |
2026 | ||
update pod
|
2027 |
This method is same as C<insert()> exept that |
2028 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2029 |
all option of C<insert()> is available. |
|
2030 | ||
update pod
|
2031 |
=over 4 |
2032 | ||
2033 |
=item C<primary_key> |
|
update pod
|
2034 | |
2035 |
Primary key. This is constant value or array reference. |
|
2036 |
|
|
2037 |
# Constant value |
|
2038 |
$dbi->insert(primary_key => 'id'); |
|
2039 | ||
2040 |
# Array reference |
|
2041 |
$dbi->insert(primary_key => ['id1', 'id2' ]); |
|
2042 | ||
2043 |
This is used to create parts of insert data. |
|
2044 | ||
update pod
|
2045 |
=item C<where> |
update pod
|
2046 | |
2047 |
Parts of Insert data, create from primary key information. |
|
2048 |
This is constant value or array reference. |
|
2049 | ||
2050 |
# Constant value |
|
2051 |
$dbi->insert(where => 5); |
|
2052 | ||
2053 |
# Array reference |
|
2054 |
$dbi->insert(where => [3, 5]); |
|
2055 | ||
2056 |
In first examle, the following SQL is created. |
|
2057 | ||
2058 |
insert into book (id, title) values (?, ?); |
|
2059 | ||
2060 |
Place holders are set to 5 and 'Perl'. |
|
added experimental DBIx::Cus...
|
2061 | |
update pod
|
2062 |
=back |
2063 | ||
2064 |
=head2 C<insert_param> EXPERIMENTAL |
|
added experimental update_pa...
|
2065 | |
2066 |
my $insert_param = $dbi->insert_param({title => 'a', age => 2}); |
|
2067 | ||
2068 |
Create insert parameter tag. |
|
2069 | ||
update pod
|
2070 |
{insert_param title age} |
added experimental update_pa...
|
2071 | |
update pod
|
2072 |
=head2 C<each_column> EXPERIMENTAL |
added experimental iterate_a...
|
2073 | |
pod fix
|
2074 |
$dbi->each_column( |
added experimental iterate_a...
|
2075 |
sub { |
update pod
|
2076 |
my ($dbi, $table, $column, $column_info) = @_; |
added experimental iterate_a...
|
2077 |
|
add experimental setup_model...
|
2078 |
my $type = $column_info->{TYPE_NAME}; |
pod fix
|
2079 |
|
2080 |
if ($type eq 'DATE') { |
|
2081 |
# ... |
|
2082 |
} |
|
added experimental iterate_a...
|
2083 |
} |
2084 |
); |
|
update pod
|
2085 | |
2086 |
Iterate all column informations of all table from database. |
|
2087 |
Argument is callback when one column is found. |
|
added experimental not_exist...
|
2088 |
Callback receive four arguments, dbi object, table name, |
add experimental setup_model...
|
2089 |
column name and column information. |
added experimental not_exist...
|
2090 | |
update pod
|
2091 |
=head2 C<include_model> EXPERIMENTAL |
removed experimental base_ta...
|
2092 | |
update pod
|
2093 |
$dbi->include_model('MyModel'); |
removed experimental base_ta...
|
2094 | |
update pod
|
2095 |
Include models from specified namespace, |
2096 |
the following layout is needed to include models. |
|
removed experimental base_ta...
|
2097 | |
update pod
|
2098 |
lib / MyModel.pm |
2099 |
/ MyModel / book.pm |
|
2100 |
/ company.pm |
|
add feture. all model class ...
|
2101 | |
update pod
|
2102 |
Name space module, extending L<DBIx::Custom::Model>. |
add feture. all model class ...
|
2103 | |
update pod
|
2104 |
B<MyModel.pm> |
add feture. all model class ...
|
2105 | |
2106 |
package MyModel; |
|
2107 |
|
|
2108 |
use base 'DBIx::Custom::Model'; |
|
update pod
|
2109 |
|
2110 |
1; |
|
add feture. all model class ...
|
2111 | |
update pod
|
2112 |
Model modules, extending name space module. |
removed experimental base_ta...
|
2113 | |
update pod
|
2114 |
B<MyModel/book.pm> |
removed experimental base_ta...
|
2115 | |
update pod
|
2116 |
package MyModel::book; |
2117 |
|
|
2118 |
use base 'MyModel'; |
|
2119 |
|
|
2120 |
1; |
|
removed experimental base_ta...
|
2121 | |
update pod
|
2122 |
B<MyModel/company.pm> |
removed experimental base_ta...
|
2123 | |
update pod
|
2124 |
package MyModel::company; |
2125 |
|
|
2126 |
use base 'MyModel'; |
|
2127 |
|
|
2128 |
1; |
|
2129 |
|
|
2130 |
MyModel::book and MyModel::company is included by C<include_model()>. |
|
removed experimental base_ta...
|
2131 | |
update pod
|
2132 |
You can get model object by C<model()>. |
2133 | ||
2134 |
my $book_model = $dbi->model('book'); |
|
2135 |
my $company_model = $dbi->model('company'); |
|
removed experimental base_ta...
|
2136 | |
update pod
|
2137 |
See L<DBIx::Custom::Model> to know model features. |
2138 | ||
2139 |
=head2 C<method> EXPERIMENTAL |
|
added experimental not_exist...
|
2140 | |
2141 |
$dbi->method( |
|
2142 |
update_or_insert => sub { |
|
2143 |
my $self = shift; |
|
update pod
|
2144 |
|
2145 |
# Process |
|
added experimental not_exist...
|
2146 |
}, |
2147 |
find_or_create => sub { |
|
2148 |
my $self = shift; |
|
update pod
|
2149 |
|
2150 |
# Process |
|
added experimental not_exist...
|
2151 |
} |
2152 |
); |
|
2153 | ||
update pod
|
2154 |
Register method. These method is called directly from L<DBIx::Custom> object. |
added experimental not_exist...
|
2155 | |
2156 |
$dbi->update_or_insert; |
|
2157 |
$dbi->find_or_create; |
|
2158 | ||
update pod
|
2159 |
=head2 C<model> EXPERIMENTAL |
2160 | ||
2161 |
$dbi->model('book')->method( |
|
2162 |
insert => sub { ... }, |
|
2163 |
update => sub { ... } |
|
2164 |
); |
|
2165 |
|
|
2166 |
my $model = $dbi->model('book'); |
|
2167 | ||
2168 |
Set and get a L<DBIx::Custom::Model> object, |
|
2169 | ||
cleanup
|
2170 |
=head2 C<mycolumn> EXPERIMENTAL |
2171 | ||
2172 |
my $column = $self->mycolumn(book => ['author', 'title']); |
|
2173 | ||
2174 |
Create column clause for myself. The follwoing column clause is created. |
|
2175 | ||
2176 |
book.author as author, |
|
2177 |
book.title as title |
|
2178 | ||
added experimental not_exist...
|
2179 |
=head2 C<new> |
2180 | ||
update pod
|
2181 |
my $dbi = DBIx::Custom->new( |
2182 |
data_source => "dbi:mysql:database=dbname", |
|
2183 |
user => 'ken', |
|
2184 |
password => '!LFKD%$&', |
|
2185 |
dbi_option => {mysql_enable_utf8 => 1} |
|
2186 |
); |
|
added experimental not_exist...
|
2187 | |
2188 |
Create a new L<DBIx::Custom> object. |
|
2189 | ||
update pod
|
2190 |
=head2 C<not_exists> EXPERIMENTAL |
added experimental not_exist...
|
2191 | |
2192 |
my $not_exists = $dbi->not_exists; |
|
2193 | ||
update pod
|
2194 |
DBIx::Custom::NotExists object, indicating the column is not exists. |
2195 |
This is used by C<clause> of L<DBIx::Custom::Where> . |
|
experimental extended select...
|
2196 | |
cleanup
|
2197 |
=head2 C<register_filter> |
2198 | ||
update pod
|
2199 |
$dbi->register_filter( |
2200 |
# Time::Piece object to database DATE format |
|
2201 |
tp_to_date => sub { |
|
2202 |
my $tp = shift; |
|
2203 |
return $tp->strftime('%Y-%m-%d'); |
|
2204 |
}, |
|
2205 |
# database DATE format to Time::Piece object |
|
2206 |
date_to_tp => sub { |
|
2207 |
my $date = shift; |
|
2208 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
2209 |
} |
|
2210 |
); |
|
cleanup
|
2211 |
|
update pod
|
2212 |
Register filters, used by C<filter> option of many methods. |
cleanup
|
2213 | |
update pod
|
2214 |
=head2 C<register_tag> |
cleanup
|
2215 | |
update pod
|
2216 |
$dbi->register_tag( |
2217 |
update => sub { |
|
2218 |
my @columns = @_; |
|
2219 |
|
|
2220 |
# Update parameters |
|
2221 |
my $s = 'set '; |
|
2222 |
$s .= "$_ = ?, " for @columns; |
|
2223 |
$s =~ s/, $//; |
|
2224 |
|
|
2225 |
return [$s, \@columns]; |
|
2226 |
} |
|
2227 |
); |
|
cleanup
|
2228 | |
update pod
|
2229 |
Register tag, used by C<execute()>. |
cleanup
|
2230 | |
update pod
|
2231 |
See also L<Tags/Tags> about tag registered by default. |
cleanup
|
2232 | |
update pod
|
2233 |
Tag parser receive arguments specified in tag. |
2234 |
In the following tag, 'title' and 'author' is parser arguments |
|
cleanup
|
2235 | |
update pod
|
2236 |
{update_param title author} |
cleanup
|
2237 | |
update pod
|
2238 |
Tag parser must return array refrence, |
2239 |
first element is the result statement, |
|
2240 |
second element is column names corresponding to place holders. |
|
cleanup
|
2241 | |
update pod
|
2242 |
In this example, result statement is |
cleanup
|
2243 | |
update pod
|
2244 |
set title = ?, author = ? |
added register_tag_processor
|
2245 | |
update pod
|
2246 |
Column names is |
added register_tag_processor
|
2247 | |
update pod
|
2248 |
['title', 'author'] |
added register_tag_processor
|
2249 | |
removed DBIx::Custom commit ...
|
2250 |
=head2 C<select> |
added select() all_column op...
|
2251 | |
select method column option ...
|
2252 |
my $result = $dbi->select( |
added select() all_column op...
|
2253 |
table => 'book', |
2254 |
column => ['author', 'title'], |
|
2255 |
where => {author => 'Ken'}, |
|
select method column option ...
|
2256 |
); |
added select() all_column op...
|
2257 |
|
update pod
|
2258 |
Select statement. |
added select() all_column op...
|
2259 | |
2260 |
The following opitons are currently available. |
|
2261 | ||
2262 |
=over 4 |
|
2263 | ||
2264 |
=item C<table> |
|
2265 | ||
2266 |
Table name. |
|
2267 | ||
update pod
|
2268 |
$dbi->select(table => 'book'); |
added select() all_column op...
|
2269 | |
2270 |
=item C<column> |
|
2271 | ||
2272 |
Column clause. This is array reference or constant value. |
|
2273 | ||
2274 |
# Hash refernce |
|
2275 |
$dbi->select(column => ['author', 'title']); |
|
2276 |
|
|
2277 |
# Constant value |
|
2278 |
$dbi->select(column => 'author'); |
|
2279 | ||
2280 |
Default is '*' unless C<column> is specified. |
|
2281 | ||
2282 |
# Default |
|
2283 |
$dbi->select(column => '*'); |
|
2284 | ||
- added EXPERIMENTAL DBIx::C...
|
2285 |
You can use hash option in C<column> |
2286 | ||
2287 |
=over 4 |
|
2288 | ||
2289 |
=item all EXPERIMENTAL |
|
added select() all_column op...
|
2290 | |
update pod
|
2291 |
Colum clause, contains all columns of joined table. This is true or false value |
added select() all_column op...
|
2292 | |
- added EXPERIMENTAL DBIx::C...
|
2293 |
$dbi->select(column => {all => 1}); |
added select() all_column op...
|
2294 | |
2295 |
If main table is C<book> and joined table is C<company>, |
|
2296 |
This create the following column clause. |
|
2297 | ||
2298 |
book.author as author |
|
2299 |
book.company_id as company_id |
|
2300 |
company.id as company__id |
|
2301 |
company.name as company__name |
|
2302 | ||
2303 |
Columns of main table is consist of only column name, |
|
2304 |
Columns of joined table is consist of table and column name joined C<__>. |
|
2305 | ||
- added EXPERIMENTAL DBIx::C...
|
2306 |
Note that this option is failed unless modles is included and |
2307 |
C<columns> attribute is set. |
|
update pod
|
2308 | |
2309 |
# Generally do the following way before using all_column option |
|
2310 |
$dbi->include_model('MyModel')->setup_model; |
|
2311 | ||
- added EXPERIMENTAL DBIx::C...
|
2312 |
=item table EXPERIMENTAL |
2313 | ||
2314 |
You can also specify table names by C<table> option |
|
- added EXPERIMENTAL DBIx::C...
|
2315 | |
- added EXPERIMENTAL DBIx::C...
|
2316 |
$dbi->select(column => {table => ['book', 'company']}); |
2317 | ||
2318 |
=item prepend EXPERIMENTAL |
|
2319 | ||
2320 |
You can add before created statement |
|
2321 | ||
2322 |
$dbi->select(column => {prepend => 'SOME', all => 1}); |
|
2323 | ||
2324 |
=back |
|
- added EXPERIMENTAL DBIx::C...
|
2325 | |
added select() all_column op...
|
2326 |
=item C<where> |
2327 | ||
where can recieve array refr...
|
2328 |
Where clause. This is hash reference or L<DBIx::Custom::Where> object, |
2329 |
or array refrence, which contains where clause and paramter. |
|
added select() all_column op...
|
2330 |
|
2331 |
# Hash reference |
|
update pod
|
2332 |
$dbi->select(where => {author => 'Ken', 'title' => 'Perl'}); |
added select() all_column op...
|
2333 |
|
update pod
|
2334 |
# DBIx::Custom::Where object |
added select() all_column op...
|
2335 |
my $where = $dbi->where( |
2336 |
clause => ['and', '{= author}', '{like title}'], |
|
2337 |
param => {author => 'Ken', title => '%Perl%'} |
|
2338 |
); |
|
update pod
|
2339 |
$dbi->select(where => $where); |
added select() all_column op...
|
2340 | |
where can recieve array refr...
|
2341 |
# Array refrendce (where clause and parameter) |
2342 |
$dbi->select(where => |
|
2343 |
[ |
|
2344 |
['and', '{= author}', '{like title}'], |
|
2345 |
{author => 'Ken', title => '%Perl%'} |
|
2346 |
] |
|
2347 |
); |
|
2348 |
|
|
update pod
|
2349 |
=item C<join> EXPERIMENTAL |
added select() all_column op...
|
2350 | |
update pod
|
2351 |
Join clause used in need. This is array reference. |
2352 | ||
2353 |
$dbi->select(join => |
|
2354 |
[ |
|
2355 |
'left outer join company on book.company_id = company_id', |
|
2356 |
'left outer join location on company.location_id = location.id' |
|
2357 |
] |
|
2358 |
); |
|
2359 | ||
2360 |
If column cluase or where clause contain table name like "company.name", |
|
2361 |
needed join clause is used automatically. |
|
2362 | ||
2363 |
$dbi->select( |
|
2364 |
table => 'book', |
|
2365 |
column => ['company.location_id as company__location_id'], |
|
2366 |
where => {'company.name' => 'Orange'}, |
|
2367 |
join => [ |
|
2368 |
'left outer join company on book.company_id = company.id', |
|
2369 |
'left outer join location on company.location_id = location.id' |
|
2370 |
] |
|
2371 |
); |
|
2372 | ||
2373 |
In above select, the following SQL is created. |
|
2374 | ||
2375 |
select company.location_id as company__location_id |
|
2376 |
from book |
|
2377 |
left outer join company on book.company_id = company.id |
|
2378 |
where company.name = Orange |
|
2379 | ||
2380 |
=item C<append> |
|
2381 | ||
update pod
|
2382 |
Append statement to last of SQL. This is string. |
update pod
|
2383 | |
2384 |
$dbi->select(append => 'order by title'); |
|
2385 | ||
2386 |
=item C<filter> |
|
2387 | ||
update pod
|
2388 |
Filter, executed before data is send to database. This is array reference. |
2389 |
Filter value is code reference or |
|
update pod
|
2390 |
filter name registerd by C<register_filter()>. |
2391 | ||
2392 |
# Basic |
|
2393 |
$dbi->select( |
|
2394 |
filter => [ |
|
2395 |
title => sub { uc $_[0] } |
|
2396 |
author => sub { uc $_[0] } |
|
2397 |
] |
|
2398 |
); |
|
2399 |
|
|
2400 |
# At once |
|
2401 |
$dbi->select( |
|
2402 |
filter => [ |
|
2403 |
[qw/title author/] => sub { uc $_[0] } |
|
2404 |
] |
|
2405 |
); |
|
2406 |
|
|
2407 |
# Filter name |
|
2408 |
$dbi->select( |
|
2409 |
filter => [ |
|
2410 |
title => 'upper_case', |
|
2411 |
author => 'upper_case' |
|
2412 |
] |
|
2413 |
); |
|
add experimental selection o...
|
2414 | |
update pod
|
2415 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
update document
|
2416 | |
update pod
|
2417 |
=item C<query> EXPERIMENTAL |
cleanup
|
2418 | |
update pod
|
2419 |
Get L<DBIx::Custom::Query> object instead of executing SQL. |
2420 |
This is true or false value. |
|
2421 | ||
update pod
|
2422 |
my $query = $dbi->select(query => 1); |
update pod
|
2423 | |
update pod
|
2424 |
You can check SQL. |
update pod
|
2425 | |
2426 |
my $sql = $query->sql; |
|
2427 | ||
- added EXPERIMENTAL type() ...
|
2428 |
=item C<type> EXPERIMENTAL |
2429 | ||
2430 |
Specify database data type. |
|
2431 | ||
2432 |
$dbi->select(type => [image => DBI::SQL_BLOB]); |
|
2433 |
$dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]); |
|
2434 | ||
2435 |
This is used to bind paramter by C<bind_param()> of statment handle. |
|
2436 | ||
2437 |
$sth->bind_param($pos, $value, DBI::SQL_BLOB); |
|
2438 | ||
update pod
|
2439 |
=back |
cleanup
|
2440 | |
update pod
|
2441 |
=head2 C<select_at()> EXPERIMENTAL |
add experimental update_at()...
|
2442 | |
update pod
|
2443 |
Select statement, using primary key. |
2444 | ||
2445 |
$dbi->select_at( |
|
2446 |
table => 'book', |
|
2447 |
primary_key => 'id', |
|
2448 |
where => '5' |
|
2449 |
); |
|
2450 | ||
update pod
|
2451 |
This method is same as C<select()> exept that |
2452 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
update pod
|
2453 |
all option of C<select()> is available. |
add experimental update_at()...
|
2454 | |
update pod
|
2455 |
=over 4 |
2456 | ||
2457 |
=item C<primary_key> |
|
add experimental update_at()...
|
2458 | |
update pod
|
2459 |
Primary key. This is constant value or array reference. |
2460 |
|
|
2461 |
# Constant value |
|
2462 |
$dbi->select(primary_key => 'id'); |
|
2463 | ||
2464 |
# Array reference |
|
2465 |
$dbi->select(primary_key => ['id1', 'id2' ]); |
|
2466 | ||
update pod
|
2467 |
This is used to create where clause. |
2468 | ||
update pod
|
2469 |
=item C<where> |
update pod
|
2470 | |
update pod
|
2471 |
Where clause, created from primary key information. |
update pod
|
2472 |
This is constant value or array reference. |
2473 | ||
2474 |
# Constant value |
|
2475 |
$dbi->select(where => 5); |
|
2476 | ||
2477 |
# Array reference |
|
2478 |
$dbi->select(where => [3, 5]); |
|
2479 | ||
2480 |
In first examle, the following SQL is created. |
|
2481 | ||
2482 |
select * from book where id = ? |
|
2483 | ||
2484 |
Place holder is set to 5. |
|
add experimental update_at()...
|
2485 | |
update pod
|
2486 |
=back |
2487 | ||
cleanup
|
2488 |
=head2 C<update> |
removed reconnect method
|
2489 | |
update pod
|
2490 |
$dbi->update( |
2491 |
table => 'book', |
|
2492 |
param => {title => 'Perl'}, |
|
2493 |
where => {id => 4} |
|
2494 |
); |
|
removed reconnect method
|
2495 | |
update pod
|
2496 |
Update statement. |
added experimental update_pa...
|
2497 | |
update pod
|
2498 |
The following opitons are currently available. |
added experimental update_pa...
|
2499 | |
update pod
|
2500 |
=over 4 |
2501 | ||
update pod
|
2502 |
=item C<table> |
2503 | ||
update pod
|
2504 |
Table name. |
2505 | ||
2506 |
$dbi->update(table => 'book'); |
|
2507 | ||
2508 |
=item C<param> |
|
2509 | ||
2510 |
Update data. This is hash reference. |
|
2511 | ||
2512 |
$dbi->update(param => {title => 'Perl'}); |
|
2513 | ||
2514 |
=item C<where> |
|
2515 | ||
where can recieve array refr...
|
2516 |
Where clause. This is hash reference or L<DBIx::Custom::Where> object |
2517 |
or array refrence. |
|
update pod
|
2518 |
|
2519 |
# Hash reference |
|
2520 |
$dbi->update(where => {author => 'Ken', 'title' => 'Perl'}); |
|
2521 |
|
|
2522 |
# DBIx::Custom::Where object |
|
2523 |
my $where = $dbi->where( |
|
2524 |
clause => ['and', '{= author}', '{like title}'], |
|
2525 |
param => {author => 'Ken', title => '%Perl%'} |
|
2526 |
); |
|
2527 |
$dbi->update(where => $where); |
|
where can recieve array refr...
|
2528 |
|
2529 |
# Array refrendce (where clause and parameter) |
|
2530 |
$dbi->update(where => |
|
2531 |
[ |
|
2532 |
['and', '{= author}', '{like title}'], |
|
2533 |
{author => 'Ken', title => '%Perl%'} |
|
2534 |
] |
|
2535 |
); |
|
update pod
|
2536 | |
2537 |
=item C<append> |
|
2538 | ||
2539 |
Append statement to last of SQL. This is string. |
|
2540 | ||
2541 |
$dbi->update(append => 'order by title'); |
|
2542 | ||
2543 |
=item C<filter> |
|
2544 | ||
2545 |
Filter, executed before data is send to database. This is array reference. |
|
2546 |
Filter value is code reference or |
|
2547 |
filter name registerd by C<register_filter()>. |
|
2548 | ||
2549 |
# Basic |
|
2550 |
$dbi->update( |
|
2551 |
filter => [ |
|
2552 |
title => sub { uc $_[0] } |
|
2553 |
author => sub { uc $_[0] } |
|
2554 |
] |
|
2555 |
); |
|
2556 |
|
|
2557 |
# At once |
|
2558 |
$dbi->update( |
|
2559 |
filter => [ |
|
2560 |
[qw/title author/] => sub { uc $_[0] } |
|
2561 |
] |
|
2562 |
); |
|
2563 |
|
|
2564 |
# Filter name |
|
2565 |
$dbi->update( |
|
2566 |
filter => [ |
|
2567 |
title => 'upper_case', |
|
2568 |
author => 'upper_case' |
|
2569 |
] |
|
2570 |
); |
|
added experimental update_pa...
|
2571 | |
update pod
|
2572 |
These filters are added to the C<out> filters, set by C<apply_filter()>. |
added experimental update_pa...
|
2573 | |
update pod
|
2574 |
=item C<query> EXPERIMENTAL |
add experimental setup_model...
|
2575 | |
update pod
|
2576 |
Get L<DBIx::Custom::Query> object instead of executing SQL. |
2577 |
This is true or false value. |
|
add experimental setup_model...
|
2578 | |
update pod
|
2579 |
my $query = $dbi->update(query => 1); |
2580 | ||
2581 |
You can check SQL. |
|
2582 | ||
2583 |
my $sql = $query->sql; |
|
add experimental setup_model...
|
2584 | |
update pod
|
2585 |
=back |
2586 | ||
cleanup
|
2587 |
=head2 C<update_all> |
renamed build_query to creat...
|
2588 | |
update pod
|
2589 |
$dbi->update_all(table => 'book', param => {title => 'Perl'}); |
renamed build_query to creat...
|
2590 | |
update pod
|
2591 |
Update statement to update all rows. |
2592 |
Options is same as C<update()>. |
|
removed DBIx::Custom commit ...
|
2593 | |
update pod
|
2594 |
=head2 C<update_at()> EXPERIMENTAL |
add experimental update_at()...
|
2595 | |
update pod
|
2596 |
Update statement, using primary key. |
add experimental update_at()...
|
2597 | |
2598 |
$dbi->update_at( |
|
2599 |
table => 'book', |
|
update pod
|
2600 |
primary_key => 'id', |
2601 |
where => '5', |
|
2602 |
param => {title => 'Perl'} |
|
add experimental update_at()...
|
2603 |
); |
2604 | ||
update pod
|
2605 |
This method is same as C<update()> exept that |
2606 |
C<primary_key> is specified and C<where> is constant value or array refrence. |
|
2607 |
all option of C<update()> is available. |
|
2608 | ||
update pod
|
2609 |
=over 4 |
2610 | ||
2611 |
=item C<primary_key> |
|
update pod
|
2612 | |
2613 |
Primary key. This is constant value or array reference. |
|
2614 |
|
|
2615 |
# Constant value |
|
2616 |
$dbi->update(primary_key => 'id'); |
|
2617 | ||
2618 |
# Array reference |
|
2619 |
$dbi->update(primary_key => ['id1', 'id2' ]); |
|
2620 | ||
2621 |
This is used to create where clause. |
|
2622 | ||
update pod
|
2623 |
=item C<where> |
update pod
|
2624 | |
2625 |
Where clause, created from primary key information. |
|
2626 |
This is constant value or array reference. |
|
2627 | ||
2628 |
# Constant value |
|
2629 |
$dbi->update(where => 5); |
|
2630 | ||
2631 |
# Array reference |
|
2632 |
$dbi->update(where => [3, 5]); |
|
2633 | ||
2634 |
In first examle, the following SQL is created. |
|
2635 | ||
2636 |
update book set title = ? where id = ? |
|
2637 | ||
2638 |
Place holders are set to 'Perl' and 5. |
|
2639 | ||
update pod
|
2640 |
=back |
2641 | ||
2642 |
=head2 C<update_param> EXPERIMENTAL |
|
update pod
|
2643 | |
2644 |
my $update_param = $dbi->update_param({title => 'a', age => 2}); |
|
2645 | ||
2646 |
Create update parameter tag. |
|
2647 | ||
2648 |
{update_param title age} |
|
add experimental update_at()...
|
2649 | |
update pod
|
2650 |
=head2 C<where> EXPERIMENTAL |
fix tests
|
2651 | |
cleanup
|
2652 |
my $where = $dbi->where( |
2653 |
clause => ['and', '{= title}', '{= author}'], |
|
2654 |
param => {title => 'Perl', author => 'Ken'} |
|
2655 |
); |
|
fix tests
|
2656 | |
2657 |
Create a new L<DBIx::Custom::Where> object. |
|
2658 | ||
update pod
|
2659 |
=head2 C<setup_model> EXPERIMENTAL |
cleanup
|
2660 | |
update pod
|
2661 |
$dbi->setup_model; |
cleanup
|
2662 | |
update pod
|
2663 |
Setup all model objects. |
update pod
|
2664 |
C<columns> of model object is automatically set, parsing database information. |
cleanup
|
2665 | |
cleanup
|
2666 |
=head1 Tags |
2667 | ||
2668 |
The following tags is available. |
|
2669 | ||
update pod
|
2670 |
=head2 C<table> EXPERIMENTAL |
add table tag
|
2671 | |
2672 |
Table tag |
|
2673 | ||
2674 |
{table TABLE} -> TABLE |
|
2675 | ||
update pod
|
2676 |
This is used to tell C<execute()> what table is needed . |
add table tag
|
2677 | |
cleanup
|
2678 |
=head2 C<?> |
2679 | ||
2680 |
Placeholder tag. |
|
2681 | ||
2682 |
{? NAME} -> ? |
|
2683 | ||
2684 |
=head2 C<=> |
|
2685 | ||
2686 |
Equal tag. |
|
2687 | ||
2688 |
{= NAME} -> NAME = ? |
|
2689 | ||
2690 |
=head2 C<E<lt>E<gt>> |
|
2691 | ||
2692 |
Not equal tag. |
|
2693 | ||
2694 |
{<> NAME} -> NAME <> ? |
|
2695 | ||
2696 |
=head2 C<E<lt>> |
|
2697 | ||
2698 |
Lower than tag |
|
2699 | ||
2700 |
{< NAME} -> NAME < ? |
|
2701 | ||
2702 |
=head2 C<E<gt>> |
|
2703 | ||
2704 |
Greater than tag |
|
2705 | ||
2706 |
{> NAME} -> NAME > ? |
|
2707 | ||
2708 |
=head2 C<E<gt>=> |
|
2709 | ||
2710 |
Greater than or equal tag |
|
2711 | ||
2712 |
{>= NAME} -> NAME >= ? |
|
2713 | ||
2714 |
=head2 C<E<lt>=> |
|
2715 | ||
2716 |
Lower than or equal tag |
|
2717 | ||
2718 |
{<= NAME} -> NAME <= ? |
|
2719 | ||
2720 |
=head2 C<like> |
|
2721 | ||
2722 |
Like tag |
|
2723 | ||
2724 |
{like NAME} -> NAME like ? |
|
2725 | ||
2726 |
=head2 C<in> |
|
2727 | ||
2728 |
In tag. |
|
2729 | ||
2730 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
2731 | ||
2732 |
=head2 C<insert_param> |
|
2733 | ||
2734 |
Insert parameter tag. |
|
2735 | ||
2736 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
2737 | ||
2738 |
=head2 C<update_param> |
|
2739 | ||
2740 |
Updata parameter tag. |
|
2741 | ||
2742 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
2743 | ||
DBIx::Custom is now stable
|
2744 |
=head1 STABILITY |
2745 | ||
cleanup
|
2746 |
L<DBIx::Custom> is stable. APIs keep backword compatible |
added select() all_column op...
|
2747 |
except EXPERIMENTAL one in the feature. |
DBIx::Custom is now stable
|
2748 | |
removed DESTROY method(not b...
|
2749 |
=head1 BUGS |
2750 | ||
renamed build_query to creat...
|
2751 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
2752 | |
2753 |
C<< <kimoto.yuki at gmail.com> >> |
|
2754 | ||
2755 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
2756 | ||
removed reconnect method
|
2757 |
=head1 AUTHOR |
2758 | ||
2759 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
2760 | |
packaging one directory
|
2761 |
=head1 COPYRIGHT & LICENSE |
2762 | ||
cleanup
|
2763 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
2764 | |
2765 |
This program is free software; you can redistribute it and/or modify it |
|
2766 |
under the same terms as Perl itself. |
|
2767 | ||
2768 |
=cut |
|
added cache_method attribute
|
2769 | |
2770 |