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