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