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