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