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