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