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