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