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