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