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