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