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