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