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