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