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