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