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