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