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