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