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