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