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