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