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