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