cleanup
|
1 |
package DBIx::Custom; |
added EXPERIMENTAL insert, u...
|
2 |
use Object::Simple -base; |
cleanup
|
3 | |
- renamed DBIx::Custom::Resu...
|
4 |
our $VERSION = '0.2106'; |
fixed DBIx::Custom::QueryBui...
|
5 |
use 5.008001; |
cleanup
|
6 | |
packaging one directory
|
7 |
use Carp 'croak'; |
8 |
use DBI; |
|
9 |
use DBIx::Custom::Result; |
|
cleanup
|
10 |
use DBIx::Custom::Query; |
cleanup
|
11 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
12 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
13 |
use DBIx::Custom::Model; |
cleanup
|
14 |
use DBIx::Custom::Tag; |
- added EXPERIMENTAL order m...
|
15 |
use DBIx::Custom::Order; |
cleanup
|
16 |
use DBIx::Custom::Util qw/_array_to_hash _subname/; |
added tests
|
17 |
use DBIx::Custom::Mapper; |
- added EXPERIMENTAL pass at...
|
18 |
use DBIx::Custom::NotExists; |
improved debug message
|
19 |
use Encode qw/encode encode_utf8 decode_utf8/; |
cleanup
|
20 |
use Scalar::Util qw/weaken/; |
added experimental use_next_...
|
21 | |
packaging one directory
|
22 | |
- added EXPERIMENTAL get_col...
|
23 |
has [qw/connector dsn password quote user exclude_table user_table_info |
cleanup
|
24 |
user_column_info safety_character/], |
25 |
cache => 0, |
|
26 |
cache_method => sub { |
|
27 |
sub { |
|
28 |
my $self = shift; |
|
29 |
$self->{_cached} ||= {}; |
|
30 |
if (@_ > 1) { $self->{_cached}{$_[0]} = $_[1] } |
|
31 |
else { return $self->{_cached}{$_[0]} } |
|
32 |
} |
|
33 |
}, |
|
34 |
option => sub { {} }, |
|
35 |
default_option => sub { |
|
36 |
{ |
|
37 |
RaiseError => 1, |
|
38 |
PrintError => 0, |
|
39 |
AutoCommit => 1 |
|
40 |
} |
|
41 |
}, |
|
42 |
filters => sub { |
|
43 |
{ |
|
44 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
45 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
46 |
} |
|
47 |
}, |
|
48 |
last_sql => '', |
|
49 |
models => sub { {} }, |
|
50 |
now => sub { |
|
51 |
sub { |
|
52 |
my ($sec, $min, $hour, $mday, $mon, $year) = localtime; |
|
53 |
$mon++; |
|
54 |
$year += 1900; |
|
55 |
my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d", |
|
56 |
$year, $mon, $mday, $hour, $min, $sec); |
|
57 |
return $now; |
|
58 |
} |
|
59 |
}, |
|
60 |
query_builder => sub { |
|
61 |
my $self = shift; |
|
62 |
my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self); |
|
63 |
weaken $builder->{dbi}; |
|
64 |
return $builder; |
|
65 |
}, |
|
66 |
result_class => 'DBIx::Custom::Result', |
|
67 |
separator => '.', |
|
68 |
stash => sub { {} }; |
|
cleanup
|
69 | |
added EXPERIMENTAL system_ta...
|
70 |
sub available_datatype { |
cleanup
|
71 |
my $self = shift; |
72 |
|
|
73 |
my $data_types = ''; |
|
74 |
for my $i (-1000 .. 1000) { |
|
75 |
my $type_info = $self->dbh->type_info($i); |
|
76 |
my $data_type = $type_info->{DATA_TYPE}; |
|
77 |
my $type_name = $type_info->{TYPE_NAME}; |
|
78 |
$data_types .= "$data_type ($type_name)\n" |
|
79 |
if defined $data_type; |
|
80 |
} |
|
81 |
return "Data Type maybe equal to Type Name" unless $data_types; |
|
82 |
$data_types = "Data Type (Type name)\n" . $data_types; |
|
83 |
return $data_types; |
|
added EXPERIMENTAL system_ta...
|
84 |
} |
85 | ||
86 |
sub available_typename { |
|
cleanup
|
87 |
my $self = shift; |
88 |
|
|
89 |
# Type Names |
|
90 |
my $type_names = {}; |
|
91 |
$self->each_column(sub { |
|
92 |
my ($self, $table, $column, $column_info) = @_; |
|
93 |
$type_names->{$column_info->{TYPE_NAME}} = 1 |
|
94 |
if $column_info->{TYPE_NAME}; |
|
95 |
}); |
|
96 |
my @output = sort keys %$type_names; |
|
97 |
unshift @output, "Type Name"; |
|
98 |
return join "\n", @output; |
|
test cleanup
|
99 |
} |
100 | ||
added helper method
|
101 |
our $AUTOLOAD; |
102 |
sub AUTOLOAD { |
|
cleanup
|
103 |
my $self = shift; |
added helper method
|
104 | |
cleanup
|
105 |
# Method name |
106 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
107 | |
cleanup
|
108 |
# Call method |
109 |
$self->{_methods} ||= {}; |
|
110 |
if (my $method = $self->{_methods}->{$mname}) { |
|
111 |
return $self->$method(@_) |
|
112 |
} |
|
113 |
elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) { |
|
114 |
$self->dbh->$dbh_method(@_); |
|
115 |
} |
|
116 |
else { |
|
117 |
croak qq{Can't locate object method "$mname" via "$package" } |
|
118 |
. _subname; |
|
119 |
} |
|
added helper method
|
120 |
} |
121 | ||
- update_param is DEPRECATED...
|
122 |
sub assign_clause { |
cleanup
|
123 |
my ($self, $param, $opts) = @_; |
124 |
|
|
125 |
my $wrap = $opts->{wrap} || {}; |
|
126 |
my ($q, $p) = split //, $self->q(''); |
|
127 |
|
|
128 |
# Assign clause (performance is important) |
|
129 |
join( |
|
130 |
', ', |
|
131 |
map { |
|
132 |
ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}} |
|
133 |
: $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_") |
|
134 |
: "$q$_$p = :$_"; |
|
135 |
} sort keys %$param |
|
136 |
); |
|
added EXPERIMENTAL assign_ta...
|
137 |
} |
138 | ||
cleanup
|
139 |
sub column { |
cleanup
|
140 |
my $self = shift; |
141 |
my $option = pop if ref $_[-1] eq 'HASH'; |
|
142 |
my $real_table = shift; |
|
143 |
my $columns = shift; |
|
144 |
my $table = $option->{alias} || $real_table; |
|
145 |
|
|
146 |
# Columns |
|
147 |
unless (defined $columns) { |
|
148 |
$columns ||= $self->model($real_table)->columns; |
|
149 |
} |
|
150 |
|
|
151 |
# Separator |
|
152 |
my $separator = $self->separator; |
|
153 |
|
|
154 |
# Column clause |
|
155 |
my @column; |
|
156 |
$columns ||= []; |
|
157 |
push @column, $self->q($table) . "." . $self->q($_) . |
|
158 |
" as " . $self->q("${table}${separator}$_") |
|
159 |
for @$columns; |
|
160 |
|
|
161 |
return join (', ', @column); |
|
added helper method
|
162 |
} |
163 | ||
packaging one directory
|
164 |
sub connect { |
cleanup
|
165 |
my $self = ref $_[0] ? shift : shift->new(@_); |
166 |
|
|
167 |
my $connector = $self->connector; |
|
168 |
|
|
169 |
if (!ref $connector && $connector) { |
|
170 |
require DBIx::Connector; |
|
171 |
|
|
172 |
my $dsn = $self->dsn; |
|
173 |
my $user = $self->user; |
|
174 |
my $password = $self->password; |
|
175 |
my $option = $self->_option; |
|
176 |
my $connector = DBIx::Connector->new($dsn, $user, $password, |
|
177 |
{%{$self->default_option} , %$option}); |
|
178 |
$self->connector($connector); |
|
179 |
} |
|
180 |
|
|
181 |
# Connect |
|
182 |
$self->dbh; |
|
183 |
|
|
184 |
return $self; |
|
packaging one directory
|
185 |
} |
186 | ||
- renamed DBIx::Custom::Resu...
|
187 |
sub count { shift->select(column => 'count(*)', @_)->fetch_one->[0] } |
- added EXPERIMENTAL DBIx::C...
|
188 | |
update pod
|
189 |
sub dbh { |
cleanup
|
190 |
my $self = shift; |
191 |
|
|
192 |
# Set |
|
193 |
if (@_) { |
|
194 |
$self->{dbh} = $_[0]; |
|
cleanup
|
195 |
|
cleanup
|
196 |
return $self; |
197 |
} |
|
198 |
|
|
199 |
# Get |
|
200 |
else { |
|
201 |
# From Connction manager |
|
202 |
if (my $connector = $self->connector) { |
|
203 |
croak "connector must have dbh() method " . _subname |
|
204 |
unless ref $connector && $connector->can('dbh'); |
|
fixed dbh() method bug:wq
|
205 |
|
cleanup
|
206 |
$self->{dbh} = $connector->dbh; |
fixed dbh() method bug:wq
|
207 |
} |
208 |
|
|
cleanup
|
209 |
# Connect |
210 |
$self->{dbh} ||= $self->_connect; |
|
211 |
|
|
212 |
# Quote |
|
213 |
if (!defined $self->reserved_word_quote && !defined $self->quote) { |
|
214 |
my $driver = $self->_driver; |
|
215 |
my $quote = $driver eq 'odbc' ? '[]' |
|
216 |
: $driver eq 'ado' ? '[]' |
|
217 |
: $driver eq 'mysql' ? '`' |
|
218 |
: '"'; |
|
219 |
$self->quote($quote); |
|
update pod
|
220 |
} |
cleanup
|
221 |
|
222 |
return $self->{dbh}; |
|
223 |
} |
|
update pod
|
224 |
} |
225 | ||
cleanup
|
226 |
sub delete { |
cleanup
|
227 |
my ($self, %opt) = @_; |
228 |
warn "delete method where_param option is DEPRECATED!" |
|
229 |
if $opt{where_param}; |
|
230 |
|
|
231 |
# Don't allow delete all rows |
|
232 |
croak qq{delete method where or id option must be specified } . _subname |
|
233 |
if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all}; |
|
234 |
|
|
235 |
# Where |
|
236 |
my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param}, |
|
237 |
delete $opt{id}, $opt{primary_key}, $opt{table}); |
|
238 | ||
239 |
# Delete statement |
|
240 |
my $sql = "delete "; |
|
241 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
|
242 |
$sql .= "from " . $self->q($opt{table}) . " $w->{clause} "; |
|
243 |
|
|
244 |
# Execute query |
|
245 |
$opt{statement} = 'delete'; |
|
246 |
$self->execute($sql, $w->{param}, %opt); |
|
packaging one directory
|
247 |
} |
248 | ||
cleanup
|
249 |
sub delete_all { shift->delete(@_, allow_delete_all => 1) } |
packaging one directory
|
250 | |
added memory leak check test
|
251 |
sub DESTROY {} |
added helper method
|
252 | |
removed EXPERIMETNAL flag fr...
|
253 |
sub create_model { |
cleanup
|
254 |
my $self = shift; |
255 |
|
|
256 |
# Options |
|
257 |
my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
258 |
$opt->{dbi} = $self; |
|
259 |
my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model'; |
|
260 |
my $model_name = delete $opt->{name}; |
|
261 |
my $model_table = delete $opt->{table}; |
|
262 |
$model_name ||= $model_table; |
|
263 |
|
|
264 |
# Create model |
|
265 |
my $model = $model_class->new($opt); |
|
266 |
weaken $model->{dbi}; |
|
267 |
$model->name($model_name) unless $model->name; |
|
268 |
$model->table($model_table) unless $model->table; |
|
269 |
|
|
270 |
# Apply filter(DEPRECATED logic) |
|
271 |
if ($model->{filter}) { |
|
272 |
my $filter = ref $model->filter eq 'HASH' |
|
273 |
? [%{$model->filter}] |
|
274 |
: $model->filter; |
|
275 |
$filter ||= []; |
|
276 |
warn "DBIx::Custom::Model filter method is DEPRECATED!" |
|
277 |
if @$filter; |
|
278 |
$self->_apply_filter($model->table, @$filter); |
|
279 |
} |
|
280 |
|
|
281 |
# Set model |
|
282 |
$self->model($model->name, $model); |
|
283 |
|
|
284 |
return $self->model($model->name); |
|
removed EXPERIMETNAL flag fr...
|
285 |
} |
286 | ||
287 |
sub each_column { |
|
cleanup
|
288 |
my ($self, $cb, %options) = @_; |
289 | ||
290 |
my $user_column_info = $self->user_column_info; |
|
291 |
|
|
292 |
if ($user_column_info) { |
|
293 |
$self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info; |
|
294 |
} |
|
295 |
else { |
|
296 |
my $re = $self->exclude_table || $options{exclude_table}; |
|
297 |
# Tables |
|
298 |
my %tables; |
|
299 |
$self->each_table(sub { $tables{$_[1]}++ }); |
|
added EXPERIMENTAL system_ta...
|
300 | |
cleanup
|
301 |
# Iterate all tables |
302 |
my @tables = sort keys %tables; |
|
303 |
for (my $i = 0; $i < @tables; $i++) { |
|
304 |
my $table = $tables[$i]; |
|
305 |
|
|
306 |
# Iterate all columns |
|
307 |
my $sth_columns; |
|
308 |
eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')}; |
|
309 |
next if $@; |
|
310 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
311 |
my $column = $column_info->{COLUMN_NAME}; |
|
312 |
$self->$cb($table, $column, $column_info); |
|
313 |
} |
|
removed EXPERIMETNAL flag fr...
|
314 |
} |
cleanup
|
315 |
} |
removed EXPERIMETNAL flag fr...
|
316 |
} |
317 | ||
added EXPERIMENTAL each_tabl...
|
318 |
sub each_table { |
cleanup
|
319 |
my ($self, $cb, %option) = @_; |
320 |
|
|
321 |
my $user_table_infos = $self->user_table_info; |
|
322 |
|
|
323 |
# Iterate tables |
|
324 |
if ($user_table_infos) { |
|
325 |
$self->$cb($_->{table}, $_->{info}) for @$user_table_infos; |
|
326 |
} |
|
327 |
else { |
|
328 |
my $re = $self->exclude_table || $option{exclude}; |
|
329 |
my $sth_tables = $self->dbh->table_info; |
|
330 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
331 |
# Table |
|
332 |
my $table = $table_info->{TABLE_NAME}; |
|
333 |
next if defined $re && $table =~ /$re/; |
|
334 |
$self->$cb($table, $table_info); |
|
335 |
} |
|
336 |
} |
|
added EXPERIMENTAL each_tabl...
|
337 |
} |
338 | ||
cleanup
|
339 |
sub execute { |
cleanup
|
340 |
my $self = shift; |
341 |
my $sql = shift; |
|
342 | ||
343 |
# Options |
|
344 |
my $params; |
|
345 |
$params = shift if @_ % 2; |
|
346 |
my %opt = @_; |
|
347 |
warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter}; |
|
348 |
$params ||= $opt{param} || {}; |
|
349 |
my $tables = $opt{table} || []; |
|
350 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
|
351 |
my $filter = ref $opt{filter} eq 'ARRAY' ? |
|
352 |
_array_to_hash($opt{filter}) : $opt{filter}; |
|
353 |
|
|
354 |
# Merge second parameter |
|
355 |
my @cleanup; |
|
356 |
my $saved_param; |
|
357 |
if (($opt{statement} || '') ne 'insert' && ref $params eq 'ARRAY') { |
|
358 |
my $params2 = $params->[1]; |
|
359 |
$params = $params->[0]; |
|
360 |
for my $column (keys %$params2) { |
|
361 |
if (!exists $params->{$column}) { |
|
362 |
$params->{$column} = $params2->{$column}; |
|
363 |
push @cleanup, $column; |
|
364 |
} |
|
365 |
else { |
|
366 |
delete $params->{$_} for @cleanup; |
|
367 |
@cleanup = (); |
|
368 |
$saved_param = $params; |
|
369 |
$params = $self->merge_param($params, $params2); |
|
370 |
delete $saved_param->{$_} for (@{$opt{cleanup} || []}); |
|
371 |
last; |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
$params = [$params] unless ref $params eq 'ARRAY'; |
|
376 |
|
|
377 |
# Append |
|
378 |
$sql .= $opt{append} if defined $opt{append} && !ref $sql; |
|
379 |
|
|
380 |
# Query |
|
381 |
my $query; |
|
382 |
if (ref $sql) { |
|
383 |
$query = $sql; |
|
384 |
warn "execute method receiving query object as first parameter is DEPRECATED!" . |
|
385 |
"because this is very buggy."; |
|
386 |
} |
|
387 |
else { |
|
388 |
$query = $opt{reuse}->{$sql} if $opt{reuse}; |
|
389 |
unless ($query) { |
|
390 |
my $c = $self->{safety_character}; |
|
391 |
# Check unsafety keys |
|
392 |
unless ((join('', keys %{$params->[0]}) || '') =~ /^[$c\.]+$/) { |
|
393 |
for my $column (keys %{$params->[0]}) { |
|
394 |
croak qq{"$column" is not safety column name } . _subname |
|
395 |
unless $column =~ /^[$c\.]+$/; |
|
micro optimization
|
396 |
} |
cleanup
|
397 |
} |
398 |
$query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter}); |
|
399 |
} |
|
400 |
$query->{statement} = $opt{statement} || ''; |
|
401 |
$opt{reuse}->{$sql} = $query if $opt{reuse}; |
|
402 |
} |
|
403 |
|
|
404 |
# Save query |
|
405 |
$self->{last_sql} = $query->{sql}; |
|
406 | ||
407 |
# Return query |
|
408 |
if ($opt{query}) { |
|
409 |
for my $column (@cleanup, @{$opt{cleanup} || []}) { |
|
410 |
delete $_->{$column} for @$params; |
|
added EXPERIMENTAL reuse_que...
|
411 |
} |
cleanup
|
412 |
return $query; |
413 |
}; |
|
414 |
|
|
415 |
# Merge query filter(DEPRECATED!) |
|
416 |
$filter ||= $query->{filter} || {}; |
|
417 |
|
|
418 |
# Tables |
|
419 |
unshift @$tables, @{$query->{tables} || []}; |
|
420 |
my $main_table = @{$tables}[-1]; |
|
421 | ||
422 |
# Merge id to parameter |
|
423 |
if (defined $opt{id}) { |
|
424 |
my $statement = $query->{statement}; |
|
425 |
warn "execute method id option is DEPRECATED!" unless $statement; |
|
426 |
croak "execute id option must be specified with primary_key option" |
|
427 |
unless $opt{primary_key}; |
|
428 |
$opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key}; |
|
429 |
$opt{id} = [$opt{id}] unless ref $opt{id}; |
|
430 |
for (my $i = 0; $i < @{$opt{id}}; $i++) { |
|
431 |
my $key = $opt{primary_key}->[$i]; |
|
432 |
$key = "$main_table.$key" if $statement eq 'update' || |
|
433 |
$statement eq 'delete' || $statement eq 'select'; |
|
434 |
next if exists $params->[0]->{$key}; |
|
435 |
$params->[0]->{$key} = $opt{id}->[$i]; |
|
436 |
push @cleanup, $key;1 |
|
437 |
} |
|
438 |
} |
|
439 |
|
|
440 |
# Cleanup tables(DEPRECATED!) |
|
441 |
$tables = $self->_remove_duplicate_table($tables, $main_table) |
|
442 |
if @$tables > 1; |
|
443 |
|
|
444 |
# Type rule |
|
445 |
my $type_filters = {}; |
|
446 |
my $type_rule_off = !$self->{_type_rule_is_called} || $opt{type_rule_off}; |
|
447 |
unless ($type_rule_off) { |
|
448 |
my $type_rule_off_parts = { |
|
449 |
1 => $opt{type_rule1_off}, |
|
450 |
2 => $opt{type_rule2_off} |
|
cleanup
|
451 |
}; |
cleanup
|
452 |
for my $i (1, 2) { |
453 |
unless ($type_rule_off_parts->{$i}) { |
|
454 |
$type_filters->{$i} = {}; |
|
455 |
my $table_alias = $opt{table_alias} || {}; |
|
456 |
for my $alias (keys %$table_alias) { |
|
457 |
my $table = $table_alias->{$alias}; |
|
458 |
|
|
459 |
for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) { |
|
460 |
$type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column}; |
|
461 |
} |
|
- insert method id value is ...
|
462 |
} |
cleanup
|
463 |
$type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}} |
464 |
if $main_table; |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
|
|
469 |
# Applied filter(DEPRECATED!) |
|
470 |
if ($self->{filter}{on}) { |
|
471 |
my $applied_filter = {}; |
|
472 |
for my $table (@$tables) { |
|
473 |
$applied_filter = { |
|
474 |
%$applied_filter, |
|
475 |
%{$self->{filter}{out}->{$table} || {}} |
|
476 |
} |
|
477 |
} |
|
478 |
$filter = {%$applied_filter, %$filter}; |
|
479 |
} |
|
480 |
|
|
481 |
# Replace filter name to code |
|
482 |
for my $column (keys %$filter) { |
|
483 |
my $name = $filter->{$column}; |
|
484 |
if (!defined $name) { |
|
485 |
$filter->{$column} = undef; |
|
486 |
} |
|
487 |
elsif (ref $name ne 'CODE') { |
|
488 |
croak qq{Filter "$name" is not registered" } . _subname |
|
489 |
unless exists $self->filters->{$name}; |
|
490 |
$filter->{$column} = $self->filters->{$name}; |
|
491 |
} |
|
492 |
} |
|
493 | ||
494 |
# Execute |
|
495 |
my $sth = $query->{sth}; |
|
496 |
my $affected; |
|
497 |
if ((!$query->{duplicate} || $opt{bulk_insert}) && $type_rule_off |
|
498 |
&& !keys %$filter && !$self->{default_out_filter} |
|
499 |
&& !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG}) |
|
500 |
{ |
|
501 |
eval { |
|
502 |
if ($opt{bulk_insert}) { |
|
503 |
my %count; |
|
504 |
my $param = $params->[0]; |
|
505 |
$affected = $sth->execute(map { $param->{$_}->[++$count{$_} - 1] } |
|
506 |
@{$query->{columns}}); |
|
507 |
} |
|
508 |
else { |
|
- insert method can receive ...
|
509 |
for my $param (@$params) { |
cleanup
|
510 |
$affected = $sth->execute(map { $param->{$_} } |
511 |
@{$query->{columns}}); |
|
- insert method can receive ...
|
512 |
} |
cleanup
|
513 |
} |
514 |
}; |
|
515 |
} |
|
516 |
else { |
|
517 |
for my $param (@$params) { |
|
518 |
# Create bind values |
|
519 |
my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns}, |
|
520 |
$filter, $type_filters, $opt{bind_type} || $opt{type} || {}); |
|
521 | ||
522 |
# Execute |
|
523 |
eval { |
|
524 |
if ($opt{bind_type} || $opt{type}) { |
|
525 |
$sth->bind_param($_ + 1, $bind->[$_], |
|
526 |
$bind_types->[$_] ? $bind_types->[$_] : ()) |
|
527 |
for (0 .. @$bind - 1); |
|
528 |
$affected = $sth->execute; |
|
cleanup
|
529 |
} |
cleanup
|
530 |
else { $affected = $sth->execute(@$bind) } |
531 | ||
532 |
# DEBUG message |
|
533 |
if ($ENV{DBIX_CUSTOM_DEBUG}) { |
|
534 |
warn "SQL:\n" . $query->{sql} . "\n"; |
|
535 |
my @output; |
|
536 |
for my $value (@$bind) { |
|
537 |
$value = 'undef' unless defined $value; |
|
538 |
$value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value) |
|
539 |
if utf8::is_utf8($value); |
|
540 |
push @output, $value; |
|
541 |
} |
|
542 |
warn "Bind values: " . join(', ', @output) . "\n\n"; |
|
543 |
} |
|
544 |
}; |
|
545 |
} |
|
546 |
} |
|
547 |
|
|
548 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
|
549 |
. qq{$query->{sql}\n} . _subname) if $@; |
|
550 | ||
551 |
# Remove id from parameter |
|
552 |
for my $column (@cleanup, @{$opt{cleanup} || []}) { |
|
553 |
delete $_->{$column} for @$params; |
|
554 |
} |
|
555 |
|
|
556 |
# Not select statement |
|
557 |
return $affected unless $sth->{NUM_OF_FIELDS}; |
|
558 | ||
559 |
# Filter(DEPRECATED!) |
|
560 |
my $infilter = {}; |
|
561 |
if ($self->{filter}{on}) { |
|
562 |
$infilter->{in} = {}; |
|
563 |
$infilter->{end} = {}; |
|
564 |
push @$tables, $main_table if $main_table; |
|
565 |
for my $table (@$tables) { |
|
566 |
for my $way (qw/in end/) { |
|
567 |
$infilter->{$way} = {%{$infilter->{$way}}, |
|
568 |
%{$self->{filter}{$way}{$table} || {}}}; |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
|
|
573 |
# Result |
|
574 |
$self->result_class->new( |
|
575 |
sth => $sth, |
|
576 |
dbi => $self, |
|
577 |
default_filter => $self->{default_in_filter}, |
|
578 |
filter => $infilter->{in} || {}, |
|
579 |
end_filter => $infilter->{end} || {}, |
|
580 |
type_rule => { |
|
581 |
from1 => $self->type_rule->{from1}, |
|
582 |
from2 => $self->type_rule->{from2} |
|
583 |
}, |
|
584 |
); |
|
cleanup
|
585 |
} |
586 | ||
added test
|
587 |
sub get_table_info { |
cleanup
|
588 |
my ($self, %opt) = @_; |
589 |
|
|
590 |
my $exclude = delete $opt{exclude}; |
|
591 |
croak qq/"$_" is wrong option/ for keys %opt; |
|
592 |
|
|
593 |
my $table_info = []; |
|
594 |
$self->each_table( |
|
595 |
sub { push @$table_info, {table => $_[1], info => $_[2] } }, |
|
596 |
exclude => $exclude |
|
597 |
); |
|
598 |
|
|
599 |
return [sort {$a->{table} cmp $b->{table} } @$table_info]; |
|
added EXPERIMENTAL find_tabl...
|
600 |
} |
601 | ||
- added EXPERIMENTAL get_col...
|
602 |
sub get_column_info { |
cleanup
|
603 |
my ($self, %opt) = @_; |
604 |
|
|
605 |
my $exclude_table = delete $opt{exclude_table}; |
|
606 |
croak qq/"$_" is wrong option/ for keys %opt; |
|
607 |
|
|
608 |
my $column_info = []; |
|
609 |
$self->each_column( |
|
610 |
sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } }, |
|
611 |
exclude_table => $exclude_table |
|
612 |
); |
|
613 |
|
|
614 |
return [ |
|
615 |
sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} } |
|
616 |
@$column_info]; |
|
- added EXPERIMENTAL get_col...
|
617 |
} |
618 | ||
- method method of DBIx::Cus...
|
619 |
sub helper { |
cleanup
|
620 |
my $self = shift; |
621 |
|
|
622 |
# Register method |
|
623 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
624 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
625 |
|
|
626 |
return $self; |
|
- method method of DBIx::Cus...
|
627 |
} |
628 | ||
cleanup
|
629 |
sub insert { |
cleanup
|
630 |
my $self = shift; |
631 |
|
|
632 |
# Options |
|
633 |
my $params = @_ % 2 ? shift : undef; |
|
634 |
my %opt = @_; |
|
635 |
warn "insert method param option is DEPRECATED!" if $opt{param}; |
|
636 |
$params ||= delete $opt{param} || {}; |
|
637 |
|
|
638 |
my $multi; |
|
639 |
if (ref $params eq 'ARRAY') { $multi = 1 } |
|
640 |
else { $params = [$params] } |
|
641 |
|
|
642 |
# Timestamp(DEPRECATED!) |
|
643 |
if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) { |
|
644 |
warn "insert timestamp option is DEPRECATED! use created_at with now attribute"; |
|
645 |
my $columns = $insert_timestamp->[0]; |
|
646 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
|
647 |
my $value = $insert_timestamp->[1]; |
|
648 |
$value = $value->() if ref $value eq 'CODE'; |
|
649 |
$params->[0]->{$_} = $value for @$columns; |
|
650 |
} |
|
651 | ||
652 |
# Created time and updated time |
|
653 |
my @timestamp_cleanup; |
|
654 |
if (defined $opt{created_at} || defined $opt{updated_at}) { |
|
655 |
my $now = $self->now; |
|
656 |
$now = $now->() if ref $now eq 'CODE'; |
|
657 |
if (defined $opt{created_at}) { |
|
658 |
$_->{$opt{created_at}} = $now for @$params; |
|
659 |
push @timestamp_cleanup, $opt{created_at}; |
|
added EXPERIMENTAL insert cr...
|
660 |
} |
cleanup
|
661 |
if (defined $opt{updated_at}) { |
662 |
$_->{$opt{updated_at}} = $now for @$params; |
|
663 |
push @timestamp_cleanup, $opt{updated_at}; |
|
664 |
} |
|
665 |
} |
|
666 |
|
|
667 |
# Merge id to parameter |
|
668 |
my @cleanup; |
|
669 |
my $id_param = {}; |
|
670 |
if (defined $opt{id} && !$multi) { |
|
671 |
croak "insert id option must be specified with primary_key option" |
|
672 |
unless $opt{primary_key}; |
|
673 |
$opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key}; |
|
674 |
$opt{id} = [$opt{id}] unless ref $opt{id}; |
|
675 |
for (my $i = 0; $i < @{$opt{primary_key}}; $i++) { |
|
676 |
my $key = $opt{primary_key}->[$i]; |
|
677 |
next if exists $params->[0]->{$key}; |
|
678 |
$params->[0]->{$key} = $opt{id}->[$i]; |
|
679 |
push @cleanup, $key; |
|
680 |
} |
|
681 |
} |
|
682 |
|
|
683 |
# Insert statement |
|
684 |
my $sql = "insert "; |
|
685 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
|
686 |
$sql .= "into " . $self->q($opt{table}) . " "; |
|
687 |
if ($opt{bulk_insert}) { |
|
688 |
$sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " "; |
|
689 |
my $new_param = {}; |
|
690 |
$new_param->{$_} = [] for keys %{$params->[0]}; |
|
691 |
for my $param (@$params) { |
|
692 |
push @{$new_param->{$_}}, $param->{$_} for keys %$param; |
|
693 |
} |
|
694 |
$params = [$new_param]; |
|
695 |
} |
|
696 |
else { |
|
697 |
$sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " "; |
|
698 |
} |
|
699 | ||
700 |
# Remove id from parameter |
|
701 |
delete $params->[0]->{$_} for @cleanup; |
|
702 |
|
|
703 |
# Execute query |
|
704 |
$opt{statement} = 'insert'; |
|
705 |
$opt{cleanup} = \@timestamp_cleanup; |
|
706 |
$self->execute($sql, $params, %opt); |
|
packaging one directory
|
707 |
} |
708 | ||
- added EXPERIMENTAL update_...
|
709 |
sub insert_timestamp { |
cleanup
|
710 |
my $self = shift; |
711 |
|
|
712 |
warn "insert_timestamp method is DEPRECATED! use now attribute"; |
|
713 |
|
|
714 |
if (@_) { |
|
715 |
$self->{insert_timestamp} = [@_]; |
|
- added EXPERIMENTAL update_...
|
716 |
|
cleanup
|
717 |
return $self; |
718 |
} |
|
719 |
return $self->{insert_timestamp}; |
|
- added EXPERIMENTAL update_...
|
720 |
} |
721 | ||
- added EXPERIMENTAL DBIx::C...
|
722 |
sub include_model { |
cleanup
|
723 |
my ($self, $name_space, $model_infos) = @_; |
724 |
|
|
725 |
# Name space |
|
726 |
$name_space ||= ''; |
|
727 |
|
|
728 |
# Get Model infomations |
|
729 |
unless ($model_infos) { |
|
730 | ||
731 |
# Load name space module |
|
732 |
croak qq{"$name_space" is invalid class name } . _subname |
|
733 |
if $name_space =~ /[^\w:]/; |
|
734 |
eval "use $name_space"; |
|
735 |
croak qq{Name space module "$name_space.pm" is needed. $@ } |
|
736 |
. _subname |
|
737 |
if $@; |
|
738 |
|
|
739 |
# Search model modules |
|
740 |
my $path = $INC{"$name_space.pm"}; |
|
741 |
$path =~ s/\.pm$//; |
|
742 |
opendir my $dh, $path |
|
743 |
or croak qq{Can't open directory "$path": $! } . _subname |
|
744 |
$model_infos = []; |
|
745 |
while (my $module = readdir $dh) { |
|
746 |
push @$model_infos, $module |
|
747 |
if $module =~ s/\.pm$//; |
|
748 |
} |
|
749 |
close $dh; |
|
750 |
} |
|
751 |
|
|
752 |
# Include models |
|
753 |
for my $model_info (@$model_infos) { |
|
754 |
|
|
755 |
# Load model |
|
756 |
my $model_class; |
|
757 |
my $model_name; |
|
758 |
my $model_table; |
|
759 |
if (ref $model_info eq 'HASH') { |
|
760 |
$model_class = $model_info->{class}; |
|
761 |
$model_name = $model_info->{name}; |
|
762 |
$model_table = $model_info->{table}; |
|
763 |
|
|
764 |
$model_name ||= $model_class; |
|
765 |
$model_table ||= $model_name; |
|
766 |
} |
|
767 |
else { $model_class = $model_name = $model_table = $model_info } |
|
768 |
my $mclass = "${name_space}::$model_class"; |
|
769 |
croak qq{"$mclass" is invalid class name } . _subname |
|
770 |
if $mclass =~ /[^\w:]/; |
|
771 |
unless ($mclass->can('isa')) { |
|
772 |
eval "use $mclass"; |
|
773 |
croak "$@ " . _subname if $@; |
|
- added EXPERIMENTAL DBIx::C...
|
774 |
} |
775 |
|
|
cleanup
|
776 |
# Create model |
777 |
my $opt = {}; |
|
778 |
$opt->{model_class} = $mclass if $mclass; |
|
779 |
$opt->{name} = $model_name if $model_name; |
|
780 |
$opt->{table} = $model_table if $model_table; |
|
781 |
$self->create_model($opt); |
|
782 |
} |
|
783 |
|
|
784 |
return $self; |
|
- added EXPERIMENTAL DBIx::C...
|
785 |
} |
786 | ||
added EXPERIMENTAL like_valu...
|
787 |
sub like_value { sub { "%$_[0]%" } } |
788 | ||
added DBIx::Custom::Mapper
|
789 |
sub mapper { |
cleanup
|
790 |
my $self = shift; |
791 |
return DBIx::Custom::Mapper->new(@_); |
|
added DBIx::Custom::Mapper
|
792 |
} |
793 | ||
added EXPERIMENTAL updat_par...
|
794 |
sub merge_param { |
cleanup
|
795 |
my ($self, @params) = @_; |
796 |
|
|
797 |
# Merge parameters |
|
798 |
my $merge = {}; |
|
799 |
for my $param (@params) { |
|
800 |
for my $column (keys %$param) { |
|
801 |
my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0; |
|
802 |
|
|
803 |
if (exists $merge->{$column}) { |
|
804 |
$merge->{$column} = [$merge->{$column}] |
|
805 |
unless ref $merge->{$column} eq 'ARRAY'; |
|
806 |
push @{$merge->{$column}}, |
|
807 |
ref $param->{$column} ? @{$param->{$column}} : $param->{$column}; |
|
808 |
} |
|
809 |
else { $merge->{$column} = $param->{$column} } |
|
810 |
} |
|
811 |
} |
|
812 |
|
|
813 |
return $merge; |
|
added EXPERIMENTAL updat_par...
|
814 |
} |
815 | ||
- added EXPERIMENTAL DBIx::C...
|
816 |
sub model { |
cleanup
|
817 |
my ($self, $name, $model) = @_; |
818 |
|
|
819 |
# Set model |
|
820 |
if ($model) { |
|
821 |
$self->models->{$name} = $model; |
|
822 |
return $self; |
|
823 |
} |
|
824 |
|
|
825 |
# Check model existance |
|
826 |
croak qq{Model "$name" is not included } . _subname |
|
827 |
unless $self->models->{$name}; |
|
828 |
|
|
829 |
# Get model |
|
830 |
return $self->models->{$name}; |
|
- added EXPERIMENTAL DBIx::C...
|
831 |
} |
832 | ||
cleanup
|
833 |
sub mycolumn { |
cleanup
|
834 |
my ($self, $table, $columns) = @_; |
835 |
|
|
836 |
# Create column clause |
|
837 |
my @column; |
|
838 |
$columns ||= []; |
|
839 |
push @column, $self->q($table) . "." . $self->q($_) . " as " . $self->q($_) |
|
840 |
for @$columns; |
|
841 |
|
|
842 |
return join (', ', @column); |
|
cleanup
|
843 |
} |
844 | ||
added dbi_options attribute
|
845 |
sub new { |
cleanup
|
846 |
my $self = shift->SUPER::new(@_); |
847 |
|
|
848 |
# Check attributes |
|
849 |
my @attrs = keys %$self; |
|
850 |
for my $attr (@attrs) { |
|
851 |
croak qq{Invalid attribute: "$attr" } . _subname |
|
852 |
unless $self->can($attr); |
|
853 |
} |
|
854 |
|
|
855 |
$self->{safety_character} = 'a-zA-Z0-9_' |
|
856 |
unless exists $self->{safety_character}; |
|
857 | ||
858 |
# DEPRECATED |
|
859 |
$self->{_tags} = { |
|
860 |
'?' => \&DBIx::Custom::Tag::placeholder, |
|
861 |
'=' => \&DBIx::Custom::Tag::equal, |
|
862 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
863 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
864 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
865 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
866 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
867 |
'like' => \&DBIx::Custom::Tag::like, |
|
868 |
'in' => \&DBIx::Custom::Tag::in, |
|
869 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
870 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
871 |
}; |
|
872 |
$self->{tag_parse} = 1 unless exists $self->{tag_parse}; |
|
873 |
$self->{cache} = 0 unless exists $self->{cache}; |
|
874 |
|
|
875 |
return $self; |
|
cleanup
|
876 |
} |
877 | ||
- added EXPERIMENTAL pass at...
|
878 |
sub not_exists { DBIx::Custom::NotExists->singleton } |
cleanup
|
879 | |
880 |
sub order { |
|
cleanup
|
881 |
my $self = shift; |
882 |
return DBIx::Custom::Order->new(dbi => $self, @_); |
|
added EXPERIMENTAL system_ta...
|
883 |
} |
884 | ||
added EXPERIMENTAL q method
|
885 |
sub q { |
cleanup
|
886 |
my ($self, $value, $quotemeta) = @_; |
887 |
|
|
888 |
my $quote = $self->{reserved_word_quote} |
|
889 |
|| $self->{quote} || $self->quote || ''; |
|
890 |
return "$quote$value$quote" |
|
891 |
if !$quotemeta && ($quote eq '`' || $quote eq '"'); |
|
892 |
|
|
893 |
my $q = substr($quote, 0, 1) || ''; |
|
894 |
my $p; |
|
895 |
if (defined $quote && length $quote > 1) { |
|
896 |
$p = substr($quote, 1, 1); |
|
897 |
} |
|
898 |
else { $p = $q } |
|
899 |
|
|
900 |
if ($quotemeta) { |
|
901 |
$q = quotemeta($q); |
|
902 |
$p = quotemeta($p); |
|
903 |
} |
|
904 |
|
|
905 |
return "$q$value$p"; |
|
added EXPERIMENTAL q method
|
906 |
} |
907 | ||
cleanup
|
908 |
sub register_filter { |
cleanup
|
909 |
my $self = shift; |
910 |
|
|
911 |
# Register filter |
|
912 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
913 |
$self->filters({%{$self->filters}, %$filters}); |
|
914 |
|
|
915 |
return $self; |
|
cleanup
|
916 |
} |
packaging one directory
|
917 | |
918 |
sub select { |
|
cleanup
|
919 |
my $self = shift; |
920 |
my $column = shift if @_ % 2; |
|
921 |
my %opt = @_; |
|
922 |
$opt{column} = $column if defined $column; |
|
923 | ||
924 |
# Options |
|
925 |
my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table} |
|
926 |
: defined $opt{table} ? [$opt{table}] |
|
927 |
: []; |
|
928 |
$opt{table} = $tables; |
|
929 |
my $where_param = $opt{where_param} || delete $opt{param} || {}; |
|
930 |
warn "select method where_param option is DEPRECATED!" |
|
931 |
if $opt{where_param}; |
|
932 |
|
|
933 |
# Add relation tables(DEPRECATED!); |
|
934 |
if ($opt{relation}) { |
|
935 |
warn "select() relation option is DEPRECATED!"; |
|
936 |
$self->_add_relation_table($tables, $opt{relation}); |
|
937 |
} |
|
938 |
|
|
939 |
# Select statement |
|
940 |
my $sql = 'select '; |
|
941 |
|
|
942 |
# Prefix |
|
943 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
|
944 |
|
|
945 |
# Column |
|
946 |
if (defined $opt{column}) { |
|
947 |
my $columns |
|
948 |
= ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}]; |
|
949 |
for my $column (@$columns) { |
|
950 |
if (ref $column eq 'HASH') { |
|
951 |
$column = $self->column(%$column) if ref $column eq 'HASH'; |
|
952 |
} |
|
953 |
elsif (ref $column eq 'ARRAY') { |
|
954 |
warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" . |
|
955 |
"use q method to quote the value"; |
|
956 |
if (@$column == 3 && $column->[1] eq 'as') { |
|
957 |
warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]"; |
|
958 |
splice @$column, 1, 1; |
|
- added EXPERIMENTAL DBIx::C...
|
959 |
} |
cleanup
|
960 |
|
961 |
$column = join(' ', $column->[0], 'as', $self->q($column->[1])); |
|
962 |
} |
|
963 |
unshift @$tables, @{$self->_search_tables($column)}; |
|
964 |
$sql .= "$column, "; |
|
packaging one directory
|
965 |
} |
micro optimization
|
966 |
$sql =~ s/, $/ /; |
cleanup
|
967 |
} |
968 |
else { $sql .= '* ' } |
|
969 |
|
|
970 |
# Table |
|
971 |
$sql .= 'from '; |
|
972 |
if ($opt{relation}) { |
|
973 |
my $found = {}; |
|
974 |
for my $table (@$tables) { |
|
975 |
$sql .= $self->q($table) . ', ' unless $found->{$table}; |
|
976 |
$found->{$table} = 1; |
|
977 |
} |
|
978 |
} |
|
979 |
else { $sql .= $self->q($tables->[-1] || '') . ' ' } |
|
980 |
$sql =~ s/, $/ /; |
|
981 |
croak "select method table option must be specified " . _subname |
|
982 |
unless defined $tables->[-1]; |
|
983 | ||
984 |
# Add tables in parameter |
|
985 |
unshift @$tables, |
|
986 |
@{$self->_search_tables(join(' ', keys %$where_param) || '')}; |
|
987 |
|
|
988 |
# Where |
|
989 |
my $w = $self->_where_clause_and_param($opt{where}, $where_param, |
|
990 |
delete $opt{id}, $opt{primary_key}, $tables->[-1]); |
|
991 |
|
|
992 |
# Add table names in where clause |
|
993 |
unshift @$tables, @{$self->_search_tables($w->{clause})}; |
|
994 |
|
|
995 |
# Join statement |
|
996 |
$self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join}; |
|
997 |
|
|
998 |
# Add where clause |
|
999 |
$sql .= "$w->{clause} "; |
|
1000 |
|
|
1001 |
# Relation(DEPRECATED!); |
|
1002 |
$self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0) |
|
1003 |
if $opt{relation}; |
|
1004 |
|
|
1005 |
# Execute query |
|
1006 |
$opt{statement} = 'select'; |
|
1007 |
my $result = $self->execute($sql, $w->{param}, %opt); |
|
1008 |
|
|
1009 |
$result; |
|
packaging one directory
|
1010 |
} |
1011 | ||
add experimental setup_model...
|
1012 |
sub setup_model { |
cleanup
|
1013 |
my $self = shift; |
1014 |
|
|
1015 |
# Setup model |
|
1016 |
$self->each_column( |
|
1017 |
sub { |
|
1018 |
my ($self, $table, $column, $column_info) = @_; |
|
1019 |
if (my $model = $self->models->{$table}) { |
|
1020 |
push @{$model->columns}, $column; |
|
1021 |
} |
|
1022 |
} |
|
1023 |
); |
|
1024 |
return $self; |
|
add experimental setup_model...
|
1025 |
} |
1026 | ||
update pod
|
1027 |
sub show_datatype { |
cleanup
|
1028 |
my ($self, $table) = @_; |
1029 |
croak "Table name must be specified" unless defined $table; |
|
1030 |
print "$table\n"; |
|
1031 |
|
|
1032 |
my $result = $self->select(table => $table, where => "'0' <> '0'"); |
|
1033 |
my $sth = $result->sth; |
|
1034 | ||
1035 |
my $columns = $sth->{NAME}; |
|
1036 |
my $data_types = $sth->{TYPE}; |
|
1037 |
|
|
1038 |
for (my $i = 0; $i < @$columns; $i++) { |
|
1039 |
my $column = $columns->[$i]; |
|
1040 |
my $data_type = lc $data_types->[$i]; |
|
1041 |
print "$column: $data_type\n"; |
|
1042 |
} |
|
update pod
|
1043 |
} |
1044 | ||
1045 |
sub show_typename { |
|
cleanup
|
1046 |
my ($self, $t) = @_; |
1047 |
croak "Table name must be specified" unless defined $t; |
|
1048 |
print "$t\n"; |
|
1049 |
|
|
1050 |
$self->each_column(sub { |
|
1051 |
my ($self, $table, $column, $infos) = @_; |
|
1052 |
return unless $table eq $t; |
|
1053 |
my $typename = lc $infos->{TYPE_NAME}; |
|
1054 |
print "$column: $typename\n"; |
|
1055 |
}); |
|
1056 |
|
|
1057 |
return $self; |
|
update pod
|
1058 |
} |
1059 | ||
test cleanup
|
1060 |
sub show_tables { |
cleanup
|
1061 |
my $self = shift; |
1062 |
|
|
1063 |
my %tables; |
|
1064 |
$self->each_table(sub { $tables{$_[1]}++ }); |
|
1065 |
print join("\n", sort keys %tables) . "\n"; |
|
1066 |
return $self; |
|
test cleanup
|
1067 |
} |
1068 | ||
added type_rule method and f...
|
1069 |
sub type_rule { |
cleanup
|
1070 |
my $self = shift; |
1071 | ||
1072 |
$self->{_type_rule_is_called} = 1; |
|
1073 |
|
|
1074 |
if (@_) { |
|
1075 |
my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
1076 |
|
|
1077 |
# Into |
|
1078 |
for my $i (1 .. 2) { |
|
1079 |
my $into = "into$i"; |
|
1080 |
my $exists_into = exists $type_rule->{$into}; |
|
1081 |
$type_rule->{$into} = _array_to_hash($type_rule->{$into}); |
|
1082 |
$self->{type_rule} = $type_rule; |
|
1083 |
$self->{"_$into"} = {}; |
|
1084 |
for my $type_name (keys %{$type_rule->{$into} || {}}) { |
|
1085 |
croak qq{type name of $into section must be lower case} |
|
1086 |
if $type_name =~ /[A-Z]/; |
|
1087 |
} |
|
1088 |
|
|
1089 |
$self->each_column(sub { |
|
1090 |
my ($dbi, $table, $column, $column_info) = @_; |
|
fixed bug that type_rule fro...
|
1091 |
|
cleanup
|
1092 |
my $type_name = lc $column_info->{TYPE_NAME}; |
1093 |
if ($type_rule->{$into} && |
|
1094 |
(my $filter = $type_rule->{$into}->{$type_name})) |
|
1095 |
{ |
|
1096 |
return unless exists $type_rule->{$into}->{$type_name}; |
|
1097 |
if (defined $filter && ref $filter ne 'CODE') |
|
1098 |
{ |
|
1099 |
my $fname = $filter; |
|
1100 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
1101 |
unless exists $self->filters->{$fname}; |
|
cleanup
|
1102 |
|
cleanup
|
1103 |
$filter = $self->filters->{$fname}; |
1104 |
} |
|
EXPERIMENTAL type_rule argum...
|
1105 | |
cleanup
|
1106 |
$self->{"_$into"}{key}{$table}{$column} = $filter; |
1107 |
$self->{"_$into"}{dot}{"$table.$column"} = $filter; |
|
fixed bug that type_rule fro...
|
1108 |
} |
cleanup
|
1109 |
}); |
1110 |
} |
|
1111 | ||
1112 |
# From |
|
1113 |
for my $i (1 .. 2) { |
|
1114 |
$type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"}); |
|
1115 |
for my $data_type (keys %{$type_rule->{"from$i"} || {}}) { |
|
1116 |
croak qq{data type of from$i section must be lower case or number} |
|
1117 |
if $data_type =~ /[A-Z]/; |
|
1118 |
my $fname = $type_rule->{"from$i"}{$data_type}; |
|
1119 |
if (defined $fname && ref $fname ne 'CODE') { |
|
1120 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
1121 |
unless exists $self->filters->{$fname}; |
|
1122 |
|
|
1123 |
$type_rule->{"from$i"}{$data_type} = $self->filters->{$fname}; |
|
1124 |
} |
|
1125 |
} |
|
added type_rule method and f...
|
1126 |
} |
1127 |
|
|
cleanup
|
1128 |
return $self; |
1129 |
} |
|
1130 |
|
|
1131 |
return $self->{type_rule} || {}; |
|
added type_rule method and f...
|
1132 |
} |
1133 | ||
cleanup
|
1134 |
sub update { |
cleanup
|
1135 |
my $self = shift; |
1136 | ||
1137 |
# Options |
|
1138 |
my $param = @_ % 2 ? shift : undef; |
|
1139 |
my %opt = @_; |
|
1140 |
warn "update param option is DEPRECATED!" if $opt{param}; |
|
1141 |
warn "update method where_param option is DEPRECATED!" |
|
1142 |
if $opt{where_param}; |
|
1143 |
$param ||= $opt{param} || {}; |
|
1144 |
|
|
1145 |
# Don't allow update all rows |
|
1146 |
croak qq{update method where option must be specified } . _subname |
|
1147 |
if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all}; |
|
1148 |
|
|
1149 |
# Timestamp(DEPRECATED!) |
|
1150 |
if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) { |
|
1151 |
warn "update timestamp option is DEPRECATED! use updated_at and now method"; |
|
1152 |
my $columns = $update_timestamp->[0]; |
|
1153 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
|
1154 |
my $value = $update_timestamp->[1]; |
|
1155 |
$value = $value->() if ref $value eq 'CODE'; |
|
1156 |
$param->{$_} = $value for @$columns; |
|
1157 |
} |
|
1158 | ||
1159 |
# Created time and updated time |
|
1160 |
my @timestamp_cleanup; |
|
1161 |
if (defined $opt{updated_at}) { |
|
1162 |
my $now = $self->now; |
|
1163 |
$now = $now->() if ref $now eq 'CODE'; |
|
1164 |
$param->{$opt{updated_at}} = $self->now->(); |
|
1165 |
push @timestamp_cleanup, $opt{updated_at}; |
|
1166 |
} |
|
1167 | ||
1168 |
# Assign clause |
|
1169 |
my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}}); |
|
1170 |
|
|
1171 |
# Where |
|
1172 |
my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param}, |
|
1173 |
delete $opt{id}, $opt{primary_key}, $opt{table}); |
|
1174 |
|
|
1175 |
# Update statement |
|
1176 |
my $sql = "update "; |
|
1177 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
|
1178 |
$sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} "; |
|
1179 |
|
|
1180 |
# Execute query |
|
1181 |
$opt{statement} = 'update'; |
|
1182 |
$opt{cleanup} = \@timestamp_cleanup; |
|
1183 |
$self->execute($sql, [$param, $w->{param}], %opt); |
|
removed reconnect method
|
1184 |
} |
1185 | ||
cleanup
|
1186 |
sub update_all { shift->update(@_, allow_update_all => 1) }; |
cleanup
|
1187 | |
cleanup
|
1188 |
sub update_or_insert { |
cleanup
|
1189 |
my ($self, $param, %opt) = @_; |
1190 |
croak "update_or_insert method need primary_key and id option " |
|
1191 |
unless defined $opt{id} && defined $opt{primary_key}; |
|
1192 |
my $statement_opt = $opt{option} || {}; |
|
1193 | ||
1194 |
my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all; |
|
1195 |
if (@$rows == 0) { |
|
1196 |
return $self->insert($param, %opt, %{$statement_opt->{insert} || {}}); |
|
1197 |
} |
|
1198 |
elsif (@$rows == 1) { |
|
1199 |
return 0 unless keys %$param; |
|
1200 |
return $self->update($param, %opt, %{$statement_opt->{update} || {}}); |
|
1201 |
} |
|
1202 |
else { croak "selected row must be one " . _subname } |
|
cleanup
|
1203 |
} |
1204 | ||
- added EXPERIMENTAL update_...
|
1205 |
sub update_timestamp { |
cleanup
|
1206 |
my $self = shift; |
1207 |
|
|
1208 |
warn "update_timestamp method is DEPRECATED! use now method"; |
|
1209 |
|
|
1210 |
if (@_) { |
|
1211 |
$self->{update_timestamp} = [@_]; |
|
- added EXPERIMENTAL update_...
|
1212 |
|
cleanup
|
1213 |
return $self; |
1214 |
} |
|
1215 |
return $self->{update_timestamp}; |
|
- added EXPERIMENTAL update_...
|
1216 |
} |
1217 | ||
- method method of DBIx::Cus...
|
1218 |
sub values_clause { |
cleanup
|
1219 |
my ($self, $param, $opts) = @_; |
1220 |
|
|
1221 |
my $wrap = $opts->{wrap} || {}; |
|
1222 |
|
|
1223 |
# Create insert parameter tag |
|
1224 |
my ($q, $p) = split //, $self->q(''); |
|
1225 |
|
|
1226 |
# values clause(performance is important) |
|
1227 |
'(' . |
|
1228 |
join( |
|
1229 |
', ', |
|
1230 |
map { "$q$_$p" } sort keys %$param |
|
1231 |
) . |
|
1232 |
') values (' . |
|
1233 |
join( |
|
1234 |
', ', |
|
1235 |
map { |
|
1236 |
ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} : |
|
1237 |
$wrap->{$_} ? $wrap->{$_}->(":$_") : |
|
1238 |
":$_"; |
|
1239 |
} sort keys %$param |
|
1240 |
) . |
|
1241 |
')' |
|
- method method of DBIx::Cus...
|
1242 |
} |
1243 | ||
added EXPERIMENTAL bulk_inse...
|
1244 |
sub _multi_values_clause { |
cleanup
|
1245 |
my ($self, $params, $opts) = @_; |
1246 |
|
|
1247 |
my $wrap = $opts->{wrap} || {}; |
|
1248 |
|
|
1249 |
# Create insert parameter tag |
|
1250 |
my ($q, $p) = split //, $self->q(''); |
|
1251 |
|
|
1252 |
# Multi values clause |
|
1253 |
my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values '; |
|
1254 |
|
|
1255 |
for (1 .. @$params) { |
|
1256 |
$clause .= '(' . join(', ', |
|
1257 |
map { |
|
1258 |
ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} : |
|
1259 |
$wrap->{$_} ? $wrap->{$_}->(":$_") : |
|
1260 |
":$_"; |
|
1261 |
} sort keys %{$params->[0]} |
|
1262 |
) . '), ' |
|
1263 |
} |
|
1264 |
$clause =~ s/, $//; |
|
1265 |
return $clause; |
|
added EXPERIMENTAL bulk_inse...
|
1266 |
} |
1267 | ||
sub module use DBIx::Custom ...
|
1268 |
sub where { DBIx::Custom::Where->new(dbi => shift, @_) } |
added experimental DBIx::Cus...
|
1269 | |
updated pod
|
1270 |
sub _create_query { |
cleanup
|
1271 |
|
1272 |
my ($self, $source, $after_build_sql) = @_; |
|
1273 |
|
|
1274 |
# Cache |
|
1275 |
my $cache = $self->{cache}; |
|
1276 |
|
|
1277 |
# Query |
|
1278 |
my $query; |
|
1279 |
|
|
1280 |
# Get cached query |
|
1281 |
if ($cache) { |
|
1282 |
|
|
1283 |
# Get query |
|
1284 |
my $q = $self->cache_method->($self, $source); |
|
updated pod
|
1285 |
|
1286 |
# Create query |
|
cleanup
|
1287 |
if ($q) { |
1288 |
$query = DBIx::Custom::Query->new($q); |
|
1289 |
$query->{filters} = $self->filters; |
|
cleanup
|
1290 |
} |
cleanup
|
1291 |
} |
1292 |
|
|
1293 |
# Create query |
|
1294 |
unless ($query) { |
|
added EXPERIMENTAL execute m...
|
1295 | |
cleanup
|
1296 |
# Create query |
1297 |
my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE} |
|
1298 |
? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse}; |
|
1299 | ||
1300 |
my $sql = " " . $source || ''; |
|
1301 |
if ($tag_parse && ($sql =~ /\s\{/)) { |
|
1302 |
$query = $self->query_builder->build_query($sql); |
|
updated pod
|
1303 |
} |
cleanup
|
1304 |
else { |
1305 |
my @columns; |
|
1306 |
my $c = $self->{safety_character}; |
|
1307 |
my $re = $c eq 'a-zA-Z0-9_' |
|
1308 |
? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so |
|
1309 |
: qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s; |
|
1310 |
my %duplicate; |
|
1311 |
my $duplicate; |
|
1312 |
# Parameter regex |
|
1313 |
$sql =~ s/([0-9]):/$1\\:/g; |
|
1314 |
my $new_sql = ''; |
|
1315 |
while ($sql =~ /$re/) { |
|
1316 |
push @columns, $2; |
|
1317 |
$duplicate = 1 if ++$duplicate{$columns[-1]} > 1; |
|
1318 |
($new_sql, $sql) = defined $3 ? |
|
1319 |
($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4"); |
|
1320 |
} |
|
1321 |
$new_sql .= $sql; |
|
1322 |
$new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1; |
|
1323 | ||
1324 |
# Create query |
|
1325 |
$query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate}; |
|
1326 |
} |
|
1327 |
|
|
1328 |
# Save query to cache |
|
1329 |
$self->cache_method->( |
|
1330 |
$self, $source, |
|
1331 |
{ |
|
1332 |
sql => $query->{sql}, |
|
1333 |
columns => $query->{columns}, |
|
1334 |
tables => $query->{tables} || [] |
|
1335 |
} |
|
1336 |
) if $cache; |
|
1337 |
} |
|
1338 | ||
1339 |
# Filter SQL |
|
1340 |
$query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql; |
|
1341 |
|
|
1342 |
# Save sql |
|
1343 |
$self->{last_sql} = $query->{sql}; |
|
1344 |
|
|
1345 |
# Prepare statement handle |
|
1346 |
my $sth; |
|
1347 |
eval { $sth = $self->dbh->prepare($query->{sql}) }; |
|
1348 |
|
|
1349 |
if ($@) { |
|
1350 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
|
1351 |
. qq{$query->{sql}\n} . _subname); |
|
1352 |
} |
|
1353 |
|
|
1354 |
# Set statement handle |
|
1355 |
$query->{sth} = $sth; |
|
1356 |
|
|
1357 |
# Set filters |
|
1358 |
$query->{filters} = $self->{filters} || $self->filters; |
|
1359 |
|
|
1360 |
return $query; |
|
cleanup
|
1361 |
} |
1362 | ||
cleanup
|
1363 |
sub _create_bind_values { |
1364 |
my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_; |
|
1365 |
|
|
1366 |
$bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY'; |
|
1367 |
|
|
1368 |
# Create bind values |
|
1369 |
my @bind; |
|
1370 |
my @types; |
|
1371 |
my %count; |
|
1372 |
my %not_exists; |
|
1373 |
for my $column (@$columns) { |
|
1374 |
|
|
1375 |
# Bind value |
|
1376 |
if(ref $params->{$column} eq 'ARRAY') { |
|
1377 |
my $i = $count{$column} || 0; |
|
1378 |
$i += $not_exists{$column} || 0; |
|
1379 |
my $found; |
|
1380 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
1381 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
1382 |
$not_exists{$column}++; |
|
micro optimization
|
1383 |
} |
cleanup
|
1384 |
else { |
1385 |
push @bind, $params->{$column}->[$k]; |
|
1386 |
$found = 1; |
|
1387 |
last |
|
micro optimization
|
1388 |
} |
cleanup
|
1389 |
} |
1390 |
next unless $found; |
|
removed reconnect method
|
1391 |
} |
cleanup
|
1392 |
else { push @bind, $params->{$column} } |
removed reconnect method
|
1393 |
|
cleanup
|
1394 |
# Filter |
1395 |
if (my $f = $filter->{$column} || $self->{default_out_filter} || '') { |
|
1396 |
$bind[-1] = $f->($bind[-1]); |
|
1397 |
} |
|
improved error messages
|
1398 |
|
cleanup
|
1399 |
# Type rule |
1400 |
if ($self->{_type_rule_is_called}) { |
|
1401 |
my $tf1 = $self->{"_into1"}->{dot}->{$column} |
|
1402 |
|| $type_filters->{1}->{$column}; |
|
1403 |
$bind[-1] = $tf1->($bind[-1]) if $tf1; |
|
1404 |
my $tf2 = $self->{"_into2"}->{dot}->{$column} |
|
1405 |
|| $type_filters->{2}->{$column}; |
|
1406 |
$bind[-1] = $tf2->($bind[-1]) if $tf2; |
|
improved error messages
|
1407 |
} |
cleanup
|
1408 |
|
1409 |
# Bind types |
|
1410 |
push @types, $bind_type->{$column}; |
|
improved error messages
|
1411 |
|
cleanup
|
1412 |
# Count up |
1413 |
$count{$column}++; |
|
1414 |
} |
|
1415 |
|
|
1416 |
return (\@bind, \@types); |
|
1417 |
} |
|
1418 | ||
1419 |
sub _id_to_param { |
|
1420 |
my ($self, $id, $primary_keys, $table) = @_; |
|
1421 |
|
|
1422 |
# Check primary key |
|
1423 |
croak "primary_key option " . |
|
1424 |
"must be specified when id option is used" . _subname |
|
1425 |
unless defined $primary_keys; |
|
1426 |
$primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY'; |
|
1427 |
|
|
1428 |
# Create parameter |
|
1429 |
my $param = {}; |
|
1430 |
if (defined $id) { |
|
1431 |
$id = [$id] unless ref $id; |
|
1432 |
for(my $i = 0; $i < @$id; $i++) { |
|
1433 |
my $key = $primary_keys->[$i]; |
|
1434 |
$key = "$table." . $key if $table; |
|
1435 |
$param->{$key} = $id->[$i]; |
|
1436 |
} |
|
1437 |
} |
|
1438 |
|
|
1439 |
return $param; |
|
improved error messages
|
1440 |
} |
1441 | ||
EXPERIMETAL fork safety impl...
|
1442 |
sub _connect { |
cleanup
|
1443 |
my $self = shift; |
1444 |
|
|
1445 |
# Attributes |
|
1446 |
my $dsn = $self->data_source; |
|
1447 |
warn "data_source is DEPRECATED!\n" |
|
1448 |
if $dsn; |
|
1449 |
$dsn ||= $self->dsn; |
|
1450 |
croak qq{"dsn" must be specified } . _subname |
|
1451 |
unless $dsn; |
|
1452 |
my $user = $self->user; |
|
1453 |
my $password = $self->password; |
|
1454 |
my $option = $self->_option; |
|
1455 |
$option = {%{$self->default_option}, %$option}; |
|
1456 |
|
|
1457 |
# Connect |
|
1458 |
my $dbh; |
|
1459 |
eval { $dbh = DBI->connect($dsn, $user, $password, $option) }; |
|
1460 |
|
|
1461 |
# Connect error |
|
1462 |
croak "$@ " . _subname if $@; |
|
1463 |
|
|
1464 |
return $dbh; |
|
EXPERIMETAL fork safety impl...
|
1465 |
} |
1466 | ||
cleanup
|
1467 |
sub _croak { |
cleanup
|
1468 |
my ($self, $error, $append) = @_; |
1469 |
|
|
1470 |
# Append |
|
1471 |
$append ||= ""; |
|
1472 |
|
|
1473 |
# Verbose |
|
1474 |
if ($Carp::Verbose) { croak $error } |
|
1475 |
|
|
1476 |
# Not verbose |
|
1477 |
else { |
|
1478 |
# Remove line and module infromation |
|
1479 |
my $at_pos = rindex($error, ' at '); |
|
1480 |
$error = substr($error, 0, $at_pos); |
|
1481 |
$error =~ s/\s+$//; |
|
1482 |
croak "$error$append"; |
|
1483 |
} |
|
cleanup
|
1484 |
} |
1485 | ||
prepare oracle test
|
1486 |
sub _driver { lc shift->{dbh}->{Driver}->{Name} } |
1487 | ||
added select() all_column op...
|
1488 |
sub _need_tables { |
cleanup
|
1489 |
my ($self, $tree, $need_tables, $tables) = @_; |
1490 |
|
|
1491 |
# Get needed tables |
|
1492 |
for my $table (@$tables) { |
|
1493 |
if ($tree->{$table}) { |
|
1494 |
$need_tables->{$table} = 1; |
|
1495 |
$self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}]) |
|
added select() all_column op...
|
1496 |
} |
cleanup
|
1497 |
} |
added select() all_column op...
|
1498 |
} |
1499 | ||
- dbi_option attribute is re...
|
1500 |
sub _option { |
cleanup
|
1501 |
my $self = shift; |
1502 |
my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}}; |
|
1503 |
warn "dbi_options is DEPRECATED! use option instead\n" |
|
1504 |
if keys %{$self->dbi_options}; |
|
1505 |
warn "dbi_option is DEPRECATED! use option instead\n" |
|
1506 |
if keys %{$self->dbi_option}; |
|
1507 |
return $option; |
|
- dbi_option attribute is re...
|
1508 |
} |
1509 | ||
fixed some select() join opi...
|
1510 |
sub _push_join { |
cleanup
|
1511 |
my ($self, $sql, $join, $join_tables) = @_; |
1512 |
|
|
1513 |
$join = [$join] unless ref $join eq 'ARRAY'; |
|
1514 |
|
|
1515 |
# No join |
|
1516 |
return unless @$join; |
|
1517 |
|
|
1518 |
# Push join clause |
|
1519 |
my $tree = {}; |
|
1520 |
for (my $i = 0; $i < @$join; $i++) { |
|
1521 |
|
|
1522 |
# Arrange |
|
1523 |
my $join_clause;; |
|
1524 |
my $option; |
|
1525 |
if (ref $join->[$i] eq 'HASH') { |
|
1526 |
$join_clause = $join->[$i]->{clause}; |
|
1527 |
$option = {table => $join->[$i]->{table}}; |
|
fixed some select() join opi...
|
1528 |
} |
cleanup
|
1529 |
else { |
1530 |
$join_clause = $join->[$i]; |
|
1531 |
$option = {}; |
|
1532 |
}; |
|
1533 | ||
1534 |
# Find tables in join clause |
|
1535 |
my $table1; |
|
1536 |
my $table2; |
|
1537 |
if (my $table = $option->{table}) { |
|
1538 |
$table1 = $table->[0]; |
|
1539 |
$table2 = $table->[1]; |
|
1540 |
} |
|
1541 |
else { |
|
1542 |
my $q = $self->_quote; |
|
1543 |
my $j_clause = (split /\s+on\s+/, $join_clause)[-1]; |
|
1544 |
$j_clause =~ s/'.+?'//g; |
|
1545 |
my $q_re = quotemeta($q); |
|
1546 |
$j_clause =~ s/[$q_re]//g; |
|
1547 |
|
|
1548 |
my @j_clauses = reverse split /\s(and|on)\s/, $j_clause; |
|
1549 |
my $c = $self->{safety_character}; |
|
1550 |
my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm; |
|
1551 |
for my $clause (@j_clauses) { |
|
1552 |
if ($clause =~ $join_re) { |
|
1553 |
$table1 = $1; |
|
1554 |
$table2 = $2; |
|
1555 |
last; |
|
1556 |
} |
|
1557 |
} |
|
1558 |
} |
|
1559 |
croak qq{join clause must have two table name after "on" keyword. } . |
|
1560 |
qq{"$join_clause" is passed } . _subname |
|
1561 |
unless defined $table1 && defined $table2; |
|
1562 |
croak qq{right side table of "$join_clause" must be unique } . _subname |
|
1563 |
if exists $tree->{$table2}; |
|
1564 |
croak qq{Same table "$table1" is specified} . _subname |
|
1565 |
if $table1 eq $table2; |
|
1566 |
$tree->{$table2} |
|
1567 |
= {position => $i, parent => $table1, join => $join_clause}; |
|
1568 |
} |
|
1569 |
|
|
1570 |
# Search need tables |
|
1571 |
my $need_tables = {}; |
|
1572 |
$self->_need_tables($tree, $need_tables, $join_tables); |
|
1573 |
my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } |
|
1574 |
keys %$need_tables; |
|
1575 |
|
|
1576 |
# Add join clause |
|
1577 |
$$sql .= $tree->{$_}{join} . ' ' for @need_tables; |
|
fixed some select() join opi...
|
1578 |
} |
cleanup
|
1579 | |
reserved_word_quote is DEPRE...
|
1580 |
sub _quote { |
cleanup
|
1581 |
my $self = shift; |
1582 |
return $self->{reserved_word_quote} || $self->quote || ''; |
|
reserved_word_quote is DEPRE...
|
1583 |
} |
1584 | ||
cleanup
|
1585 |
sub _remove_duplicate_table { |
cleanup
|
1586 |
my ($self, $tables, $main_table) = @_; |
1587 |
|
|
1588 |
# Remove duplicate table |
|
1589 |
my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables; |
|
1590 |
delete $tables{$main_table} if $main_table; |
|
1591 |
|
|
1592 |
my $new_tables = [keys %tables, $main_table ? $main_table : ()]; |
|
1593 |
if (my $q = $self->_quote) { |
|
1594 |
$q = quotemeta($q); |
|
1595 |
$_ =~ s/[$q]//g for @$new_tables; |
|
1596 |
} |
|
micro optimization
|
1597 | |
cleanup
|
1598 |
return $new_tables; |
cleanup
|
1599 |
} |
1600 | ||
cleanup
|
1601 |
sub _search_tables { |
cleanup
|
1602 |
my ($self, $source) = @_; |
1603 |
|
|
1604 |
# Search tables |
|
1605 |
my $tables = []; |
|
1606 |
my $safety_character = $self->{safety_character}; |
|
1607 |
my $q = $self->_quote; |
|
1608 |
my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1); |
|
1609 |
my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./ |
|
1610 |
: qr/(?:^|[^$safety_character])([$safety_character]+)\./; |
|
1611 |
while ($source =~ /$table_re/g) { push @$tables, $1 } |
|
1612 |
return $tables; |
|
cleanup
|
1613 |
} |
1614 | ||
cleanup
|
1615 |
sub _where_clause_and_param { |
cleanup
|
1616 |
my ($self, $where, $where_param, $id, $primary_key, $table) = @_; |
1617 | ||
1618 |
$where ||= {}; |
|
1619 |
$where = $self->_id_to_param($id, $primary_key, $table) if defined $id; |
|
1620 |
$where_param ||= {}; |
|
1621 |
my $w = {}; |
|
1622 |
my $where_clause = ''; |
|
1623 | ||
1624 |
my $obj; |
|
1625 |
|
|
1626 |
if (ref $where) { |
|
1627 |
if (ref $where eq 'HASH') { |
|
1628 |
my $clause = ['and']; |
|
1629 |
my $column_join = ''; |
|
1630 |
for my $column (keys %$where) { |
|
1631 |
$column_join .= $column; |
|
1632 |
my $table; |
|
1633 |
my $c; |
|
1634 |
if ($column =~ /(?:(.*?)\.)?(.*)/) { |
|
1635 |
$table = $1; |
|
1636 |
$c = $2; |
|
cleanup
|
1637 |
} |
1638 |
|
|
cleanup
|
1639 |
my $table_quote; |
1640 |
$table_quote = $self->q($table) if defined $table; |
|
1641 |
my $column_quote = $self->q($c); |
|
1642 |
$column_quote = $table_quote . '.' . $column_quote |
|
1643 |
if defined $table_quote; |
|
1644 |
push @$clause, "$column_quote = :$column"; |
|
1645 |
} |
|
1646 | ||
1647 |
# Check unsafety column |
|
1648 |
my $safety = $self->{safety_character}; |
|
1649 |
unless ($column_join =~ /^[$safety\.]+$/) { |
|
1650 |
for my $column (keys %$where) { |
|
1651 |
croak qq{"$column" is not safety column name } . _subname |
|
1652 |
unless $column =~ /^[$safety\.]+$/; |
|
1653 |
} |
|
1654 |
} |
|
1655 |
|
|
1656 |
$obj = $self->where(clause => $clause, param => $where); |
|
1657 |
} |
|
1658 |
elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where } |
|
1659 |
elsif (ref $where eq 'ARRAY') { |
|
1660 |
$obj = $self->where(clause => $where->[0], param => $where->[1]); |
|
1661 |
} |
|
1662 |
|
|
1663 |
# Check where argument |
|
1664 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
|
1665 |
. qq{or array reference, which contains where clause and parameter} |
|
1666 |
. _subname |
|
1667 |
unless ref $obj eq 'DBIx::Custom::Where'; |
|
1668 | ||
1669 |
$w->{param} = keys %$where_param |
|
1670 |
? $self->merge_param($where_param, $obj->param) |
|
1671 |
: $obj->param; |
|
1672 |
$w->{clause} = $obj->to_string; |
|
1673 |
} |
|
1674 |
elsif ($where) { |
|
1675 |
$w->{clause} = "where $where"; |
|
1676 |
$w->{param} = $where_param; |
|
1677 |
} |
|
1678 |
|
|
1679 |
return $w; |
|
cleanup
|
1680 |
} |
1681 | ||
updated pod
|
1682 |
sub _apply_filter { |
cleanup
|
1683 |
my ($self, $table, @cinfos) = @_; |
1684 | ||
1685 |
# Initialize filters |
|
1686 |
$self->{filter} ||= {}; |
|
1687 |
$self->{filter}{on} = 1; |
|
1688 |
$self->{filter}{out} ||= {}; |
|
1689 |
$self->{filter}{in} ||= {}; |
|
1690 |
$self->{filter}{end} ||= {}; |
|
1691 |
|
|
1692 |
# Usage |
|
1693 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
1694 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
|
1695 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
1696 |
|
|
1697 |
# Apply filter |
|
1698 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
updated pod
|
1699 |
|
cleanup
|
1700 |
# Column |
1701 |
my $column = $cinfos[$i]; |
|
1702 |
if (ref $column eq 'ARRAY') { |
|
1703 |
for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] } |
|
1704 |
next; |
|
1705 |
} |
|
updated pod
|
1706 |
|
cleanup
|
1707 |
# Filter infomation |
1708 |
my $finfo = $cinfos[$i + 1] || {}; |
|
1709 |
croak "$usage (table: $table) " . _subname |
|
1710 |
unless ref $finfo eq 'HASH'; |
|
1711 |
for my $ftype (keys %$finfo) { |
|
1712 |
croak "$usage (table: $table) " . _subname |
|
1713 |
unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; |
|
updated pod
|
1714 |
} |
1715 |
|
|
cleanup
|
1716 |
# Set filters |
1717 |
for my $way (qw/in out end/) { |
|
1718 |
|
|
1719 |
# Filter |
|
1720 |
my $filter = $finfo->{$way}; |
|
1721 |
|
|
1722 |
# Filter state |
|
1723 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
1724 |
: !defined $filter ? 'not_defined' |
|
1725 |
: ref $filter eq 'CODE' ? 'code' |
|
1726 |
: 'name'; |
|
1727 |
|
|
1728 |
# Filter is not exists |
|
1729 |
next if $state eq 'not_exists'; |
|
1730 |
|
|
1731 |
# Check filter name |
|
1732 |
croak qq{Filter "$filter" is not registered } . _subname |
|
1733 |
if $state eq 'name' && ! exists $self->filters->{$filter}; |
|
1734 |
|
|
1735 |
# Set filter |
|
1736 |
my $f = $state eq 'not_defined' ? undef |
|
1737 |
: $state eq 'code' ? $filter |
|
1738 |
: $self->filters->{$filter}; |
|
1739 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
1740 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
1741 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
1742 |
$self->{filter}{$way}{$table}{"${table}-$column"} = $f; |
|
1743 |
} |
|
1744 |
} |
|
1745 |
|
|
1746 |
return $self; |
|
updated pod
|
1747 |
} |
1748 | ||
- update_param is DEPRECATED...
|
1749 |
# DEPRECATED! |
1750 |
has 'data_source'; |
|
1751 |
has dbi_options => sub { {} }; |
|
1752 |
has filter_check => 1; |
|
1753 |
has 'reserved_word_quote'; |
|
- dbi_option attribute is re...
|
1754 |
has dbi_option => sub { {} }; |
1755 |
has default_dbi_option => sub { |
|
cleanup
|
1756 |
warn "default_dbi_option is DEPRECATED! use default_option instead"; |
1757 |
return shift->default_option; |
|
- dbi_option attribute is re...
|
1758 |
}; |
1759 | ||
- DBIx::Custom::QueryBuilder...
|
1760 |
# DEPRECATED |
1761 |
sub tag_parse { |
|
cleanup
|
1762 |
my $self = shift; |
1763 |
warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " . |
|
1764 |
"environment variable"; |
|
1765 |
if (@_) { |
|
1766 |
$self->{tag_parse} = $_[0]; |
|
1767 |
return $self; |
|
1768 |
} |
|
1769 |
return $self->{tag_parse}; |
|
- DBIx::Custom::QueryBuilder...
|
1770 |
} |
1771 | ||
- method method of DBIx::Cus...
|
1772 |
# DEPRECATED! |
1773 |
sub method { |
|
cleanup
|
1774 |
warn "method is DEPRECATED! use helper instead"; |
1775 |
return shift->helper(@_); |
|
- method method of DBIx::Cus...
|
1776 |
} |
- update_param is DEPRECATED...
|
1777 | |
1778 |
# DEPRECATED! |
|
1779 |
sub assign_param { |
|
cleanup
|
1780 |
my $self = shift; |
1781 |
warn "assing_param is DEPRECATED! use assign_clause instead"; |
|
1782 |
return $self->assign_clause(@_); |
|
- update_param is DEPRECATED...
|
1783 |
} |
1784 | ||
1785 |
# DEPRECATED |
|
1786 |
sub update_param { |
|
cleanup
|
1787 |
my ($self, $param, $opts) = @_; |
1788 |
|
|
1789 |
warn "update_param is DEPRECATED! use assign_clause instead."; |
|
1790 |
|
|
1791 |
# Create update parameter tag |
|
1792 |
my $tag = $self->assign_clause($param, $opts); |
|
1793 |
$tag = "set $tag" unless $opts->{no_set}; |
|
- update_param is DEPRECATED...
|
1794 | |
cleanup
|
1795 |
return $tag; |
- update_param is DEPRECATED...
|
1796 |
} |
1797 | ||
updated pod
|
1798 |
# DEPRECATED! |
1799 |
sub create_query { |
|
cleanup
|
1800 |
warn "create_query is DEPRECATED! use query option of each method"; |
1801 |
shift->_create_query(@_); |
|
updated pod
|
1802 |
} |
1803 | ||
cleanup
|
1804 |
# DEPRECATED! |
1805 |
sub apply_filter { |
|
cleanup
|
1806 |
my $self = shift; |
1807 |
|
|
1808 |
warn "apply_filter is DEPRECATED!"; |
|
1809 |
return $self->_apply_filter(@_); |
|
cleanup
|
1810 |
} |
1811 | ||
select_at is DEPRECATED! use...
|
1812 |
# DEPRECATED! |
1813 |
sub select_at { |
|
cleanup
|
1814 |
my ($self, %opt) = @_; |
1815 | ||
1816 |
warn "select_at is DEPRECATED! use select method id option instead"; |
|
1817 | ||
1818 |
# Options |
|
1819 |
my $primary_keys = delete $opt{primary_key}; |
|
1820 |
my $where = delete $opt{where}; |
|
1821 |
my $param = delete $opt{param}; |
|
1822 |
|
|
1823 |
# Table |
|
1824 |
croak qq{"table" option must be specified } . _subname |
|
1825 |
unless $opt{table}; |
|
1826 |
my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table}; |
|
1827 |
|
|
1828 |
# Create where parameter |
|
1829 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
|
1830 |
|
|
1831 |
return $self->select(where => $where_param, %opt); |
|
select_at is DEPRECATED! use...
|
1832 |
} |
1833 | ||
delete_at is DEPRECATED! use...
|
1834 |
# DEPRECATED! |
1835 |
sub delete_at { |
|
cleanup
|
1836 |
my ($self, %opt) = @_; |
updated pod
|
1837 | |
cleanup
|
1838 |
warn "delete_at is DEPRECATED! use delete method id option instead"; |
1839 |
|
|
1840 |
# Options |
|
1841 |
my $primary_keys = delete $opt{primary_key}; |
|
1842 |
my $where = delete $opt{where}; |
|
1843 |
|
|
1844 |
# Create where parameter |
|
1845 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
|
1846 |
|
|
1847 |
return $self->delete(where => $where_param, %opt); |
|
delete_at is DEPRECATED! use...
|
1848 |
} |
1849 | ||
cleanup
|
1850 |
# DEPRECATED! |
1851 |
sub update_at { |
|
cleanup
|
1852 |
my $self = shift; |
1853 | ||
1854 |
warn "update_at is DEPRECATED! use update method id option instead"; |
|
1855 |
|
|
1856 |
# Options |
|
1857 |
my $param; |
|
1858 |
$param = shift if @_ % 2; |
|
1859 |
my %opt = @_; |
|
1860 |
my $primary_keys = delete $opt{primary_key}; |
|
1861 |
my $where = delete $opt{where}; |
|
1862 |
my $p = delete $opt{param} || {}; |
|
1863 |
$param ||= $p; |
|
1864 |
|
|
1865 |
# Create where parameter |
|
1866 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
|
1867 |
|
|
1868 |
return $self->update(where => $where_param, param => $param, %opt); |
|
cleanup
|
1869 |
} |
1870 | ||
insert_at is DEPRECATED! add...
|
1871 |
# DEPRECATED! |
1872 |
sub insert_at { |
|
cleanup
|
1873 |
my $self = shift; |
1874 |
|
|
1875 |
warn "insert_at is DEPRECATED! use insert method id option instead"; |
|
1876 |
|
|
1877 |
# Options |
|
1878 |
my $param; |
|
1879 |
$param = shift if @_ % 2; |
|
1880 |
my %opt = @_; |
|
1881 |
my $primary_key = delete $opt{primary_key}; |
|
1882 |
$primary_key = [$primary_key] unless ref $primary_key; |
|
1883 |
my $where = delete $opt{where}; |
|
1884 |
my $p = delete $opt{param} || {}; |
|
1885 |
$param ||= $p; |
|
1886 |
|
|
1887 |
# Create where parameter |
|
1888 |
my $where_param = $self->_id_to_param($where, $primary_key); |
|
1889 |
$param = $self->merge_param($where_param, $param); |
|
1890 |
|
|
1891 |
return $self->insert(param => $param, %opt); |
|
insert_at is DEPRECATED! add...
|
1892 |
} |
1893 | ||
added warnings
|
1894 |
# DEPRECATED! |
1895 |
sub register_tag { |
|
cleanup
|
1896 |
my $self = shift; |
1897 |
|
|
1898 |
warn "register_tag is DEPRECATED!"; |
|
1899 |
|
|
1900 |
# Merge tag |
|
1901 |
my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
1902 |
$self->{_tags} = {%{$self->{_tags} || {}}, %$tags}; |
|
1903 |
|
|
1904 |
return $self; |
|
test cleanup
|
1905 |
} |
1906 | ||
1907 |
# DEPRECATED! |
|
1908 |
sub register_tag_processor { |
|
cleanup
|
1909 |
my $self = shift; |
1910 |
warn "register_tag_processor is DEPRECATED!"; |
|
1911 |
# Merge tag |
|
1912 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
1913 |
$self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}}; |
|
1914 |
return $self; |
|
added warnings
|
1915 |
} |
1916 | ||
cleanup
|
1917 |
# DEPRECATED! |
cleanup
|
1918 |
sub default_bind_filter { |
cleanup
|
1919 |
my $self = shift; |
1920 |
|
|
1921 |
warn "default_bind_filter is DEPRECATED!"; |
|
1922 |
|
|
1923 |
if (@_) { |
|
1924 |
my $fname = $_[0]; |
|
added warnings
|
1925 |
|
cleanup
|
1926 |
if (@_ && !$fname) { |
1927 |
$self->{default_out_filter} = undef; |
|
cleanup
|
1928 |
} |
cleanup
|
1929 |
else { |
1930 |
croak qq{Filter "$fname" is not registered} |
|
1931 |
unless exists $self->filters->{$fname}; |
|
1932 |
|
|
1933 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1934 |
} |
|
1935 |
return $self; |
|
1936 |
} |
|
1937 |
|
|
1938 |
return $self->{default_out_filter}; |
|
cleanup
|
1939 |
} |
1940 | ||
cleanup
|
1941 |
# DEPRECATED! |
cleanup
|
1942 |
sub default_fetch_filter { |
cleanup
|
1943 |
my $self = shift; |
added warnings
|
1944 | |
cleanup
|
1945 |
warn "default_fetch_filter is DEPRECATED!"; |
1946 |
|
|
1947 |
if (@_) { |
|
1948 |
my $fname = $_[0]; |
|
many changed
|
1949 | |
cleanup
|
1950 |
if (@_ && !$fname) { |
1951 |
$self->{default_in_filter} = undef; |
|
1952 |
} |
|
1953 |
else { |
|
1954 |
croak qq{Filter "$fname" is not registered} |
|
1955 |
unless exists $self->filters->{$fname}; |
|
1956 |
|
|
1957 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
cleanup
|
1958 |
} |
1959 |
|
|
cleanup
|
1960 |
return $self; |
1961 |
} |
|
1962 |
|
|
1963 |
return $self->{default_in_filter}; |
|
cleanup
|
1964 |
} |
1965 | ||
- update_param is DEPRECATED...
|
1966 |
# DEPRECATED! |
1967 |
sub insert_param { |
|
cleanup
|
1968 |
my $self = shift; |
1969 |
warn "insert_param is DEPRECATED! use values_clause instead"; |
|
1970 |
return $self->values_clause(@_); |
|
- update_param is DEPRECATED...
|
1971 |
} |
1972 | ||
- renamed update_param to up...
|
1973 |
# DEPRECATED! |
- update_param_tag is DEPREC...
|
1974 |
sub insert_param_tag { |
cleanup
|
1975 |
warn "insert_param_tag is DEPRECATED! " . |
1976 |
"use insert_param instead!"; |
|
1977 |
return shift->insert_param(@_); |
|
- renamed update_param to up...
|
1978 |
} |
1979 | ||
1980 |
# DEPRECATED! |
|
- update_param_tag is DEPREC...
|
1981 |
sub update_param_tag { |
cleanup
|
1982 |
warn "update_param_tag is DEPRECATED! " . |
1983 |
"use update_param instead"; |
|
1984 |
return shift->update_param(@_); |
|
- renamed update_param to up...
|
1985 |
} |
cleanup
|
1986 |
# DEPRECATED! |
1987 |
sub _push_relation { |
|
cleanup
|
1988 |
my ($self, $sql, $tables, $relation, $need_where) = @_; |
1989 |
|
|
1990 |
if (keys %{$relation || {}}) { |
|
1991 |
$$sql .= $need_where ? 'where ' : 'and '; |
|
1992 |
for my $rcolumn (keys %$relation) { |
|
1993 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
1994 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1995 |
push @$tables, ($table1, $table2); |
|
1996 |
$$sql .= "$rcolumn = " . $relation->{$rcolumn} . 'and '; |
|
cleanup
|
1997 |
} |
cleanup
|
1998 |
} |
1999 |
$$sql =~ s/and $/ /; |
|
cleanup
|
2000 |
} |
2001 | ||
2002 |
# DEPRECATED! |
|
2003 |
sub _add_relation_table { |
|
cleanup
|
2004 |
my ($self, $tables, $relation) = @_; |
2005 |
|
|
2006 |
if (keys %{$relation || {}}) { |
|
2007 |
for my $rcolumn (keys %$relation) { |
|
2008 |
my $table1 = (split (/\./, $rcolumn))[0]; |
|
2009 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
2010 |
my $table1_exists; |
|
2011 |
my $table2_exists; |
|
2012 |
for my $table (@$tables) { |
|
2013 |
$table1_exists = 1 if $table eq $table1; |
|
2014 |
$table2_exists = 1 if $table eq $table2; |
|
2015 |
} |
|
2016 |
unshift @$tables, $table1 unless $table1_exists; |
|
2017 |
unshift @$tables, $table2 unless $table2_exists; |
|
2018 |
} |
|
2019 |
} |
|
cleanup
|
2020 |
} |
2021 | ||
fixed DBIx::Custom::QueryBui...
|
2022 |
1; |
2023 | ||
removed reconnect method
|
2024 |
=head1 NAME |
2025 | ||
moved DBIx::Custom::Guide to...
|
2026 |
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily |
removed reconnect method
|
2027 | |
fix heading typos
|
2028 |
=head1 SYNOPSIS |
cleanup
|
2029 | |
cleanup
|
2030 |
use DBIx::Custom; |
2031 |
|
|
2032 |
# Connect |
|
2033 |
my $dbi = DBIx::Custom->connect( |
|
2034 |
dsn => "dbi:mysql:database=dbname", |
|
2035 |
user => 'ken', |
|
2036 |
password => '!LFKD%$&', |
|
2037 |
option => {mysql_enable_utf8 => 1} |
|
2038 |
); |
|
2039 | ||
2040 |
# Insert |
|
2041 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
|
2042 |
|
|
2043 |
# Update |
|
2044 |
$dbi->update({title => 'Perl', author => 'Ken'}, table => 'book', |
|
2045 |
where => {id => 5}); |
|
2046 |
|
|
2047 |
# Delete |
|
2048 |
$dbi->delete(table => 'book', where => {author => 'Ken'}); |
|
2049 | ||
2050 |
# Select |
|
2051 |
my $result = $dbi->select(table => 'book', |
|
2052 |
column => ['title', 'author'], where => {author => 'Ken'}); |
|
2053 | ||
2054 |
# Select, more complex |
|
2055 |
my $result = $dbi->select( |
|
2056 |
table => 'book', |
|
2057 |
column => [ |
|
2058 |
{book => [qw/title author/]}, |
|
2059 |
{company => ['name']} |
|
2060 |
], |
|
2061 |
where => {'book.author' => 'Ken'}, |
|
2062 |
join => ['left outer join company on book.company_id = company.id'], |
|
2063 |
append => 'order by id limit 5' |
|
2064 |
); |
|
2065 |
|
|
2066 |
# Fetch |
|
2067 |
while (my $row = $result->fetch) { |
|
2068 |
|
|
2069 |
} |
|
2070 |
|
|
2071 |
# Fetch as hash |
|
2072 |
while (my $row = $result->fetch_hash) { |
|
2073 |
|
|
2074 |
} |
|
2075 |
|
|
2076 |
# Execute SQL with parameter. |
|
2077 |
$dbi->execute( |
|
2078 |
"select id from book where author = :author and title like :title", |
|
2079 |
{author => 'ken', title => '%Perl%'} |
|
2080 |
); |
|
2081 |
|
|
fix heading typos
|
2082 |
=head1 DESCRIPTION |
removed reconnect method
|
2083 | |
cleanup
|
2084 |
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily. |
updated pod
|
2085 |
This module have the following features. |
- remaned experimental safty...
|
2086 | |
updated pod
|
2087 |
=over 4 |
- remaned experimental safty...
|
2088 | |
cleanup
|
2089 |
=item * |
- remaned experimental safty...
|
2090 | |
cleanup
|
2091 |
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily |
- remaned experimental safty...
|
2092 | |
cleanup
|
2093 |
=item * |
- remaned experimental safty...
|
2094 | |
cleanup
|
2095 |
Create C<where> clause flexibly |
- remaned experimental safty...
|
2096 | |
cleanup
|
2097 |
=item * |
- remaned experimental safty...
|
2098 | |
micro optimization
|
2099 |
Named place holder support |
2100 | ||
2101 |
=item * |
|
2102 | ||
cleanup
|
2103 |
Model support |
2104 | ||
2105 |
=item * |
|
2106 | ||
2107 |
Connection manager support |
|
2108 | ||
2109 |
=item * |
|
pod fix
|
2110 | |
cleanup
|
2111 |
Choice your favorite relational database management system, |
cleanup
|
2112 |
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>, |
2113 |
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, |
|
2114 | ||
2115 |
=item * |
|
2116 | ||
- removed EXPERIMENTAL flag ...
|
2117 |
Filtering by data type or column name |
cleanup
|
2118 | |
2119 |
=item * |
|
2120 | ||
- removed EXPERIMENTAL flag ...
|
2121 |
Create C<order by> clause flexibly |
cleanup
|
2122 | |
2123 |
=back |
|
pod fix
|
2124 | |
fix heading typos
|
2125 |
=head1 DOCUMENTATION |
pod fix
|
2126 | |
cleanup
|
2127 |
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom> |
pod fix
|
2128 | |
- remaned experimental safty...
|
2129 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> |
cleanup
|
2130 |
- Theare are various examples. |
2131 | ||
micro optimization
|
2132 |
Module documentations - |
cleanup
|
2133 |
L<DBIx::Custom::Result>, |
2134 |
L<DBIx::Custom::Query>, |
|
2135 |
L<DBIx::Custom::Where>, |
|
2136 |
L<DBIx::Custom::Model>, |
|
2137 |
L<DBIx::Custom::Order> |
|
updated document
|
2138 | |
update document
|
2139 |
=head1 ATTRIBUTES |
packaging one directory
|
2140 | |
- removed DEPRECATED DBIx::C...
|
2141 |
=head2 C<connector> |
- removed EXPERIMENTAL Prefo...
|
2142 | |
cleanup
|
2143 |
my $connector = $dbi->connector; |
2144 |
$dbi = $dbi->connector($connector); |
|
- removed EXPERIMENTAL Prefo...
|
2145 | |
micro optimization
|
2146 |
Connection manager object. if C<connector> is set, you can get C<dbh> |
2147 |
through connection manager. Conection manager object must have C<dbh> mehtod. |
|
- removed EXPERIMENTAL Prefo...
|
2148 | |
2149 |
This is L<DBIx::Connector> example. Please pass |
|
- dbi_option attribute is re...
|
2150 |
C<default_option> to L<DBIx::Connector> C<new> method. |
- removed EXPERIMENTAL Prefo...
|
2151 | |
cleanup
|
2152 |
my $connector = DBIx::Connector->new( |
2153 |
"dbi:mysql:database=$database", |
|
2154 |
$user, |
|
2155 |
$password, |
|
2156 |
DBIx::Custom->new->default_option |
|
2157 |
); |
|
2158 |
|
|
2159 |
my $dbi = DBIx::Custom->connect(connector => $connector); |
|
- removed EXPERIMENTAL Prefo...
|
2160 | |
cleanup
|
2161 |
If C<connector> is set to 1 when connect method is called, |
2162 |
L<DBIx::Connector> is automatically set to C<connector> |
|
2163 | ||
cleanup
|
2164 |
my $dbi = DBIx::Custom->connect( |
2165 |
dsn => $dsn, user => $user, password => $password, connector => 1); |
|
2166 |
|
|
2167 |
my $connector = $dbi->connector; # DBIx::Connector |
|
cleanup
|
2168 | |
2169 |
Note that L<DBIx::Connector> must be installed. |
|
2170 | ||
data_source is DEPRECATED! I...
|
2171 |
=head2 C<dsn> |
2172 | ||
cleanup
|
2173 |
my $dsn = $dbi->dsn; |
2174 |
$dbi = $dbi->dsn("DBI:mysql:database=dbname"); |
|
packaging one directory
|
2175 | |
updated pod
|
2176 |
Data source name, used when C<connect> method is executed. |
removed DESTROY method(not b...
|
2177 | |
- dbi_option attribute is re...
|
2178 |
=head2 C<default_option> |
add default_dbi_option()
|
2179 | |
cleanup
|
2180 |
my $default_option = $dbi->default_option; |
2181 |
$dbi = $dbi->default_option($default_option); |
|
add default_dbi_option()
|
2182 | |
updated pod
|
2183 |
L<DBI> default option, used when C<connect> method is executed, |
- remaned experimental safty...
|
2184 |
default to the following values. |
add default_dbi_option()
|
2185 | |
cleanup
|
2186 |
{ |
2187 |
RaiseError => 1, |
|
2188 |
PrintError => 0, |
|
2189 |
AutoCommit => 1, |
|
2190 |
} |
|
packaging one directory
|
2191 | |
removed EXPERIMETNAL flag fr...
|
2192 |
=head2 C<exclude_table> |
2193 | ||
cleanup
|
2194 |
my $exclude_table = $dbi->exclude_table; |
2195 |
$dbi = $dbi->exclude_table(qr/pg_/); |
|
removed EXPERIMETNAL flag fr...
|
2196 | |
2197 |
Excluded table regex. |
|
2198 |
C<each_column>, C<each_table>, C<type_rule>, |
|
2199 |
and C<setup_model> methods ignore matching tables. |
|
2200 | ||
cleanup
|
2201 |
=head2 C<filters> |
bind_filter argument is chan...
|
2202 | |
cleanup
|
2203 |
my $filters = $dbi->filters; |
2204 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
2205 | |
updated pod
|
2206 |
Filters, registered by C<register_filter> method. |
add models() attribute
|
2207 | |
- removed EXPERIMENTAL statu...
|
2208 |
=head2 C<last_sql> |
added EXPERIMENTAL last_sql ...
|
2209 | |
cleanup
|
2210 |
my $last_sql = $dbi->last_sql; |
2211 |
$dbi = $dbi->last_sql($last_sql); |
|
added EXPERIMENTAL last_sql ...
|
2212 | |
2213 |
Get last successed SQL executed by C<execute> method. |
|
2214 | ||
- id option work if id count...
|
2215 |
=head2 C<now> |
- insert timestamp option is...
|
2216 | |
cleanup
|
2217 |
my $now = $dbi->now; |
2218 |
$dbi = $dbi->now($now); |
|
- insert timestamp option is...
|
2219 | |
- id option work if id count...
|
2220 |
Code reference which return current time, default to the following code reference. |
- insert timestamp option is...
|
2221 | |
cleanup
|
2222 |
sub { |
2223 |
my ($sec, $min, $hour, $mday, $mon, $year) = localtime; |
|
2224 |
$mon++; |
|
2225 |
$year += 1900; |
|
2226 |
return sprintf("%04d-%02d-%02d %02d:%02d:%02d"); |
|
2227 |
} |
|
- insert timestamp option is...
|
2228 | |
- id option work if id count...
|
2229 |
This return the time like C<2011-10-14 05:05:27>. |
2230 | ||
2231 |
This is used by C<insert> method's C<created_at> option and C<updated_at> option, |
|
2232 |
and C<update> method's C<updated_at> option. |
|
- insert timestamp option is...
|
2233 | |
- removed DEPRECATED DBIx::C...
|
2234 |
=head2 C<models> |
add models() attribute
|
2235 | |
cleanup
|
2236 |
my $models = $dbi->models; |
2237 |
$dbi = $dbi->models(\%models); |
|
add models() attribute
|
2238 | |
updated pod
|
2239 |
Models, included by C<include_model> method. |
add models() attribute
|
2240 | |
removed EXPERIMETNAL flag fr...
|
2241 |
=head2 C<option> |
2242 | ||
cleanup
|
2243 |
my $option = $dbi->option; |
2244 |
$dbi = $dbi->option($option); |
|
removed EXPERIMETNAL flag fr...
|
2245 | |
2246 |
L<DBI> option, used when C<connect> method is executed. |
|
2247 |
Each value in option override the value of C<default_option>. |
|
2248 | ||
cleanup
|
2249 |
=head2 C<password> |
2250 | ||
cleanup
|
2251 |
my $password = $dbi->password; |
2252 |
$dbi = $dbi->password('lkj&le`@s'); |
|
cleanup
|
2253 | |
updated pod
|
2254 |
Password, used when C<connect> method is executed. |
update document
|
2255 | |
renamed update tag to update...
|
2256 |
=head2 C<query_builder> |
added commit method
|
2257 | |
cleanup
|
2258 |
my $builder = $dbi->query_builder; |
added commit method
|
2259 | |
test cleanup
|
2260 |
Creat query builder. This is L<DBIx::Custom::QueryBuilder>. |
cleanup
|
2261 | |
reserved_word_quote is DEPRE...
|
2262 |
=head2 C<quote> |
added EXPERIMENTAL reserved_...
|
2263 | |
cleanup
|
2264 |
my quote = $dbi->quote; |
2265 |
$dbi = $dbi->quote('"'); |
|
added EXPERIMENTAL reserved_...
|
2266 | |
DBIx::Custom::Model type att...
|
2267 |
Reserved word quote. |
2268 |
Default to double quote '"' except for mysql. |
|
2269 |
In mysql, default to back quote '`' |
|
added EXPERIMENTAL reserved_...
|
2270 | |
cleanup
|
2271 |
You can set quote pair. |
2272 | ||
cleanup
|
2273 |
$dbi->quote('[]'); |
cleanup
|
2274 | |
cleanup
|
2275 |
=head2 C<result_class> |
cleanup
|
2276 | |
cleanup
|
2277 |
my $result_class = $dbi->result_class; |
2278 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
2279 | |
- remaned experimental safty...
|
2280 |
Result class, default to L<DBIx::Custom::Result>. |
cleanup
|
2281 | |
removed EXPERIMETNAL flag fr...
|
2282 |
=head2 C<safety_character> |
update pod
|
2283 | |
cleanup
|
2284 |
my $safety_character = $dbi->safety_character; |
2285 |
$dbi = $dbi->safety_character($character); |
|
update pod
|
2286 | |
update pod
|
2287 |
Regex of safety character for table and column name, default to '\w'. |
cleanup
|
2288 |
Note that you don't have to specify like '[\w]'. |
update pod
|
2289 | |
cleanup test
|
2290 |
=head2 C<separator> |
2291 | ||
cleanup
|
2292 |
my $separator = $dbi->separator; |
2293 |
$dbi = $dbi->separator('-'); |
|
improved join clause parsing
|
2294 | |
2295 |
Separator which join table name and column name. |
|
2296 |
This have effect to C<column> and C<mycolumn> method, |
|
2297 |
and C<select> method's column option. |
|
cleanup test
|
2298 | |
improved join clause parsing
|
2299 |
Default to C<.>. |
cleanup test
|
2300 | |
added tag_parse attribute
|
2301 |
=head2 C<tag_parse> |
2302 | ||
cleanup
|
2303 |
my $tag_parse = $dbi->tag_parse(0); |
2304 |
$dbi = $dbi->tag_parse; |
|
added tag_parse attribute
|
2305 | |
2306 |
Enable DEPRECATED tag parsing functionality, default to 1. |
|
2307 |
If you want to disable tag parsing functionality, set to 0. |
|
2308 | ||
cleanup
|
2309 |
=head2 C<user> |
cleanup
|
2310 | |
cleanup
|
2311 |
my $user = $dbi->user; |
2312 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
2313 | |
updated pod
|
2314 |
User name, used when C<connect> method is executed. |
update pod
|
2315 | |
- removed EXPERIMENTAL flag ...
|
2316 |
=head2 C<user_column_info> |
- added EXPERIMENTAL get_col...
|
2317 | |
cleanup
|
2318 |
my $user_column_info = $dbi->user_column_info; |
2319 |
$dbi = $dbi->user_column_info($user_column_info); |
|
- added EXPERIMENTAL get_col...
|
2320 | |
improved join clause parsing
|
2321 |
You can set the date like the following one. |
- added EXPERIMENTAL get_col...
|
2322 | |
cleanup
|
2323 |
[ |
2324 |
{table => 'book', column => 'title', info => {...}}, |
|
2325 |
{table => 'author', column => 'name', info => {...}} |
|
2326 |
] |
|
- added EXPERIMENTAL get_col...
|
2327 | |
improved join clause parsing
|
2328 |
Usually, you set return value of C<get_column_info>. |
- added EXPERIMENTAL get_col...
|
2329 | |
cleanup
|
2330 |
my $user_column_info |
2331 |
= $dbi->get_column_info(exclude_table => qr/^system/); |
|
2332 |
$dbi->user_column_info($user_column_info); |
|
- added EXPERIMENTAL get_col...
|
2333 | |
2334 |
If C<user_column_info> is set, C<each_column> use C<user_column_info> |
|
- removed EXPERIMENTAL flag ...
|
2335 |
to find column info. this is very fast. |
- added EXPERIMENTAL get_col...
|
2336 | |
- removed EXPERIMENTAL flag ...
|
2337 |
=head2 C<user_table_info> |
added test
|
2338 | |
cleanup
|
2339 |
my $user_table_info = $dbi->user_table_info; |
2340 |
$dbi = $dbi->user_table_info($user_table_info); |
|
added test
|
2341 | |
2342 |
You can set the following data. |
|
2343 | ||
cleanup
|
2344 |
[ |
2345 |
{table => 'book', info => {...}}, |
|
2346 |
{table => 'author', info => {...}} |
|
2347 |
] |
|
added test
|
2348 | |
2349 |
Usually, you can set return value of C<get_table_info>. |
|
2350 | ||
cleanup
|
2351 |
my $user_table_info = $dbi->get_table_info(exclude => qr/^system/); |
2352 |
$dbi->user_table_info($user_table_info); |
|
added test
|
2353 | |
2354 |
If C<user_table_info> is set, C<each_table> use C<user_table_info> |
|
2355 |
to find table info. |
|
2356 | ||
cleanup
|
2357 |
=head1 METHODS |
added commit method
|
2358 | |
cleanup
|
2359 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
cleanup
|
2360 |
and use all methods of L<DBI> |
cleanup
|
2361 |
and implements the following new ones. |
added check_filter attribute
|
2362 | |
- removed EXPERIMENTAL flag ...
|
2363 |
=head2 C<available_datatype> |
changed type_rule arguments ...
|
2364 | |
cleanup
|
2365 |
print $dbi->available_datatype; |
changed type_rule arguments ...
|
2366 | |
added EXPERIMENTAL available...
|
2367 |
Get available data types. You can use these data types |
updated pod
|
2368 |
in C<type rule>'s C<from1> and C<from2> section. |
added EXPERIMENTAL available...
|
2369 | |
- removed EXPERIMENTAL flag ...
|
2370 |
=head2 C<available_typename> |
added EXPERIMENTAL available...
|
2371 | |
cleanup
|
2372 |
print $dbi->available_typename; |
added EXPERIMENTAL available...
|
2373 | |
2374 |
Get available type names. You can use these type names in |
|
updated pod
|
2375 |
C<type_rule>'s C<into1> and C<into2> section. |
changed type_rule arguments ...
|
2376 | |
- update_param is DEPRECATED...
|
2377 |
=head2 C<assign_clause> |
added EXPERIMENTAL assign_ta...
|
2378 | |
cleanup
|
2379 |
my $assign_clause = $dbi->assign_clause({title => 'a', age => 2}); |
added EXPERIMENTAL assign_ta...
|
2380 | |
- update_param is DEPRECATED...
|
2381 |
Create assign clause |
added EXPERIMENTAL assign_ta...
|
2382 | |
cleanup
|
2383 |
title = :title, author = :author |
added EXPERIMENTAL assign_ta...
|
2384 | |
- update_param is DEPRECATED...
|
2385 |
This is used to create update clause. |
2386 | ||
cleanup
|
2387 |
"update book set " . $dbi->assign_clause({title => 'a', age => 2}); |
added EXPERIMENTAL assign_ta...
|
2388 | |
added EXPERIMENTAL parameter...
|
2389 |
=head2 C<column> |
- select() EXPERIMETNAL colu...
|
2390 | |
cleanup
|
2391 |
my $column = $dbi->column(book => ['author', 'title']); |
- select() EXPERIMETNAL colu...
|
2392 | |
2393 |
Create column clause. The follwoing column clause is created. |
|
2394 | ||
cleanup
|
2395 |
book.author as "book.author", |
2396 |
book.title as "book.title" |
|
- select() EXPERIMETNAL colu...
|
2397 | |
cleanup test
|
2398 |
You can change separator by C<separator> attribute. |
- select() EXPERIMETNAL colu...
|
2399 | |
cleanup
|
2400 |
# Separator is hyphen |
2401 |
$dbi->separator('-'); |
|
2402 |
|
|
2403 |
book.author as "book-author", |
|
2404 |
book.title as "book-title" |
|
2405 |
|
|
removed DBIx::Custom commit ...
|
2406 |
=head2 C<connect> |
packaging one directory
|
2407 | |
cleanup
|
2408 |
my $dbi = DBIx::Custom->connect( |
2409 |
dsn => "dbi:mysql:database=dbname", |
|
2410 |
user => 'ken', |
|
2411 |
password => '!LFKD%$&', |
|
2412 |
option => {mysql_enable_utf8 => 1} |
|
2413 |
); |
|
update pod
|
2414 | |
2415 |
Connect to the database and create a new L<DBIx::Custom> object. |
|
bind_filter argument is chan...
|
2416 | |
renamed build_query to creat...
|
2417 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
2418 |
C<AutoCommit> and C<RaiseError> options are true, |
update pod
|
2419 |
and C<PrintError> option is false by default. |
packaging one directory
|
2420 | |
- removed EXPERIMENTAL flag ...
|
2421 |
=head2 C<count> |
- added EXPERIMENTAL DBIx::C...
|
2422 | |
cleanup
|
2423 |
my $count = $dbi->count(table => 'book'); |
- added EXPERIMENTAL DBIx::C...
|
2424 | |
2425 |
Get rows count. |
|
2426 | ||
2427 |
Options is same as C<select> method's ones. |
|
2428 | ||
2429 |
=head2 C<create_model> |
|
removed EXPERIMETNAL flag fr...
|
2430 | |
cleanup
|
2431 |
my $model = $dbi->create_model( |
2432 |
table => 'book', |
|
2433 |
primary_key => 'id', |
|
2434 |
join => [ |
|
2435 |
'inner join company on book.comparny_id = company.id' |
|
2436 |
], |
|
2437 |
); |
|
removed EXPERIMETNAL flag fr...
|
2438 | |
2439 |
Create L<DBIx::Custom::Model> object and initialize model. |
|
updated pod
|
2440 |
the module is also used from C<model> method. |
removed EXPERIMETNAL flag fr...
|
2441 | |
cleanup
|
2442 |
$dbi->model('book')->select(...); |
removed EXPERIMETNAL flag fr...
|
2443 | |
EXPERIMETAL fork safety impl...
|
2444 |
=head2 C<dbh> |
2445 | ||
cleanup
|
2446 |
my $dbh = $dbi->dbh; |
EXPERIMETAL fork safety impl...
|
2447 | |
- removed EXPERIMENTAL Prefo...
|
2448 |
Get L<DBI> database handle. if C<connector> is set, you can get |
updated pod
|
2449 |
database handle through C<connector> object. |
removed EXPERIMETNAL flag fr...
|
2450 | |
added EXPERIMENTAL find_tabl...
|
2451 |
=head2 C<delete> |
2452 | ||
cleanup
|
2453 |
$dbi->delete(table => 'book', where => {title => 'Perl'}); |
added EXPERIMENTAL find_tabl...
|
2454 | |
2455 |
Execute delete statement. |
|
2456 | ||
2457 |
The following opitons are available. |
|
2458 | ||
cleanup
|
2459 |
B<OPTIONS> |
added EXPERIMENTAL find_tabl...
|
2460 | |
cleanup
|
2461 |
C<delete> method use all of C<execute> method's options, |
2462 |
and use the following new ones. |
|
added EXPERIMENTAL find_tabl...
|
2463 | |
cleanup
|
2464 |
=over 4 |
added EXPERIMENTAL find_tabl...
|
2465 | |
2466 |
=item C<id> |
|
2467 | ||
cleanup
|
2468 |
id => 4 |
2469 |
id => [4, 5] |
|
added EXPERIMENTAL find_tabl...
|
2470 | |
2471 |
ID corresponding to C<primary_key>. |
|
2472 |
You can delete rows by C<id> and C<primary_key>. |
|
2473 | ||
cleanup
|
2474 |
$dbi->delete( |
2475 |
primary_key => ['id1', 'id2'], |
|
2476 |
id => [4, 5], |
|
2477 |
table => 'book', |
|
2478 |
); |
|
added EXPERIMENTAL find_tabl...
|
2479 | |
2480 |
The above is same as the followin one. |
|
2481 | ||
cleanup
|
2482 |
$dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book'); |
added EXPERIMENTAL find_tabl...
|
2483 | |
2484 |
=item C<prefix> |
|
2485 | ||
cleanup
|
2486 |
prefix => 'some' |
added EXPERIMENTAL find_tabl...
|
2487 | |
2488 |
prefix before table name section. |
|
2489 | ||
cleanup
|
2490 |
delete some from book |
added EXPERIMENTAL find_tabl...
|
2491 | |
2492 |
=item C<table> |
|
2493 | ||
cleanup
|
2494 |
table => 'book' |
added EXPERIMENTAL find_tabl...
|
2495 | |
2496 |
Table name. |
|
2497 | ||
2498 |
=item C<where> |
|
2499 | ||
2500 |
Same as C<select> method's C<where> option. |
|
2501 | ||
2502 |
=back |
|
2503 | ||
2504 |
=head2 C<delete_all> |
|
2505 | ||
cleanup
|
2506 |
$dbi->delete_all(table => $table); |
added EXPERIMENTAL find_tabl...
|
2507 | |
2508 |
Execute delete statement for all rows. |
|
2509 |
Options is same as C<delete>. |
|
2510 | ||
removed EXPERIMETNAL flag fr...
|
2511 |
=head2 C<each_column> |
2512 | ||
cleanup
|
2513 |
$dbi->each_column( |
2514 |
sub { |
|
2515 |
my ($dbi, $table, $column, $column_info) = @_; |
|
2516 |
|
|
2517 |
my $type = $column_info->{TYPE_NAME}; |
|
2518 |
|
|
2519 |
if ($type eq 'DATE') { |
|
2520 |
# ... |
|
2521 |
} |
|
2522 |
} |
|
2523 |
); |
|
removed EXPERIMETNAL flag fr...
|
2524 | |
improved pod
|
2525 |
Iterate all column informations in database. |
2526 |
Argument is callback which is executed when one column is found. |
|
2527 |
Callback receive four arguments. C<DBIx::Custom object>, C<table name>, |
|
2528 |
C<column name>, and C<column information>. |
|
2529 | ||
2530 |
If C<user_column_info> is set, C<each_column> method use C<user_column_info> |
|
2531 |
infromation, you can improve the performance of C<each_column> in |
|
2532 |
the following way. |
|
2533 | ||
cleanup
|
2534 |
my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/); |
2535 |
$dbi->user_column_info($column_info); |
|
2536 |
$dbi->each_column(sub { ... }); |
|
EXPERIMETAL fork safety impl...
|
2537 | |
- removed EXPERIMENTAL statu...
|
2538 |
=head2 C<each_table> |
added EXPERIMENTAL each_tabl...
|
2539 | |
cleanup
|
2540 |
$dbi->each_table( |
2541 |
sub { |
|
2542 |
my ($dbi, $table, $table_info) = @_; |
|
2543 |
|
|
2544 |
my $table_name = $table_info->{TABLE_NAME}; |
|
2545 |
} |
|
2546 |
); |
|
added EXPERIMENTAL each_tabl...
|
2547 | |
improved pod
|
2548 |
Iterate all table informationsfrom in database. |
2549 |
Argument is callback which is executed when one table is found. |
|
2550 |
Callback receive three arguments, C<DBIx::Custom object>, C<table name>, |
|
2551 |
C<table information>. |
|
2552 | ||
2553 |
If C<user_table_info> is set, C<each_table> method use C<user_table_info> |
|
2554 |
infromation, you can improve the performance of C<each_table> in |
|
2555 |
the following way. |
|
2556 | ||
cleanup
|
2557 |
my $table_infos = $dbi->get_table_info(exclude => qr/^system_/); |
2558 |
$dbi->user_table_info($table_info); |
|
2559 |
$dbi->each_table(sub { ... }); |
|
added EXPERIMENTAL each_tabl...
|
2560 | |
cleanup
|
2561 |
=head2 C<execute> |
packaging one directory
|
2562 | |
cleanup
|
2563 |
my $result = $dbi->execute( |
2564 |
"select * from book where title = :title and author like :author", |
|
2565 |
{title => 'Perl', author => '%Ken%'} |
|
2566 |
); |
|
updated pod
|
2567 | |
cleanup
|
2568 |
my $result = $dbi->execute( |
2569 |
"select * from book where title = :book.title and author like :book.author", |
|
2570 |
{'book.title' => 'Perl', 'book.author' => '%Ken%'} |
|
2571 |
); |
|
update pod
|
2572 | |
updated pod
|
2573 |
Execute SQL. SQL can contain column parameter such as :author and :title. |
2574 |
You can append table name to column name such as :book.title and :book.author. |
|
2575 |
Second argunet is data, embedded into column parameter. |
|
2576 |
Return value is L<DBIx::Custom::Result> object when select statement is executed, |
|
2577 |
or the count of affected rows when insert, update, delete statement is executed. |
|
update pod
|
2578 | |
I call :title named placehol...
|
2579 |
Named placeholder such as C<:title> is replaced by placeholder C<?>. |
cleanup
|
2580 |
|
2581 |
# Original |
|
2582 |
select * from book where title = :title and author like :author |
|
2583 |
|
|
2584 |
# Replaced |
|
2585 |
select * from where title = ? and author like ?; |
|
update pod
|
2586 | |
I call :title named placehol...
|
2587 |
You can specify operator with named placeholder |
fixed pod
|
2588 |
by C<name{operator}> syntax. |
added EXPERIMENTAL parameter...
|
2589 | |
cleanup
|
2590 |
# Original |
2591 |
select * from book where :title{=} and :author{like} |
|
2592 |
|
|
2593 |
# Replaced |
|
2594 |
select * from where title = ? and author like ?; |
|
update pod
|
2595 | |
fixed named placeholder bug ...
|
2596 |
Note that colons in time format such as 12:13:15 is exeption, |
2597 |
it is not parsed as named placeholder. |
|
2598 |
If you want to use colon generally, you must escape it by C<\\> |
|
2599 | ||
cleanup
|
2600 |
select * from where title = "aa\\:bb"; |
fixed named placeholder bug ...
|
2601 | |
cleanup
|
2602 |
B<OPTIONS> |
2603 | ||
updated pod
|
2604 |
The following opitons are available. |
update pod
|
2605 | |
2606 |
=over 4 |
|
2607 | ||
added EXPERIMENTAL reuse_sth...
|
2608 |
=item C<after_build_sql> |
2609 | ||
2610 |
You can filter sql after the sql is build. |
|
2611 | ||
cleanup
|
2612 |
after_build_sql => $code_ref |
added EXPERIMENTAL reuse_sth...
|
2613 | |
2614 |
The following one is one example. |
|
2615 | ||
cleanup
|
2616 |
$dbi->select( |
2617 |
table => 'book', |
|
2618 |
column => 'distinct(name)', |
|
2619 |
after_build_sql => sub { |
|
2620 |
"select count(*) from ($_[0]) as t1" |
|
2621 |
} |
|
2622 |
); |
|
added EXPERIMENTAL reuse_sth...
|
2623 | |
2624 |
The following SQL is executed. |
|
2625 | ||
cleanup
|
2626 |
select count(*) from (select distinct(name) from book) as t1; |
added EXPERIMENTAL reuse_sth...
|
2627 | |
cleanup
|
2628 |
=item C<append> |
2629 | ||
cleanup
|
2630 |
append => 'order by name' |
cleanup
|
2631 | |
2632 |
Append some statement after SQL. |
|
2633 | ||
added EXPERIMENTAL execute m...
|
2634 |
=item C<bind_type> |
2635 | ||
2636 |
Specify database bind data type. |
|
2637 | ||
cleanup
|
2638 |
bind_type => [image => DBI::SQL_BLOB] |
2639 |
bind_type => [[qw/image audio/] => DBI::SQL_BLOB] |
|
added EXPERIMENTAL execute m...
|
2640 | |
2641 |
This is used to bind parameter by C<bind_param> of statment handle. |
|
2642 | ||
cleanup
|
2643 |
$sth->bind_param($pos, $value, DBI::SQL_BLOB); |
added EXPERIMENTAL execute m...
|
2644 | |
update pod
|
2645 |
=item C<filter> |
cleanup
|
2646 |
|
2647 |
filter => { |
|
2648 |
title => sub { uc $_[0] } |
|
2649 |
author => sub { uc $_[0] } |
|
2650 |
} |
|
2651 | ||
2652 |
# Filter name |
|
2653 |
filter => { |
|
2654 |
title => 'upper_case', |
|
2655 |
author => 'upper_case' |
|
2656 |
} |
|
2657 |
|
|
2658 |
# At once |
|
2659 |
filter => [ |
|
2660 |
[qw/title author/] => sub { uc $_[0] } |
|
2661 |
] |
|
updated pod
|
2662 | |
separate DBIx::Custom type_r...
|
2663 |
Filter. You can set subroutine or filter name |
updated pod
|
2664 |
registered by by C<register_filter>. |
separate DBIx::Custom type_r...
|
2665 |
This filter is executed before data is saved into database. |
2666 |
and before type rule filter is executed. |
|
added EXPERIMENTAL execute()...
|
2667 | |
updated document
|
2668 |
=item C<query> |
2669 | ||
cleanup
|
2670 |
query => 1 |
updated document
|
2671 | |
DBIx::Custom::Query is DEPRE...
|
2672 |
C<execute> method return hash reference which contain SQL and column |
2673 |
infromation |
|
updated pod
|
2674 | |
cleanup
|
2675 |
my $sql = $query->{sql}; |
2676 |
my $columns = $query->{columns}; |
|
2677 |
|
|
- DBIx::Custom::QueryBuilder...
|
2678 |
=item C<reuse> |
cleanup
|
2679 |
|
2680 |
reuse => $hash_ref |
|
- DBIx::Custom::QueryBuilder...
|
2681 | |
2682 |
Reuse query object if the hash reference variable is set. |
|
cleanup
|
2683 |
|
2684 |
my $queries = {}; |
|
2685 |
$dbi->execute($sql, $param, reuse => $queries); |
|
- DBIx::Custom::QueryBuilder...
|
2686 | |
2687 |
This will improved performance when you want to execute same query repeatedly |
|
2688 |
because generally creating query object is slow. |
|
2689 | ||
- removed placeholder count ...
|
2690 |
=item C<primary_key> |
2691 | ||
cleanup
|
2692 |
primary_key => 'id' |
2693 |
primary_key => ['id1', 'id2'] |
|
cleanup
|
2694 | |
execute method id option is ...
|
2695 |
Priamry key. This is used for C<id> option. |
- removed placeholder count ...
|
2696 | |
updated pod
|
2697 |
=item C<table> |
cleanup
|
2698 |
|
2699 |
table => 'author' |
|
updated pod
|
2700 | |
updated pod
|
2701 |
If you want to omit table name in column name |
2702 |
and enable C<into1> and C<into2> type filter, |
|
2703 |
You must set C<table> option. |
|
updated pod
|
2704 | |
cleanup
|
2705 |
$dbi->execute("select * from book where title = :title and author = :author", |
2706 |
{title => 'Perl', author => 'Ken', table => 'book'); |
|
updated pod
|
2707 | |
cleanup
|
2708 |
# Same |
2709 |
$dbi->execute( |
|
2710 |
"select * from book where title = :book.title and author = :book.author", |
|
2711 |
{title => 'Perl', author => 'Ken'); |
|
added EXPERIMENTAL execute()...
|
2712 | |
- removed EXPERIMENTAL flag ...
|
2713 |
=item C<table_alias> |
added EXPERIMENTAL execute m...
|
2714 | |
cleanup
|
2715 |
table_alias => {user => 'worker'} |
added EXPERIMENTAL execute m...
|
2716 | |
2717 |
Table alias. Key is real table name, value is alias table name. |
|
2718 |
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule |
|
2719 |
on alias table name. |
|
2720 | ||
- removed EXPERIMENTAL flag ...
|
2721 |
=item C<type_rule_off> |
added EXPERIMENTAL execute()...
|
2722 | |
cleanup
|
2723 |
type_rule_off => 1 |
added EXPERIMENTAL execute()...
|
2724 | |
EXPERIMENTAL type_rule argum...
|
2725 |
Turn C<into1> and C<into2> type rule off. |
2726 | ||
- removed EXPERIMENTAL flag ...
|
2727 |
=item C<type_rule1_off> |
EXPERIMENTAL type_rule argum...
|
2728 | |
cleanup
|
2729 |
type_rule1_off => 1 |
EXPERIMENTAL type_rule argum...
|
2730 | |
2731 |
Turn C<into1> type rule off. |
|
2732 | ||
- removed EXPERIMENTAL flag ...
|
2733 |
=item C<type_rule2_off> |
EXPERIMENTAL type_rule argum...
|
2734 | |
cleanup
|
2735 |
type_rule2_off => 1 |
EXPERIMENTAL type_rule argum...
|
2736 | |
2737 |
Turn C<into2> type rule off. |
|
update document
|
2738 | |
update pod
|
2739 |
=back |
version 0.0901
|
2740 | |
- removed EXPERIMENTAL flag ...
|
2741 |
=head2 C<get_column_info> |
- added EXPERIMENTAL get_col...
|
2742 | |
cleanup
|
2743 |
my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/); |
- added EXPERIMENTAL get_col...
|
2744 | |
2745 |
get column infomation except for one which match C<exclude_table> pattern. |
|
2746 | ||
cleanup
|
2747 |
[ |
2748 |
{table => 'book', column => 'title', info => {...}}, |
|
2749 |
{table => 'author', column => 'name' info => {...}} |
|
2750 |
] |
|
- added EXPERIMENTAL get_col...
|
2751 | |
- removed EXPERIMENTAL flag ...
|
2752 |
=head2 C<get_table_info> |
added test
|
2753 | |
cleanup
|
2754 |
my $table_infos = $dbi->get_table_info(exclude => qr/^system_/); |
update pod
|
2755 | |
added test
|
2756 |
get table infomation except for one which match C<exclude> pattern. |
2757 | ||
cleanup
|
2758 |
[ |
2759 |
{table => 'book', info => {...}}, |
|
2760 |
{table => 'author', info => {...}} |
|
2761 |
] |
|
add experimental update_at()...
|
2762 | |
added test
|
2763 |
You can set this value to C<user_table_info>. |
update pod
|
2764 | |
removed EXPERIMETNAL flag fr...
|
2765 |
=head2 C<helper> |
2766 | ||
cleanup
|
2767 |
$dbi->helper( |
2768 |
find_or_create => sub { |
|
2769 |
my $self = shift; |
|
2770 |
|
|
2771 |
# Process |
|
2772 |
}, |
|
2773 |
... |
|
2774 |
); |
|
removed EXPERIMETNAL flag fr...
|
2775 | |
2776 |
Register helper. These helper is called directly from L<DBIx::Custom> object. |
|
2777 | ||
cleanup
|
2778 |
$dbi->find_or_create; |
removed EXPERIMETNAL flag fr...
|
2779 | |
cleanup
|
2780 |
=head2 C<insert> |
2781 | ||
cleanup
|
2782 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
update pod
|
2783 | |
updated pod
|
2784 |
Execute insert statement. First argument is row data. Return value is |
2785 |
affected row count. |
|
update pod
|
2786 | |
insert and update method's p...
|
2787 |
If you want to set constant value to row data, use scalar reference |
2788 |
as parameter value. |
|
2789 | ||
cleanup
|
2790 |
{date => \"NOW()"} |
insert and update method's p...
|
2791 | |
updated pod
|
2792 |
You can pass multiple parameters, this is very fast. |
2793 |
This is EXPERIMETNAL. |
|
2794 | ||
cleanup
|
2795 |
$dbi->insert( |
2796 |
[ |
|
2797 |
{title => 'Perl', author => 'Ken'}, |
|
2798 |
{title => 'Ruby', author => 'Tom'} |
|
2799 |
], |
|
2800 |
table => 'book' |
|
2801 |
); |
|
updated pod
|
2802 | |
2803 |
In multiple insert, you can't use C<id> option. |
|
2804 |
and only first parameter is used by creating sql. |
|
2805 | ||
cleanup
|
2806 |
B<options> |
2807 | ||
cleanup
|
2808 |
C<insert> method use all of C<execute> method's options, |
cleanup
|
2809 |
and use the following new ones. |
update pod
|
2810 | |
cleanup
|
2811 |
=over 4 |
improved bulk_insert perform...
|
2812 |
b |
added EXPERIMENTAL bulk_inse...
|
2813 |
=item C<bulk_insert> EXPERIMENTAL |
2814 | ||
cleanup
|
2815 |
bulk_insert => 1 |
added EXPERIMENTAL bulk_inse...
|
2816 | |
2817 |
bulk insert is executed if database support bulk insert and |
|
2818 |
multiple parameters is passed to C<insert>. |
|
2819 |
The SQL like the following one is executed. |
|
2820 | ||
cleanup
|
2821 |
insert into book (id, title) values (?, ?), (?, ?); |
added EXPERIMENTAL bulk_inse...
|
2822 | |
- id option work if id count...
|
2823 |
=item C<created_at> |
added EXPERIMENTAL insert cr...
|
2824 | |
cleanup
|
2825 |
created_at => 'created_datetime' |
added EXPERIMENTAL insert cr...
|
2826 | |
2827 |
Created timestamp column name. time when row is created is set to the column. |
|
2828 |
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by |
|
2829 |
C<now> attribute. |
|
2830 | ||
added EXPERIMENTAL execute()...
|
2831 |
=item C<id> |
2832 | ||
cleanup
|
2833 |
id => 4 |
2834 |
id => [4, 5] |
|
update pod
|
2835 | |
updated document
|
2836 |
ID corresponding to C<primary_key>. |
2837 |
You can insert a row by C<id> and C<primary_key>. |
|
added EXPERIMENTAL execute()...
|
2838 | |
cleanup
|
2839 |
$dbi->insert( |
2840 |
{title => 'Perl', author => 'Ken'} |
|
2841 |
primary_key => ['id1', 'id2'], |
|
2842 |
id => [4, 5], |
|
2843 |
table => 'book' |
|
2844 |
); |
|
added EXPERIMENTAL execute()...
|
2845 | |
updated document
|
2846 |
The above is same as the followin one. |
update pod
|
2847 | |
cleanup
|
2848 |
$dbi->insert( |
2849 |
{id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}, |
|
2850 |
table => 'book' |
|
2851 |
); |
|
update pod
|
2852 | |
- removed EXPERIMENTAL statu...
|
2853 |
=item C<prefix> |
added EXPERIMENTAL insert, u...
|
2854 | |
cleanup
|
2855 |
prefix => 'or replace' |
added EXPERIMENTAL insert, u...
|
2856 | |
2857 |
prefix before table name section |
|
2858 | ||
cleanup
|
2859 |
insert or replace into book |
added EXPERIMENTAL insert, u...
|
2860 | |
updated document
|
2861 |
=item C<table> |
2862 | ||
cleanup
|
2863 |
table => 'book' |
updated document
|
2864 | |
2865 |
Table name. |
|
2866 | ||
- id option work if id count...
|
2867 |
=item C<updated_at> |
added EXPERIMENTAL insert cr...
|
2868 | |
2869 |
This option is same as C<update> method C<updated_at> option. |
|
2870 | ||
- removed EXPERIMENTAL flag ...
|
2871 |
=item C<wrap> |
updated pod
|
2872 | |
cleanup
|
2873 |
wrap => {price => sub { "max($_[0])" }} |
updated pod
|
2874 | |
2875 |
placeholder wrapped string. |
|
2876 | ||
2877 |
If the following statement |
|
2878 | ||
cleanup
|
2879 |
$dbi->insert({price => 100}, table => 'book', |
2880 |
{price => sub { "$_[0] + 5" }}); |
|
updated pod
|
2881 | |
2882 |
is executed, the following SQL is executed. |
|
2883 | ||
cleanup
|
2884 |
insert into book price values ( ? + 5 ); |
updated pod
|
2885 | |
update pod
|
2886 |
=back |
2887 | ||
2888 |
=over 4 |
|
2889 | ||
- removed DEPRECATED DBIx::C...
|
2890 |
=head2 C<include_model> |
removed experimental base_ta...
|
2891 | |
cleanup
|
2892 |
$dbi->include_model('MyModel'); |
removed experimental base_ta...
|
2893 | |
update pod
|
2894 |
Include models from specified namespace, |
2895 |
the following layout is needed to include models. |
|
removed experimental base_ta...
|
2896 | |
cleanup
|
2897 |
lib / MyModel.pm |
2898 |
/ MyModel / book.pm |
|
2899 |
/ company.pm |
|
add feture. all model class ...
|
2900 | |
update pod
|
2901 |
Name space module, extending L<DBIx::Custom::Model>. |
add feture. all model class ...
|
2902 | |
update pod
|
2903 |
B<MyModel.pm> |
add feture. all model class ...
|
2904 | |
cleanup
|
2905 |
package MyModel; |
2906 |
use DBIx::Custom::Model -base; |
|
2907 |
|
|
2908 |
1; |
|
add feture. all model class ...
|
2909 | |
update pod
|
2910 |
Model modules, extending name space module. |
removed experimental base_ta...
|
2911 | |
update pod
|
2912 |
B<MyModel/book.pm> |
removed experimental base_ta...
|
2913 | |
cleanup
|
2914 |
package MyModel::book; |
2915 |
use MyModel -base; |
|
2916 |
|
|
2917 |
1; |
|
removed experimental base_ta...
|
2918 | |
update pod
|
2919 |
B<MyModel/company.pm> |
removed experimental base_ta...
|
2920 | |
cleanup
|
2921 |
package MyModel::company; |
2922 |
use MyModel -base; |
|
2923 |
|
|
2924 |
1; |
|
2925 |
|
|
updated pod
|
2926 |
MyModel::book and MyModel::company is included by C<include_model>. |
removed experimental base_ta...
|
2927 | |
updated pod
|
2928 |
You can get model object by C<model>. |
update pod
|
2929 | |
cleanup
|
2930 |
my $book_model = $dbi->model('book'); |
2931 |
my $company_model = $dbi->model('company'); |
|
removed experimental base_ta...
|
2932 | |
update pod
|
2933 |
See L<DBIx::Custom::Model> to know model features. |
2934 | ||
cleanup
|
2935 |
=head2 C<like_value> |
added EXPERIMENTAL like_valu...
|
2936 | |
cleanup
|
2937 |
my $like_value = $dbi->like_value |
added EXPERIMENTAL like_valu...
|
2938 | |
cleanup
|
2939 |
Code reference which return a value for the like value. |
added EXPERIMENTAL like_valu...
|
2940 | |
cleanup
|
2941 |
sub { "%$_[0]%" } |
added EXPERIMENTAL like_valu...
|
2942 | |
sqlfilter option is renamed ...
|
2943 |
=head2 C<mapper> |
- added EXPERIMENTAL pass at...
|
2944 | |
cleanup
|
2945 |
my $mapper = $dbi->mapper(param => $param); |
- added EXPERIMENTAL pass at...
|
2946 | |
2947 |
Create a new L<DBIx::Custom::Mapper> object. |
|
2948 | ||
- removed DEPRECATED DBIx::C...
|
2949 |
=head2 C<merge_param> |
added EXPERIMENTAL updat_par...
|
2950 | |
cleanup
|
2951 |
my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2}); |
added EXPERIMENTAL updat_par...
|
2952 | |
cleanup
|
2953 |
Merge parameters. The following new parameter is created. |
added EXPERIMENTAL updat_par...
|
2954 | |
cleanup
|
2955 |
{key1 => [1, 1], key2 => 2} |
added EXPERIMENTAL updat_par...
|
2956 | |
cleanup
|
2957 |
If same keys contains, the value is converted to array reference. |
2958 | ||
- removed DEPRECATED DBIx::C...
|
2959 |
=head2 C<model> |
update pod
|
2960 | |
cleanup
|
2961 |
my $model = $dbi->model('book'); |
update pod
|
2962 | |
cleanup
|
2963 |
Get a L<DBIx::Custom::Model> object |
2964 |
create by C<create_model> or C<include_model> |
|
update pod
|
2965 | |
- removed DEPRECATED DBIx::C...
|
2966 |
=head2 C<mycolumn> |
cleanup
|
2967 | |
cleanup
|
2968 |
my $column = $dbi->mycolumn(book => ['author', 'title']); |
cleanup
|
2969 | |
2970 |
Create column clause for myself. The follwoing column clause is created. |
|
2971 | ||
cleanup
|
2972 |
book.author as author, |
2973 |
book.title as title |
|
cleanup
|
2974 | |
added experimental not_exist...
|
2975 |
=head2 C<new> |
2976 | ||
cleanup
|
2977 |
my $dbi = DBIx::Custom->new( |
2978 |
dsn => "dbi:mysql:database=dbname", |
|
2979 |
user => 'ken', |
|
2980 |
password => '!LFKD%$&', |
|
2981 |
option => {mysql_enable_utf8 => 1} |
|
2982 |
); |
|
added experimental not_exist...
|
2983 | |
2984 |
Create a new L<DBIx::Custom> object. |
|
2985 | ||
removed EXPERIMETNAL flag fr...
|
2986 |
=head2 C<not_exists> |
added experimental not_exist...
|
2987 | |
cleanup
|
2988 |
my $not_exists = $dbi->not_exists; |
added experimental not_exist...
|
2989 | |
update pod
|
2990 |
DBIx::Custom::NotExists object, indicating the column is not exists. |
cleanup
|
2991 |
This is used in C<param> of L<DBIx::Custom::Where> . |
experimental extended select...
|
2992 | |
- removed EXPERIMENTAL flag ...
|
2993 |
=head2 C<order> |
- added EXPERIMENTAL order m...
|
2994 | |
cleanup
|
2995 |
my $order = $dbi->order; |
- added EXPERIMENTAL order m...
|
2996 | |
2997 |
Create a new L<DBIx::Custom::Order> object. |
|
2998 | ||
- id option work if id count...
|
2999 |
=head2 C<q> |
added EXPERIMENTAL q method
|
3000 | |
cleanup
|
3001 |
my $quooted = $dbi->q("title"); |
added EXPERIMENTAL q method
|
3002 | |
3003 |
Quote string by value of C<quote>. |
|
3004 | ||
cleanup
|
3005 |
=head2 C<register_filter> |
3006 | ||
cleanup
|
3007 |
$dbi->register_filter( |
3008 |
# Time::Piece object to database DATE format |
|
3009 |
tp_to_date => sub { |
|
3010 |
my $tp = shift; |
|
3011 |
return $tp->strftime('%Y-%m-%d'); |
|
3012 |
}, |
|
3013 |
# database DATE format to Time::Piece object |
|
3014 |
date_to_tp => sub { |
|
3015 |
my $date = shift; |
|
3016 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
3017 |
} |
|
3018 |
); |
|
3019 |
|
|
update pod
|
3020 |
Register filters, used by C<filter> option of many methods. |
cleanup
|
3021 | |
removed DBIx::Custom commit ...
|
3022 |
=head2 C<select> |
added select() all_column op...
|
3023 | |
cleanup
|
3024 |
my $result = $dbi->select( |
3025 |
column => ['author', 'title'], |
|
3026 |
table => 'book', |
|
3027 |
where => {author => 'Ken'}, |
|
3028 |
); |
|
3029 |
|
|
updated document
|
3030 |
Execute select statement. |
added select() all_column op...
|
3031 | |
- select method can receive ...
|
3032 |
You can pass odd number arguments. first argument is C<column>. |
3033 |
This is EXPERIMENTAL. |
|
3034 | ||
cleanup
|
3035 |
my $result = $dbi->select(['author', 'title'], table => 'book'); |
- select method can receive ...
|
3036 | |
cleanup
|
3037 |
B<OPTIONS> |
added select() all_column op...
|
3038 | |
cleanup
|
3039 |
C<select> method use all of C<execute> method's options, |
3040 |
and use the following new ones. |
|
added EXPERIMENTAL execute m...
|
3041 | |
cleanup
|
3042 |
=over 4 |
added EXPERIMENTAL execute m...
|
3043 | |
added select() all_column op...
|
3044 |
=item C<column> |
cleanup
|
3045 |
|
3046 |
column => 'author' |
|
3047 |
column => ['author', 'title'] |
|
updated document
|
3048 | |
3049 |
Column clause. |
|
cleanup
|
3050 |
|
updated document
|
3051 |
if C<column> is not specified, '*' is set. |
added select() all_column op...
|
3052 | |
cleanup
|
3053 |
column => '*' |
added select() all_column op...
|
3054 | |
- removed EXPERIMENTAL statu...
|
3055 |
You can specify hash of array reference. |
updated pod
|
3056 | |
cleanup
|
3057 |
column => [ |
3058 |
{book => [qw/author title/]}, |
|
3059 |
{person => [qw/name age/]} |
|
3060 |
] |
|
updated pod
|
3061 | |
updated pod
|
3062 |
This is expanded to the following one by using C<colomn> method. |
- select() column option can...
|
3063 | |
cleanup
|
3064 |
book.author as "book.author", |
3065 |
book.title as "book.title", |
|
3066 |
person.name as "person.name", |
|
3067 |
person.age as "person.age" |
|
- select() column option can...
|
3068 | |
- select method column optio...
|
3069 |
You can specify array of array reference, first argument is |
3070 |
column name, second argument is alias. |
|
- select() column option can...
|
3071 | |
cleanup
|
3072 |
column => [ |
3073 |
['date(book.register_datetime)' => 'book.register_date'] |
|
3074 |
]; |
|
- select() column option can...
|
3075 | |
- select method column optio...
|
3076 |
Alias is quoted properly and joined. |
- select() column option can...
|
3077 | |
cleanup
|
3078 |
date(book.register_datetime) as "book.register_date" |
updated pod
|
3079 | |
updated document
|
3080 |
=item C<id> |
3081 | ||
cleanup
|
3082 |
id => 4 |
3083 |
id => [4, 5] |
|
updated document
|
3084 | |
3085 |
ID corresponding to C<primary_key>. |
|
3086 |
You can select rows by C<id> and C<primary_key>. |
|
3087 | ||
cleanup
|
3088 |
$dbi->select( |
3089 |
primary_key => ['id1', 'id2'], |
|
3090 |
id => [4, 5], |
|
3091 |
table => 'book' |
|
3092 |
); |
|
added select() all_column op...
|
3093 | |
updated document
|
3094 |
The above is same as the followin one. |
3095 | ||
cleanup
|
3096 |
$dbi->select( |
3097 |
where => {id1 => 4, id2 => 5}, |
|
3098 |
table => 'book' |
|
3099 |
); |
|
3100 |
|
|
cleanup
|
3101 |
=item C<param> |
added select() all_column op...
|
3102 | |
cleanup
|
3103 |
param => {'table2.key3' => 5} |
update pod
|
3104 | |
updated document
|
3105 |
Parameter shown before where clause. |
cleanup
|
3106 |
|
updated document
|
3107 |
For example, if you want to contain tag in join clause, |
3108 |
you can pass parameter by C<param> option. |
|
update pod
|
3109 | |
cleanup
|
3110 |
join => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . |
3111 |
' as table2 on table1.key1 = table2.key1'] |
|
updated document
|
3112 | |
- removed EXPERIMENTAL statu...
|
3113 |
=itme C<prefix> |
added EXPERIMENTAL select pr...
|
3114 | |
cleanup
|
3115 |
prefix => 'SQL_CALC_FOUND_ROWS' |
added EXPERIMENTAL select pr...
|
3116 | |
3117 |
Prefix of column cluase |
|
3118 | ||
cleanup
|
3119 |
select SQL_CALC_FOUND_ROWS title, author from book; |
added EXPERIMENTAL select pr...
|
3120 | |
updated document
|
3121 |
=item C<join> |
3122 | ||
cleanup
|
3123 |
join => [ |
3124 |
'left outer join company on book.company_id = company_id', |
|
3125 |
'left outer join location on company.location_id = location.id' |
|
3126 |
] |
|
3127 |
|
|
updated document
|
3128 |
Join clause. If column cluase or where clause contain table name like "company.name", |
3129 |
join clausees needed when SQL is created is used automatically. |
|
update pod
|
3130 | |
cleanup
|
3131 |
$dbi->select( |
3132 |
table => 'book', |
|
3133 |
column => ['company.location_id as location_id'], |
|
3134 |
where => {'company.name' => 'Orange'}, |
|
3135 |
join => [ |
|
3136 |
'left outer join company on book.company_id = company.id', |
|
3137 |
'left outer join location on company.location_id = location.id' |
|
3138 |
] |
|
3139 |
); |
|
update pod
|
3140 | |
updated document
|
3141 |
In above select, column and where clause contain "company" table, |
3142 |
the following SQL is created |
|
update pod
|
3143 | |
cleanup
|
3144 |
select company.location_id as location_id |
3145 |
from book |
|
3146 |
left outer join company on book.company_id = company.id |
|
3147 |
where company.name = ?; |
|
update pod
|
3148 | |
added join new syntax
|
3149 |
You can specify two table by yourself. This is useful when join parser can't parse |
- removed EXPERIMENTAL flag ...
|
3150 |
the join clause correctly. |
added join new syntax
|
3151 | |
cleanup
|
3152 |
$dbi->select( |
3153 |
table => 'book', |
|
3154 |
column => ['company.location_id as location_id'], |
|
3155 |
where => {'company.name' => 'Orange'}, |
|
3156 |
join => [ |
|
3157 |
{ |
|
3158 |
clause => 'left outer join location on company.location_id = location.id', |
|
3159 |
table => ['company', 'location'] |
|
3160 |
} |
|
3161 |
] |
|
3162 |
); |
|
added join new syntax
|
3163 | |
updated document
|
3164 |
=item C<table> |
updated pod
|
3165 | |
cleanup
|
3166 |
table => 'book' |
updated pod
|
3167 | |
updated document
|
3168 |
Table name. |
updated pod
|
3169 | |
updated document
|
3170 |
=item C<where> |
cleanup
|
3171 |
|
3172 |
# Hash refrence |
|
3173 |
where => {author => 'Ken', 'title' => 'Perl'} |
|
3174 |
|
|
3175 |
# DBIx::Custom::Where object |
|
3176 |
where => $dbi->where( |
|
3177 |
clause => ['and', ':author{=}', ':title{like}'], |
|
3178 |
param => {author => 'Ken', title => '%Perl%'} |
|
3179 |
); |
|
3180 |
|
|
3181 |
# Array reference, this is same as above |
|
3182 |
where => [ |
|
3183 |
['and', ':author{=}', ':title{like}'], |
|
3184 |
{author => 'Ken', title => '%Perl%'} |
|
3185 |
]; |
|
3186 |
|
|
3187 |
# String |
|
3188 |
where => 'title is null' |
|
update pod
|
3189 | |
cleanup
|
3190 |
Where clause. See L<DBIx::Custom::Where>. |
cleanup
|
3191 |
|
update pod
|
3192 |
=back |
cleanup
|
3193 | |
removed EXPERIMETNAL flag fr...
|
3194 |
=head2 C<setup_model> |
3195 | ||
cleanup
|
3196 |
$dbi->setup_model; |
removed EXPERIMETNAL flag fr...
|
3197 | |
3198 |
Setup all model objects. |
|
3199 |
C<columns> of model object is automatically set, parsing database information. |
|
3200 | ||
3201 |
=head2 C<type_rule> |
|
3202 | ||
cleanup
|
3203 |
$dbi->type_rule( |
3204 |
into1 => { |
|
3205 |
date => sub { ... }, |
|
3206 |
datetime => sub { ... } |
|
3207 |
}, |
|
3208 |
into2 => { |
|
3209 |
date => sub { ... }, |
|
3210 |
datetime => sub { ... } |
|
3211 |
}, |
|
3212 |
from1 => { |
|
3213 |
# DATE |
|
3214 |
9 => sub { ... }, |
|
3215 |
# DATETIME or TIMESTAMP |
|
3216 |
11 => sub { ... }, |
|
3217 |
} |
|
3218 |
from2 => { |
|
3219 |
# DATE |
|
3220 |
9 => sub { ... }, |
|
3221 |
# DATETIME or TIMESTAMP |
|
3222 |
11 => sub { ... }, |
|
3223 |
} |
|
3224 |
); |
|
removed EXPERIMETNAL flag fr...
|
3225 | |
3226 |
Filtering rule when data is send into and get from database. |
|
3227 |
This has a little complex problem. |
|
3228 | ||
3229 |
In C<into1> and C<into2> you can specify |
|
3230 |
type name as same as type name defined |
|
3231 |
by create table, such as C<DATETIME> or C<DATE>. |
|
3232 | ||
3233 |
Note that type name and data type don't contain upper case. |
|
3234 |
If these contain upper case charactor, you convert it to lower case. |
|
3235 | ||
3236 |
C<into2> is executed after C<into1>. |
|
3237 | ||
3238 |
Type rule of C<into1> and C<into2> is enabled on the following |
|
3239 |
column name. |
|
3240 | ||
3241 |
=over 4 |
|
3242 | ||
3243 |
=item 1. column name |
|
3244 | ||
cleanup
|
3245 |
issue_date |
3246 |
issue_datetime |
|
removed EXPERIMETNAL flag fr...
|
3247 | |
3248 |
This need C<table> option in each method. |
|
3249 | ||
3250 |
=item 2. table name and column name, separator is dot |
|
3251 | ||
cleanup
|
3252 |
book.issue_date |
3253 |
book.issue_datetime |
|
removed EXPERIMETNAL flag fr...
|
3254 | |
3255 |
=back |
|
3256 | ||
3257 |
You get all type name used in database by C<available_typename>. |
|
3258 | ||
cleanup
|
3259 |
print $dbi->available_typename; |
removed EXPERIMETNAL flag fr...
|
3260 | |
3261 |
In C<from1> and C<from2> you specify data type, not type name. |
|
3262 |
C<from2> is executed after C<from1>. |
|
3263 |
You get all data type by C<available_datatype>. |
|
3264 | ||
cleanup
|
3265 |
print $dbi->available_datatype; |
removed EXPERIMETNAL flag fr...
|
3266 | |
3267 |
You can also specify multiple types at once. |
|
3268 | ||
cleanup
|
3269 |
$dbi->type_rule( |
3270 |
into1 => [ |
|
3271 |
[qw/DATE DATETIME/] => sub { ... }, |
|
3272 |
], |
|
3273 |
); |
|
removed EXPERIMETNAL flag fr...
|
3274 | |
cleanup
|
3275 |
=head2 C<update> |
removed reconnect method
|
3276 | |
cleanup
|
3277 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 4}); |
removed reconnect method
|
3278 | |
insert and update method's p...
|
3279 |
Execute update statement. First argument is update row data. |
3280 | ||
3281 |
If you want to set constant value to row data, use scalar reference |
|
3282 |
as parameter value. |
|
3283 | ||
cleanup
|
3284 |
{date => \"NOW()"} |
added experimental update_pa...
|
3285 | |
cleanup
|
3286 |
B<OPTIONS> |
- insert, insert_at, update,...
|
3287 | |
cleanup
|
3288 |
C<update> method use all of C<execute> method's options, |
3289 |
and use the following new ones. |
|
- insert, insert_at, update,...
|
3290 | |
cleanup
|
3291 |
=over 4 |
- insert, insert_at, update,...
|
3292 | |
updated document
|
3293 |
=item C<id> |
- insert, insert_at, update,...
|
3294 | |
cleanup
|
3295 |
id => 4 |
3296 |
id => [4, 5] |
|
- insert, insert_at, update,...
|
3297 | |
updated document
|
3298 |
ID corresponding to C<primary_key>. |
3299 |
You can update rows by C<id> and C<primary_key>. |
|
update pod
|
3300 | |
cleanup
|
3301 |
$dbi->update( |
3302 |
{title => 'Perl', author => 'Ken'} |
|
3303 |
primary_key => ['id1', 'id2'], |
|
3304 |
id => [4, 5], |
|
3305 |
table => 'book' |
|
3306 |
); |
|
update pod
|
3307 | |
updated document
|
3308 |
The above is same as the followin one. |
update pod
|
3309 | |
cleanup
|
3310 |
$dbi->update( |
3311 |
{title => 'Perl', author => 'Ken'} |
|
3312 |
where => {id1 => 4, id2 => 5}, |
|
3313 |
table => 'book' |
|
3314 |
); |
|
update pod
|
3315 | |
- removed EXPERIMENTAL statu...
|
3316 |
=item C<prefix> |
added EXPERIMENTAL insert, u...
|
3317 | |
cleanup
|
3318 |
prefix => 'or replace' |
added EXPERIMENTAL insert, u...
|
3319 | |
3320 |
prefix before table name section |
|
3321 | ||
cleanup
|
3322 |
update or replace book |
added EXPERIMENTAL insert, u...
|
3323 | |
updated document
|
3324 |
=item C<table> |
update pod
|
3325 | |
cleanup
|
3326 |
table => 'book' |
update pod
|
3327 | |
updated document
|
3328 |
Table name. |
update pod
|
3329 | |
added EXPERIMENTAL execute m...
|
3330 |
=item C<where> |
3331 | ||
3332 |
Same as C<select> method's C<where> option. |
|
3333 | ||
- removed EXPERIMENTAL flag ...
|
3334 |
=item C<wrap> |
updated pod
|
3335 | |
cleanup
|
3336 |
wrap => {price => sub { "max($_[0])" }} |
updated pod
|
3337 | |
3338 |
placeholder wrapped string. |
|
3339 | ||
3340 |
If the following statement |
|
3341 | ||
cleanup
|
3342 |
$dbi->update({price => 100}, table => 'book', |
3343 |
{price => sub { "$_[0] + 5" }}); |
|
updated pod
|
3344 | |
3345 |
is executed, the following SQL is executed. |
|
3346 | ||
cleanup
|
3347 |
update book set price = ? + 5; |
updated pod
|
3348 | |
- id option work if id count...
|
3349 |
=item C<updated_at> |
added EXPERIMENTAL insert cr...
|
3350 | |
cleanup
|
3351 |
updated_at => 'updated_datetime' |
added EXPERIMENTAL insert cr...
|
3352 | |
3353 |
Updated timestamp column name. time when row is updated is set to the column. |
|
3354 |
default time format is C<YYYY-mm-dd HH:MM:SS>, which can be changed by |
|
3355 |
C<now> attribute. |
|
3356 | ||
updated pod
|
3357 |
=back |
update pod
|
3358 | |
updated pod
|
3359 |
=head2 C<update_all> |
update pod
|
3360 | |
cleanup
|
3361 |
$dbi->update_all({title => 'Perl'}, table => 'book', ); |
update pod
|
3362 | |
updated document
|
3363 |
Execute update statement for all rows. |
updated pod
|
3364 |
Options is same as C<update> method. |
update pod
|
3365 | |
- id option work if id count...
|
3366 |
=head2 C<update_or_insert> |
cleanup
|
3367 |
|
3368 |
# ID |
|
3369 |
$dbi->update_or_insert( |
|
3370 |
{title => 'Perl'}, |
|
3371 |
table => 'book', |
|
3372 |
id => 1, |
|
3373 |
primary_key => 'id', |
|
3374 |
option => { |
|
3375 |
select => { |
|
3376 |
append => 'for update' |
|
3377 |
} |
|
3378 |
} |
|
3379 |
); |
|
- EXPERIMENTAL update_or_ins...
|
3380 | |
- removed DEPRECATED status ...
|
3381 |
Update or insert. |
3382 | ||
- EXPERIMENTAL update_or_ins...
|
3383 |
C<update_or_insert> method execute C<select> method first to find row. |
3384 |
If the row is exists, C<update> is executed. |
|
3385 |
If not, C<insert> is executed. |
|
- removed DEPRECATED status ...
|
3386 | |
- EXPERIMENTAL update_or_ins...
|
3387 |
C<OPTIONS> |
3388 | ||
3389 |
C<update_or_insert> method use all common option |
|
3390 |
in C<select>, C<update>, C<delete>, and has the following new ones. |
|
3391 | ||
3392 |
=over 4 |
|
3393 | ||
3394 |
=item C<option> |
|
3395 | ||
cleanup
|
3396 |
option => { |
3397 |
select => { |
|
3398 |
append => '...' |
|
3399 |
}, |
|
3400 |
insert => { |
|
3401 |
prefix => '...' |
|
3402 |
}, |
|
3403 |
update => { |
|
3404 |
filter => {} |
|
- EXPERIMENTAL update_or_ins...
|
3405 |
} |
cleanup
|
3406 |
} |
- removed DEPRECATED status ...
|
3407 | |
- EXPERIMENTAL update_or_ins...
|
3408 |
If you want to pass option to each method, |
3409 |
you can use C<option> option. |
|
- removed DEPRECATED status ...
|
3410 | |
3411 |
=over 4 |
|
3412 | ||
3413 |
=item C<select_option> |
|
3414 | ||
cleanup
|
3415 |
select_option => {append => 'for update'} |
- removed DEPRECATED status ...
|
3416 | |
3417 |
select method option, |
|
3418 |
select method is used to check the row is already exists. |
|
3419 | ||
- removed EXPERIMENTAL flag ...
|
3420 |
=head2 C<show_datatype> |
update pod
|
3421 | |
cleanup
|
3422 |
$dbi->show_datatype($table); |
update pod
|
3423 | |
3424 |
Show data type of the columns of specified table. |
|
3425 | ||
cleanup
|
3426 |
book |
3427 |
title: 5 |
|
3428 |
issue_date: 91 |
|
update pod
|
3429 | |
3430 |
This data type is used in C<type_rule>'s C<from1> and C<from2>. |
|
3431 | ||
- removed EXPERIMENTAL the f...
|
3432 |
=head2 C<show_tables> |
test cleanup
|
3433 | |
cleanup
|
3434 |
$dbi->show_tables; |
test cleanup
|
3435 | |
3436 |
Show tables. |
|
3437 | ||
- removed EXPERIMENTAL flag ...
|
3438 |
=head2 C<show_typename> |
update pod
|
3439 | |
cleanup
|
3440 |
$dbi->show_typename($table); |
update pod
|
3441 | |
3442 |
Show type name of the columns of specified table. |
|
3443 | ||
cleanup
|
3444 |
book |
3445 |
title: varchar |
|
3446 |
issue_date: date |
|
update pod
|
3447 | |
3448 |
This type name is used in C<type_rule>'s C<into1> and C<into2>. |
|
3449 | ||
removed EXPERIMETNAL flag fr...
|
3450 |
=head2 C<values_clause> |
3451 | ||
cleanup
|
3452 |
my $values_clause = $dbi->values_clause({title => 'a', age => 2}); |
removed EXPERIMETNAL flag fr...
|
3453 | |
3454 |
Create values clause. |
|
3455 | ||
cleanup
|
3456 |
(title, author) values (title = :title, age = :age); |
removed EXPERIMETNAL flag fr...
|
3457 | |
3458 |
You can use this in insert statement. |
|
3459 | ||
cleanup
|
3460 |
my $insert_sql = "insert into book $values_clause"; |
removed EXPERIMETNAL flag fr...
|
3461 | |
3462 |
=head2 C<where> |
|
3463 | ||
cleanup
|
3464 |
my $where = $dbi->where( |
3465 |
clause => ['and', 'title = :title', 'author = :author'], |
|
3466 |
param => {title => 'Perl', author => 'Ken'} |
|
3467 |
); |
|
removed EXPERIMETNAL flag fr...
|
3468 | |
3469 |
Create a new L<DBIx::Custom::Where> object. |
|
3470 | ||
- added EXPERIMENTAL update_...
|
3471 |
=head1 ENVIRONMENTAL VARIABLES |
3472 | ||
3473 |
=head2 C<DBIX_CUSTOM_DEBUG> |
|
3474 | ||
3475 |
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true, |
|
3476 |
executed SQL and bind values are printed to STDERR. |
|
3477 | ||
improved debug message
|
3478 |
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING> |
3479 | ||
3480 |
DEBUG output encoding. Default to UTF-8. |
|
added environment variable D...
|
3481 | |
- fixed bug DBIx::Custom::Re...
|
3482 |
=head2 C<DBIX_CUSTOM_TAG_PARSE> |
3483 | ||
3484 |
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off. |
|
3485 | ||
3486 |
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE> |
|
3487 | ||
3488 |
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1, |
|
3489 |
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute. |
|
3490 | ||
fix heading typos
|
3491 |
=head1 DEPRECATED FUNCTIONALITY |
- added EXPERIMENTAL order m...
|
3492 | |
3493 |
L<DBIx::Custom> |
|
3494 | ||
cleanup
|
3495 |
# Attribute methods |
3496 |
tag_parse # will be removed 2017/1/1 |
|
3497 |
default_dbi_option # will be removed 2017/1/1 |
|
3498 |
dbi_option # will be removed 2017/1/1 |
|
3499 |
data_source # will be removed at 2017/1/1 |
|
3500 |
dbi_options # will be removed at 2017/1/1 |
|
3501 |
filter_check # will be removed at 2017/1/1 |
|
3502 |
reserved_word_quote # will be removed at 2017/1/1 |
|
3503 |
cache_method # will be removed at 2017/1/1 |
|
3504 |
|
|
3505 |
# Methods |
|
3506 |
update_timestamp # will be removed at 2017/1/1 |
|
3507 |
insert_timestamp # will be removed at 2017/1/1 |
|
3508 |
method # will be removed at 2017/1/1 |
|
3509 |
assign_param # will be removed at 2017/1/1 |
|
3510 |
update_param # will be removed at 2017/1/1 |
|
3511 |
insert_param # will be removed at 2017/1/1 |
|
3512 |
create_query # will be removed at 2017/1/1 |
|
3513 |
apply_filter # will be removed at 2017/1/1 |
|
3514 |
select_at # will be removed at 2017/1/1 |
|
3515 |
delete_at # will be removed at 2017/1/1 |
|
3516 |
update_at # will be removed at 2017/1/1 |
|
3517 |
insert_at # will be removed at 2017/1/1 |
|
3518 |
register_tag # will be removed at 2017/1/1 |
|
3519 |
default_bind_filter # will be removed at 2017/1/1 |
|
3520 |
default_fetch_filter # will be removed at 2017/1/1 |
|
3521 |
insert_param_tag # will be removed at 2017/1/1 |
|
3522 |
register_tag # will be removed at 2017/1/1 |
|
3523 |
register_tag_processor # will be removed at 2017/1/1 |
|
3524 |
update_param_tag # will be removed at 2017/1/1 |
|
3525 |
|
|
3526 |
# Options |
|
3527 |
select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1 |
|
3528 |
execute method id option # will be removed 2017/1/1 |
|
3529 |
update timestamp option # will be removed 2017/1/1 |
|
3530 |
insert timestamp option # will be removed 2017/1/1 |
|
3531 |
select method where_param option # will be removed 2017/1/1 |
|
3532 |
delete method where_param option # will be removed 2017/1/1 |
|
3533 |
update method where_param option # will be removed 2017/1/1 |
|
3534 |
insert method param option # will be removed at 2017/1/1 |
|
3535 |
insert method id option # will be removed at 2017/1/1 |
|
3536 |
select method relation option # will be removed at 2017/1/1 |
|
3537 |
select method column option [COLUMN, as => ALIAS] format |
|
3538 |
# will be removed at 2017/1/1 |
|
3539 |
execute method's sqlfilter option # will be removed at 2017/1/1 |
|
3540 |
|
|
3541 |
# Others |
|
3542 |
execute($query, ...) # execute method receiving query object. |
|
3543 |
# this is removed at 2017/1/1 |
|
3544 |
execute("select * from {= title}"); # execute method's |
|
3545 |
# tag parsing functionality |
|
3546 |
# will be removed at 2017/1/1 |
|
3547 |
Query caching # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3548 | |
3549 |
L<DBIx::Custom::Model> |
|
3550 | ||
cleanup
|
3551 |
# Attribute methods |
3552 |
execute # will be removed at 2017/1/1 |
|
3553 |
method # will be removed at 2017/1/1 |
|
3554 |
filter # will be removed at 2017/1/1 |
|
3555 |
name # will be removed at 2017/1/1 |
|
3556 |
type # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3557 | |
3558 |
L<DBIx::Custom::Query> |
|
DBIx::Custom::Query is DEPRE...
|
3559 | |
3560 |
This module is DEPRECATED! # will be removed at 2017/1/1 |
|
cleanup
|
3561 |
|
3562 |
# Attribute methods |
|
3563 |
default_filter # will be removed at 2017/1/1 |
|
3564 |
table # will be removed at 2017/1/1 |
|
3565 |
filters # will be removed at 2017/1/1 |
|
3566 |
|
|
3567 |
# Methods |
|
3568 |
filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3569 | |
3570 |
L<DBIx::Custom::QueryBuilder> |
|
- DBIx::Custom::QueryBuilder...
|
3571 | |
3572 |
This module is DEPRECATED! # will be removed at 2017/1/1 |
|
cleanup
|
3573 |
|
3574 |
# Attribute methods |
|
3575 |
tags # will be removed at 2017/1/1 |
|
3576 |
tag_processors # will be removed at 2017/1/1 |
|
3577 |
|
|
3578 |
# Methods |
|
3579 |
register_tag # will be removed at 2017/1/1 |
|
3580 |
register_tag_processor # will be removed at 2017/1/1 |
|
3581 |
|
|
3582 |
# Others |
|
3583 |
build_query("select * from {= title}"); # tag parsing functionality |
|
3584 |
# will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3585 | |
3586 |
L<DBIx::Custom::Result> |
|
cleanup
|
3587 |
|
3588 |
# Attribute methods |
|
3589 |
filter_check # will be removed at 2017/1/1 |
|
3590 |
|
|
3591 |
# Methods |
|
3592 |
fetch_first # will be removed at 2017/2/1 |
|
3593 |
fetch_hash_first # will be removed 2017/2/1 |
|
3594 |
filter_on # will be removed at 2017/1/1 |
|
3595 |
filter_off # will be removed at 2017/1/1 |
|
3596 |
end_filter # will be removed at 2017/1/1 |
|
3597 |
remove_end_filter # will be removed at 2017/1/1 |
|
3598 |
remove_filter # will be removed at 2017/1/1 |
|
3599 |
default_filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3600 | |
3601 |
L<DBIx::Custom::Tag> |
|
3602 | ||
cleanup
|
3603 |
This module is DEPRECATED! # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3604 | |
micro optimization
|
3605 |
L<DBIx::Custom::Order> |
3606 | ||
cleanup
|
3607 |
# Other |
3608 |
prepend method array reference receiving |
|
3609 |
$order->prepend(['book', 'desc']); # will be removed 2017/1/1 |
|
micro optimization
|
3610 | |
fix heading typos
|
3611 |
=head1 BACKWARDS COMPATIBILITY POLICY |
- added EXPERIMENTAL order m...
|
3612 | |
3613 |
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings |
|
3614 |
except for attribute method. |
|
3615 |
You can check all DEPRECATED functionalities by document. |
|
3616 |
DEPRECATED functionality is removed after five years, |
|
3617 |
but if at least one person use the functionality and tell me that thing |
|
added EXPERIMENTAL each_tabl...
|
3618 |
I extend one year each time he tell me it. |
- added EXPERIMENTAL order m...
|
3619 | |
3620 |
EXPERIMENTAL functionality will be changed without warnings. |
|
DBIx::Custom is now stable
|
3621 | |
removed DESTROY method(not b...
|
3622 |
=head1 BUGS |
3623 | ||
renamed build_query to creat...
|
3624 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
3625 | |
3626 |
C<< <kimoto.yuki at gmail.com> >> |
|
3627 | ||
3628 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
3629 | ||
removed reconnect method
|
3630 |
=head1 AUTHOR |
3631 | ||
3632 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
3633 | |
packaging one directory
|
3634 |
=head1 COPYRIGHT & LICENSE |
3635 | ||
cleanup
|
3636 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
3637 | |
3638 |
This program is free software; you can redistribute it and/or modify it |
|
3639 |
under the same terms as Perl itself. |
|
3640 | ||
3641 |
=cut |