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