cleanup
|
1 |
package DBIx::Custom; |
added EXPERIMENTAL insert, u...
|
2 |
use Object::Simple -base; |
cleanup
|
3 | |
- added EXPERIMENTAL pass at...
|
4 |
our $VERSION = '0.1722'; |
fixed DBIx::Custom::QueryBui...
|
5 |
use 5.008001; |
cleanup
|
6 | |
packaging one directory
|
7 |
use Carp 'croak'; |
8 |
use DBI; |
|
9 |
use DBIx::Custom::Result; |
|
cleanup
|
10 |
use DBIx::Custom::Query; |
cleanup
|
11 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
12 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
13 |
use DBIx::Custom::Model; |
cleanup
|
14 |
use DBIx::Custom::Tag; |
- added EXPERIMENTAL order m...
|
15 |
use DBIx::Custom::Order; |
cleanup
|
16 |
use DBIx::Custom::Util qw/_array_to_hash _subname/; |
added tests
|
17 |
use DBIx::Custom::Mapper; |
- added EXPERIMENTAL pass at...
|
18 |
use DBIx::Custom::NotExists; |
improved debug message
|
19 |
use Encode qw/encode encode_utf8 decode_utf8/; |
cleanup
|
20 |
use Scalar::Util qw/weaken/; |
packaging one directory
|
21 | |
added environment variable D...
|
22 |
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0; |
improved debug message
|
23 |
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8'; |
added environment variable D...
|
24 | |
- added EXPERIMENTAL get_col...
|
25 |
has [qw/connector dsn password quote user exclude_table user_table_info |
26 |
user_column_info/], |
|
removed from cache() and cac...
|
27 |
cache => 0, |
many changed
|
28 |
cache_method => sub { |
29 |
sub { |
|
30 |
my $self = shift; |
|
31 |
|
|
32 |
$self->{_cached} ||= {}; |
|
33 |
|
|
34 |
if (@_ > 1) { |
|
update pod
|
35 |
$self->{_cached}{$_[0]} = $_[1]; |
many changed
|
36 |
} |
37 |
else { |
|
update pod
|
38 |
return $self->{_cached}{$_[0]}; |
many changed
|
39 |
} |
40 |
} |
|
update pod
|
41 |
}, |
42 |
dbi_option => sub { {} }, |
|
43 |
default_dbi_option => sub { |
|
44 |
{ |
|
45 |
RaiseError => 1, |
|
46 |
PrintError => 0, |
|
47 |
AutoCommit => 1 |
|
48 |
} |
|
49 |
}, |
|
fix tests
|
50 |
filters => sub { |
51 |
{ |
|
52 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
53 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
54 |
} |
|
update pod
|
55 |
}, |
added EXPERIMENTAL last_sql ...
|
56 |
last_sql => '', |
update pod
|
57 |
models => sub { {} }, |
cleanup
|
58 |
query_builder => sub { |
59 |
my $self = shift; |
|
60 |
my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self); |
|
61 |
weaken $builder->{dbi}; |
|
62 |
return $builder; |
|
63 |
}, |
|
update pod
|
64 |
result_class => 'DBIx::Custom::Result', |
65 |
safety_character => '\w', |
|
cleanup test
|
66 |
separator => '.', |
added tag_parse attribute
|
67 |
stash => sub { {} }, |
68 |
tag_parse => 1; |
|
cleanup
|
69 | |
added EXPERIMENTAL system_ta...
|
70 |
sub available_datatype { |
test cleanup
|
71 |
my $self = shift; |
72 |
|
|
added EXPERIMENTAL system_ta...
|
73 |
my $data_types = ''; |
74 |
foreach my $i (-1000 .. 1000) { |
|
75 |
my $type_info = $self->dbh->type_info($i); |
|
76 |
my $data_type = $type_info->{DATA_TYPE}; |
|
77 |
my $type_name = $type_info->{TYPE_NAME}; |
|
78 |
$data_types .= "$data_type ($type_name)\n" |
|
79 |
if defined $data_type; |
|
80 |
} |
|
81 |
return "Data Type maybe equal to Type Name" unless $data_types; |
|
82 |
$data_types = "Data Type (Type name)\n" . $data_types; |
|
83 |
return $data_types; |
|
84 |
} |
|
85 | ||
86 |
sub available_typename { |
|
87 |
my $self = shift; |
|
88 |
|
|
89 |
# Type Names |
|
90 |
my $type_names = {}; |
|
91 |
$self->each_column(sub { |
|
92 |
my ($self, $table, $column, $column_info) = @_; |
|
93 |
$type_names->{$column_info->{TYPE_NAME}} = 1 |
|
94 |
if $column_info->{TYPE_NAME}; |
|
95 |
}); |
|
96 |
my @output = sort keys %$type_names; |
|
97 |
unshift @output, "Type Name"; |
|
98 |
return join "\n", @output; |
|
test cleanup
|
99 |
} |
100 | ||
added helper method
|
101 |
our $AUTOLOAD; |
102 |
sub AUTOLOAD { |
|
103 |
my $self = shift; |
|
104 | ||
renamed helper to method.
|
105 |
# Method name |
106 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
107 | |
cleanup
|
108 |
# Call method |
renamed helper to method.
|
109 |
$self->{_methods} ||= {}; |
add feture. all model class ...
|
110 |
if (my $method = $self->{_methods}->{$mname}) { |
111 |
return $self->$method(@_) |
|
112 |
} |
|
- removed EXPERIMENTAL Prefo...
|
113 |
elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) { |
- added EXPERIMENTAL DBIx::C...
|
114 |
$self->dbh->$dbh_method(@_); |
add feture. all model class ...
|
115 |
} |
116 |
else { |
|
cleanup
|
117 |
croak qq{Can't locate object method "$mname" via "$package" } |
118 |
. _subname; |
|
add feture. all model class ...
|
119 |
} |
added helper method
|
120 |
} |
121 | ||
- update_param_tag is DEPREC...
|
122 |
sub assign_param { |
added EXPERIMENTAL assign_ta...
|
123 |
my ($self, $param) = @_; |
124 |
|
|
125 |
# Create set tag |
|
126 |
my @params; |
|
127 |
my $safety = $self->safety_character; |
|
insert and update method's p...
|
128 |
foreach my $column (sort keys %$param) { |
added EXPERIMENTAL assign_ta...
|
129 |
croak qq{"$column" is not safety column name } . _subname |
130 |
unless $column =~ /^[$safety\.]+$/; |
|
added quote method's two cha...
|
131 |
my $column_quote = $self->_q($column); |
132 |
$column_quote =~ s/\./$self->_q(".")/e; |
|
insert and update method's p...
|
133 |
push @params, ref $param->{$column} eq 'SCALAR' |
134 |
? "$column_quote = " . ${$param->{$column}} |
|
135 |
: "$column_quote = :$column"; |
|
136 | ||
added EXPERIMENTAL assign_ta...
|
137 |
} |
138 |
my $tag = join(', ', @params); |
|
139 |
|
|
140 |
return $tag; |
|
141 |
} |
|
142 | ||
cleanup
|
143 |
sub column { |
- DBIx::Custom Model filter ...
|
144 |
my $self = shift; |
145 |
my $option = pop if ref $_[-1] eq 'HASH'; |
|
146 |
my $real_table = shift; |
|
147 |
my $columns = shift; |
|
148 |
my $table = $option->{alias} || $real_table; |
|
149 |
|
|
150 |
# Columns |
|
151 |
unless ($columns) { |
|
152 |
$columns ||= $self->model($real_table)->columns; |
|
153 |
} |
|
added helper method
|
154 |
|
EXPERIMTANL column method th...
|
155 |
# Separator |
156 |
my $separator = $self->separator; |
|
157 |
|
|
cleanup
|
158 |
# Column clause |
cleanup
|
159 |
my @column; |
cleanup
|
160 |
$columns ||= []; |
added quote method's two cha...
|
161 |
push @column, $self->_q($table) . "." . $self->_q($_) . |
162 |
" as " . $self->_q("${table}${separator}$_") |
|
EXPERIMTANL column method th...
|
163 |
for @$columns; |
cleanup
|
164 |
|
165 |
return join (', ', @column); |
|
added helper method
|
166 |
} |
167 | ||
packaging one directory
|
168 |
sub connect { |
cleanup
|
169 |
my $self = ref $_[0] ? shift : shift->new(@_); |
170 |
|
|
171 |
my $connector = $self->connector; |
|
172 |
|
|
173 |
if (!ref $connector && $connector) { |
|
174 |
require DBIx::Connector; |
|
175 |
|
|
176 |
my $dsn = $self->dsn; |
|
177 |
my $user = $self->user; |
|
178 |
my $password = $self->password; |
|
179 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
|
180 |
my $connector = DBIx::Connector->new($dsn, $user, $password, |
|
181 |
{%{$self->default_dbi_option} , %$dbi_option}); |
|
182 |
$self->connector($connector); |
|
183 |
} |
|
removed register_format()
|
184 |
|
- removed EXPERIMENTAL Prefo...
|
185 |
# Connect |
186 |
$self->dbh; |
|
update document
|
187 |
|
packaging one directory
|
188 |
return $self; |
189 |
} |
|
190 | ||
- added EXPERIMENTAL DBIx::C...
|
191 |
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] } |
192 | ||
update pod
|
193 |
sub dbh { |
194 |
my $self = shift; |
|
cleanup
|
195 |
|
fixed dbh() method bug:wq
|
196 |
# Set |
197 |
if (@_) { |
|
198 |
$self->{dbh} = $_[0]; |
|
199 |
|
|
200 |
return $self; |
|
201 |
} |
|
202 |
|
|
203 |
# Get |
|
204 |
else { |
|
205 |
# From Connction manager |
|
206 |
if (my $connector = $self->connector) { |
|
cleanup
|
207 |
croak "connector must have dbh() method " . _subname |
fixed dbh() method bug:wq
|
208 |
unless ref $connector && $connector->can('dbh'); |
209 |
|
|
set reserved_word_quote auto...
|
210 |
$self->{dbh} = $connector->dbh; |
fixed dbh() method bug:wq
|
211 |
} |
212 |
|
|
set reserved_word_quote auto...
|
213 |
# Connect |
214 |
$self->{dbh} ||= $self->_connect; |
|
215 |
|
|
216 |
# Quote |
|
reserved_word_quote is DEPRE...
|
217 |
if (!defined $self->reserved_word_quote && !defined $self->quote) { |
prepare oracle test
|
218 |
my $driver = $self->_driver; |
added EXPERIMENTAL find_tabl...
|
219 |
my $quote = $driver eq 'odbc' ? '[]' |
220 |
: $driver eq 'ado' ? '[]' |
|
221 |
: $driver eq 'mysql' ? '`' |
|
fixex [] reserved_word_quote...
|
222 |
: '"'; |
reserved_word_quote is DEPRE...
|
223 |
$self->quote($quote); |
set reserved_word_quote auto...
|
224 |
} |
reserved_word_quote is DEPRE...
|
225 |
|
set reserved_word_quote auto...
|
226 |
return $self->{dbh}; |
update pod
|
227 |
} |
228 |
} |
|
229 | ||
cleanup
|
230 |
sub delete { |
select, insert, update, upda...
|
231 |
my ($self, %args) = @_; |
added EXPERIMENTAL reserved_...
|
232 | |
cleanup update and update_al...
|
233 |
# Arguments |
cleanup
|
234 |
my $table = $args{table} || ''; |
cleanup
|
235 |
croak qq{"table" option must be specified. } . _subname |
improved error messages
|
236 |
unless $table; |
cleanup
|
237 |
my $where = delete $args{where} || {}; |
238 |
my $append = delete $args{append}; |
|
239 |
my $allow_delete_all = delete $args{allow_delete_all}; |
|
DEPRECATED select() param op...
|
240 |
my $where_param = delete $args{where_param} || {}; |
delete_at is DEPRECATED! use...
|
241 |
my $id = delete $args{id}; |
242 |
my $primary_key = delete $args{primary_key}; |
|
243 |
croak "update method primary_key option " . |
|
244 |
"must be specified when id is specified " . _subname |
|
245 |
if defined $id && !defined $primary_key; |
|
246 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
added EXPERIMENTAL insert, u...
|
247 |
my $prefix = delete $args{prefix}; |
delete_at is DEPRECATED! use...
|
248 |
|
make delete() using where ob...
|
249 |
# Where |
fixed small insert, update, ...
|
250 |
$where = $self->_create_param_from_id($id, $primary_key) if defined $id; |
select, update, and delete w...
|
251 |
my $where_clause = ''; |
updated pod
|
252 |
if (ref $where eq 'ARRAY' && !ref $where->[0]) { |
253 |
$where_clause = "where " . $where->[0]; |
|
254 |
$where_param = $where->[1]; |
|
255 |
} |
|
256 |
elsif (ref $where) { |
|
select, update, and delete w...
|
257 |
$where = $self->_where_to_obj($where); |
DEPRECATED select() param op...
|
258 |
$where_param = keys %$where_param |
259 |
? $self->merge_param($where_param, $where->param) |
|
260 |
: $where->param; |
|
select, update, and delete w...
|
261 |
|
262 |
# String where |
|
263 |
$where_clause = $where->to_string; |
|
264 |
} |
|
265 |
elsif ($where) { $where_clause = "where $where" } |
|
cleanup
|
266 |
croak qq{"where" must be specified } . _subname |
cleanup
|
267 |
if $where_clause eq '' && !$allow_delete_all; |
make delete() using where ob...
|
268 | |
cleanup
|
269 |
# Delete statement |
cleanup
|
270 |
my @sql; |
added EXPERIMENTAL insert, u...
|
271 |
push @sql, "delete"; |
272 |
push @sql, $prefix if defined $prefix; |
|
added quote method's two cha...
|
273 |
push @sql, "from " . $self->_q($table) . " $where_clause"; |
added EXPERIMENTAL insert, u...
|
274 |
push @sql, $append if defined $append; |
cleanup
|
275 |
my $sql = join(' ', @sql); |
packaging one directory
|
276 |
|
277 |
# Execute query |
|
updated pod
|
278 |
return $self->execute($sql, $where_param, table => $table, %args); |
packaging one directory
|
279 |
} |
280 | ||
cleanup
|
281 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
282 | |
added memory leak check test
|
283 |
sub DESTROY {} |
added helper method
|
284 | |
removed EXPERIMETNAL flag fr...
|
285 |
sub create_model { |
286 |
my $self = shift; |
|
287 |
|
|
cleanup
|
288 |
# Arguments |
removed EXPERIMETNAL flag fr...
|
289 |
my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
290 |
$args->{dbi} = $self; |
|
291 |
my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model'; |
|
292 |
my $model_name = delete $args->{name}; |
|
293 |
my $model_table = delete $args->{table}; |
|
294 |
$model_name ||= $model_table; |
|
295 |
|
|
cleanup
|
296 |
# Create model |
removed EXPERIMETNAL flag fr...
|
297 |
my $model = $model_class->new($args); |
cleanup
|
298 |
weaken $model->{dbi}; |
removed EXPERIMETNAL flag fr...
|
299 |
$model->name($model_name) unless $model->name; |
300 |
$model->table($model_table) unless $model->table; |
|
301 |
|
|
micro optimization
|
302 |
# Apply filter(DEPRECATED logic) |
303 |
if ($model->{filter}) { |
|
304 |
my $filter = ref $model->filter eq 'HASH' |
|
305 |
? [%{$model->filter}] |
|
306 |
: $model->filter; |
|
307 |
$filter ||= []; |
|
308 |
warn "DBIx::Custom::Model filter method is DEPRECATED!" |
|
309 |
if @$filter; |
|
310 |
$self->_apply_filter($model->table, @$filter); |
|
311 |
} |
|
312 |
|
|
removed EXPERIMETNAL flag fr...
|
313 |
# Set model |
314 |
$self->model($model->name, $model); |
|
315 |
|
|
create_model() return model
|
316 |
return $self->model($model->name); |
removed EXPERIMETNAL flag fr...
|
317 |
} |
318 | ||
319 |
sub each_column { |
|
- added EXPERIMENTAL get_col...
|
320 |
my ($self, $cb, %options) = @_; |
added EXPERIMENTAL system_ta...
|
321 | |
- added EXPERIMENTAL get_col...
|
322 |
my $user_column_info = $self->user_column_info; |
removed EXPERIMETNAL flag fr...
|
323 |
|
- added EXPERIMENTAL get_col...
|
324 |
if ($user_column_info) { |
325 |
$self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info; |
|
326 |
} |
|
327 |
else { |
|
328 |
|
|
329 |
my $re = $self->exclude_table || $options{exclude_table}; |
|
330 |
# Tables |
|
331 |
my %tables; |
|
332 |
$self->each_table(sub { $tables{$_[1]}++ }); |
|
added SQL Server test
|
333 | |
- added EXPERIMENTAL get_col...
|
334 |
# Iterate all tables |
335 |
my @tables = sort keys %tables; |
|
336 |
for (my $i = 0; $i < @tables; $i++) { |
|
337 |
my $table = $tables[$i]; |
|
338 |
|
|
339 |
# Iterate all columns |
|
340 |
my $sth_columns; |
|
341 |
eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')}; |
|
342 |
next if $@; |
|
343 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
344 |
my $column = $column_info->{COLUMN_NAME}; |
|
345 |
$self->$cb($table, $column, $column_info); |
|
346 |
} |
|
removed EXPERIMETNAL flag fr...
|
347 |
} |
348 |
} |
|
349 |
} |
|
350 | ||
added EXPERIMENTAL each_tabl...
|
351 |
sub each_table { |
added EXPERIMENTAL find_tabl...
|
352 |
my ($self, $cb, %option) = @_; |
added EXPERIMENTAL each_tabl...
|
353 |
|
cleanup test
|
354 |
my $user_table_infos = $self->user_table_info; |
added EXPERIMENTAL system_ta...
|
355 |
|
added test
|
356 |
# Iterate tables |
357 |
if ($user_table_infos) { |
|
358 |
$self->$cb($_->{table}, $_->{info}) for @$user_table_infos; |
|
359 |
} |
|
360 |
else { |
|
361 |
my $re = $self->exclude_table || $option{exclude}; |
|
362 |
my $sth_tables = $self->dbh->table_info; |
|
363 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
364 |
|
|
365 |
# Table |
|
366 |
my $table = $table_info->{TABLE_NAME}; |
|
367 |
next if defined $re && $table =~ /$re/; |
|
368 |
$self->$cb($table, $table_info); |
|
369 |
} |
|
added EXPERIMENTAL each_tabl...
|
370 |
} |
371 |
} |
|
372 | ||
simplified arguments check
|
373 |
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all |
374 |
allow_update_all bind_type column filter id join param prefix primary_key |
|
added EXPERIMENTAL execute m...
|
375 |
query relation sqlfilter table table_alias type type_rule_off type_rule1_off |
simplified arguments check
|
376 |
type_rule2_off wrap/; |
cleanup
|
377 | |
378 |
sub execute { |
|
execute method can second ar...
|
379 |
my $self = shift; |
380 |
my $query = shift; |
|
381 |
my $param; |
|
382 |
$param = shift if @_ % 2; |
|
383 |
my %args = @_; |
|
refactoring delete and delet...
|
384 |
|
cleanup
|
385 |
# Arguments |
execute method can second ar...
|
386 |
my $p = delete $args{param} || {}; |
387 |
$param ||= $p; |
|
cleanup
|
388 |
my $tables = delete $args{table} || []; |
389 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
|
cleanup
|
390 |
my $filter = delete $args{filter}; |
cleanup
|
391 |
$filter = _array_to_hash($filter); |
DBIx::Custom::Model type att...
|
392 |
my $bind_type = delete $args{bind_type} || delete $args{type}; |
393 |
$bind_type = _array_to_hash($bind_type); |
|
added EXPERIMENTAL execute()...
|
394 |
my $type_rule_off = delete $args{type_rule_off}; |
EXPERIMENTAL type_rule argum...
|
395 |
my $type_rule_off_parts = { |
396 |
1 => delete $args{type_rule1_off}, |
|
397 |
2 => delete $args{type_rule2_off} |
|
398 |
}; |
|
cleanup
|
399 |
my $query_return = delete $args{query}; |
added EXPERIMENTAL execute m...
|
400 |
my $table_alias = delete $args{table_alias} || {}; |
added EXPERIMENTAL execute m...
|
401 |
my $sqlfilter = $args{sqlfilter}; |
- removed placeholder count ...
|
402 |
my $id = delete $args{id}; |
403 |
my $primary_key = delete $args{primary_key}; |
|
404 |
croak "insert method primary_key option " . |
|
405 |
"must be specified when id is specified " . _subname |
|
406 |
if defined $id && !defined $primary_key; |
|
407 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
408 | ||
409 |
if (defined $id) { |
|
410 |
my $id_param = $self->_create_param_from_id($id, $primary_key); |
|
411 |
$param = $self->merge_param($id_param, $param); |
|
412 |
} |
|
added EXPERIMENTAL reserved_...
|
413 |
|
cleanup
|
414 |
# Check argument names |
select, insert, update, upda...
|
415 |
foreach my $name (keys %args) { |
cleanup
|
416 |
croak qq{"$name" is wrong option } . _subname |
simplified arguments check
|
417 |
unless $VALID_ARGS{$name}; |
refactoring delete and delet...
|
418 |
} |
419 |
|
|
added EXPERIMENTAL execute m...
|
420 |
$query = $self->_create_query($query, $sqlfilter) unless ref $query; |
added EXPERIMENTAL last_sql ...
|
421 |
|
422 |
# Save query |
|
423 |
$self->last_sql($query->sql); |
|
424 | ||
cleanup
|
425 |
return $query if $query_return; |
micro optimization
|
426 |
|
427 |
# DEPRECATED! Merge query filter |
|
DBIx::Custom::Query filter m...
|
428 |
$filter ||= $query->{filter} || {}; |
all filter can receive array...
|
429 |
|
cleanup
|
430 |
# Tables |
DBIx::Custom::Query tables a...
|
431 |
unshift @$tables, @{$query->{tables} || []}; |
micro optimization
|
432 |
my $main_table = @{$tables}[-1]; |
micro optimization
|
433 |
|
micro optimization
|
434 |
# DEPRECATED! Cleanup tables |
micro optimization
|
435 |
$tables = $self->_remove_duplicate_table($tables, $main_table) |
436 |
if @$tables > 1; |
|
cleanup
|
437 |
|
added type_rule into logic
|
438 |
# Type rule |
EXPERIMENTAL type_rule argum...
|
439 |
my $type_filters = {}; |
added EXPERIMENTAL execute()...
|
440 |
unless ($type_rule_off) { |
micro optimization
|
441 |
foreach my $i (1, 2) { |
442 |
unless ($type_rule_off_parts->{$i}) { |
|
443 |
$type_filters->{$i} = {}; |
|
444 |
foreach my $alias (keys %$table_alias) { |
|
445 |
my $table = $table_alias->{$alias}; |
|
added EXPERIMENTAL execute m...
|
446 |
|
micro optimization
|
447 |
foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) { |
448 |
$type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column}; |
|
EXPERIMENTAL type_rule argum...
|
449 |
} |
450 |
} |
|
micro optimization
|
451 |
$type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}} |
452 |
if $main_table; |
|
added EXPERIMENTAL execute()...
|
453 |
} |
added type_rule into logic
|
454 |
} |
455 |
} |
|
cleanup
|
456 |
|
micro optimization
|
457 |
# DEPRECATED! Applied filter |
micro optimization
|
458 |
if ($self->{filter}{on}) { |
459 |
my $applied_filter = {}; |
|
460 |
foreach my $table (@$tables) { |
|
461 |
$applied_filter = { |
|
462 |
%$applied_filter, |
|
463 |
%{$self->{filter}{out}->{$table} || {}} |
|
464 |
} |
|
added auto_filter method
|
465 |
} |
micro optimization
|
466 |
$filter = {%$applied_filter, %$filter}; |
added auto_filter method
|
467 |
} |
468 |
|
|
cleanup
|
469 |
# Replace filter name to code |
470 |
foreach my $column (keys %$filter) { |
|
471 |
my $name = $filter->{$column}; |
|
472 |
if (!defined $name) { |
|
473 |
$filter->{$column} = undef; |
|
renamed auto_filter to apply...
|
474 |
} |
cleanup
|
475 |
elsif (ref $name ne 'CODE') { |
cleanup
|
476 |
croak qq{Filter "$name" is not registered" } . _subname |
cleanup
|
477 |
unless exists $self->filters->{$name}; |
478 |
$filter->{$column} = $self->filters->{$name}; |
|
cleanup
|
479 |
} |
480 |
} |
|
packaging one directory
|
481 |
|
cleanup
|
482 |
# Create bind values |
483 |
my $bind = $self->_create_bind_values( |
|
484 |
$param, |
|
485 |
$query->columns, |
|
486 |
$filter, |
|
EXPERIMENTAL type_rule argum...
|
487 |
$type_filters, |
DBIx::Custom::Model type att...
|
488 |
$bind_type |
cleanup
|
489 |
); |
added EXPERIMENTAL execute m...
|
490 | |
cleanup
|
491 |
# Execute |
added experimental not_exist...
|
492 |
my $sth = $query->sth; |
cleanup
|
493 |
my $affected; |
cleanup
|
494 |
eval { |
495 |
for (my $i = 0; $i < @$bind; $i++) { |
|
DBIx::Custom::Model type att...
|
496 |
my $bind_type = $bind->[$i]->{bind_type}; |
497 |
$sth->bind_param( |
|
498 |
$i + 1, |
|
499 |
$bind->[$i]->{value}, |
|
500 |
$bind_type ? $bind_type : () |
|
501 |
); |
|
cleanup
|
502 |
} |
503 |
$affected = $sth->execute; |
|
504 |
}; |
|
improved error messages
|
505 |
|
micro optimization
|
506 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
507 |
. qq{$query->{sql}\n} . _subname) if $@; |
|
cleanup
|
508 |
|
improved debug message
|
509 |
# DEBUG message |
510 |
if (DEBUG) { |
|
511 |
print STDERR "SQL:\n" . $query->sql . "\n"; |
|
512 |
my @output; |
|
513 |
foreach my $b (@$bind) { |
|
514 |
my $value = $b->{value}; |
|
515 |
$value = 'undef' unless defined $value; |
|
516 |
$value = encode(DEBUG_ENCODING(), $value) |
|
517 |
if utf8::is_utf8($value); |
|
518 |
push @output, $value; |
|
519 |
} |
|
520 |
print STDERR "Bind values: " . join(', ', @output) . "\n\n"; |
|
521 |
} |
|
added environment variable D...
|
522 |
|
cleanup
|
523 |
# Select statement |
cleanup
|
524 |
if ($sth->{NUM_OF_FIELDS}) { |
525 |
|
|
micro optimization
|
526 |
# DEPRECATED! Filter |
cleanup
|
527 |
my $filter = {}; |
micro optimization
|
528 |
if ($self->{filter}{on}) { |
529 |
$filter->{in} = {}; |
|
530 |
$filter->{end} = {}; |
|
531 |
push @$tables, $main_table if $main_table; |
|
532 |
foreach my $table (@$tables) { |
|
533 |
foreach my $way (qw/in end/) { |
|
534 |
$filter->{$way} = { |
|
535 |
%{$filter->{$way}}, |
|
536 |
%{$self->{filter}{$way}{$table} || {}} |
|
537 |
}; |
|
538 |
} |
|
cleanup
|
539 |
} |
cleanup
|
540 |
} |
541 |
|
|
542 |
# Result |
|
543 |
my $result = $self->result_class->new( |
|
added type_rule method and f...
|
544 |
sth => $sth, |
sub module use DBIx::Custom ...
|
545 |
dbi => $self, |
cleanup
|
546 |
default_filter => $self->{default_in_filter}, |
added type_rule method and f...
|
547 |
filter => $filter->{in} || {}, |
548 |
end_filter => $filter->{end} || {}, |
|
EXPERIMENTAL type_rule argum...
|
549 |
type_rule => { |
550 |
from1 => $self->type_rule->{from1}, |
|
551 |
from2 => $self->type_rule->{from2} |
|
552 |
}, |
|
cleanup
|
553 |
); |
554 | ||
555 |
return $result; |
|
556 |
} |
|
cleanup
|
557 |
|
558 |
# Not select statement |
|
559 |
else { return $affected } |
|
cleanup
|
560 |
} |
561 | ||
added test
|
562 |
sub get_table_info { |
added EXPERIMENTAL find_tabl...
|
563 |
my ($self, %args) = @_; |
564 |
|
|
565 |
my $exclude = delete $args{exclude}; |
|
566 |
croak qq/"$_" is wrong option/ for keys %args; |
|
567 |
|
|
added test
|
568 |
my $table_info = []; |
569 |
$self->each_table( |
|
570 |
sub { push @$table_info, {table => $_[1], info => $_[2] } }, |
|
571 |
exclude => $exclude |
|
572 |
); |
|
added EXPERIMENTAL find_tabl...
|
573 |
|
cleanup test
|
574 |
return [sort {$a->{table} cmp $b->{table} } @$table_info]; |
added EXPERIMENTAL find_tabl...
|
575 |
} |
576 | ||
- added EXPERIMENTAL get_col...
|
577 |
sub get_column_info { |
578 |
my ($self, %args) = @_; |
|
579 |
|
|
580 |
my $exclude_table = delete $args{exclude_table}; |
|
581 |
croak qq/"$_" is wrong option/ for keys %args; |
|
582 |
|
|
583 |
my $column_info = []; |
|
584 |
$self->each_column( |
|
585 |
sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } }, |
|
586 |
exclude_table => $exclude_table |
|
587 |
); |
|
588 |
|
|
589 |
return [ |
|
590 |
sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} } |
|
cleanup
|
591 |
@$column_info]; |
- added EXPERIMENTAL get_col...
|
592 |
} |
593 | ||
cleanup
|
594 |
sub insert { |
- insert, insert_at, update,...
|
595 |
my $self = shift; |
added EXPERIMENTAL reserved_...
|
596 |
|
cleanup
|
597 |
# Arguments |
- insert, insert_at, update,...
|
598 |
my $param; |
599 |
$param = shift if @_ % 2; |
|
600 |
my %args = @_; |
|
cleanup
|
601 |
my $table = delete $args{table}; |
cleanup
|
602 |
croak qq{"table" option must be specified } . _subname |
simplified arguments check
|
603 |
unless defined $table; |
- insert, insert_at, update,...
|
604 |
my $p = delete $args{param} || {}; |
605 |
$param ||= $p; |
|
cleanup
|
606 |
my $append = delete $args{append} || ''; |
insert_at is DEPRECATED! add...
|
607 |
my $id = delete $args{id}; |
608 |
my $primary_key = delete $args{primary_key}; |
|
cleanup
|
609 |
croak "insert method primary_key option " . |
added tests
|
610 |
"must be specified when id is specified " . _subname |
611 |
if defined $id && !defined $primary_key; |
|
insert_at is DEPRECATED! add...
|
612 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
added EXPERIMENTAL insert, u...
|
613 |
my $prefix = delete $args{prefix}; |
cleanup
|
614 | |
insert_at is DEPRECATED! add...
|
615 |
# Merge parameter |
fixed small insert, update, ...
|
616 |
if (defined $id) { |
cleanup
|
617 |
my $id_param = $self->_create_param_from_id($id, $primary_key); |
insert_at is DEPRECATED! add...
|
618 |
$param = $self->merge_param($id_param, $param); |
619 |
} |
|
620 | ||
cleanup
|
621 |
# Insert statement |
cleanup
|
622 |
my @sql; |
added EXPERIMENTAL insert, u...
|
623 |
push @sql, "insert"; |
624 |
push @sql, $prefix if defined $prefix; |
|
added quote method's two cha...
|
625 |
push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param); |
added EXPERIMENTAL insert, u...
|
626 |
push @sql, $append if defined $append; |
cleanup
|
627 |
my $sql = join (' ', @sql); |
packaging one directory
|
628 |
|
629 |
# Execute query |
|
updated pod
|
630 |
return $self->execute($sql, $param, table => $table, %args); |
packaging one directory
|
631 |
} |
632 | ||
- update_param_tag is DEPREC...
|
633 |
sub insert_param { |
remove experimental DBIx::Cu...
|
634 |
my ($self, $param) = @_; |
635 |
|
|
cleanup
|
636 |
# Create insert parameter tag |
- remaned experimental safty...
|
637 |
my $safety = $self->safety_character; |
cleanup
|
638 |
my @columns; |
639 |
my @placeholders; |
|
insert and update method's p...
|
640 |
foreach my $column (sort keys %$param) { |
cleanup
|
641 |
croak qq{"$column" is not safety column name } . _subname |
- remaned experimental safty...
|
642 |
unless $column =~ /^[$safety\.]+$/; |
added quote method's two cha...
|
643 |
my $column_quote = $self->_q($column); |
644 |
$column_quote =~ s/\./$self->_q(".")/e; |
|
- update_param_tag is DEPREC...
|
645 |
push @columns, $column_quote; |
insert and update method's p...
|
646 |
push @placeholders, ref $param->{$column} eq 'SCALAR' |
647 |
? ${$param->{$column}} : ":$column"; |
|
remove experimental DBIx::Cu...
|
648 |
} |
649 |
|
|
cleanup
|
650 |
return '(' . join(', ', @columns) . ') ' . 'values ' . |
651 |
'(' . join(', ', @placeholders) . ')' |
|
remove experimental DBIx::Cu...
|
652 |
} |
653 | ||
- added EXPERIMENTAL DBIx::C...
|
654 |
sub include_model { |
655 |
my ($self, $name_space, $model_infos) = @_; |
|
656 |
|
|
cleanup
|
657 |
# Name space |
- added EXPERIMENTAL DBIx::C...
|
658 |
$name_space ||= ''; |
cleanup
|
659 |
|
660 |
# Get Model infomations |
|
- added EXPERIMENTAL DBIx::C...
|
661 |
unless ($model_infos) { |
cleanup
|
662 | |
- added EXPERIMENTAL DBIx::C...
|
663 |
# Load name space module |
cleanup
|
664 |
croak qq{"$name_space" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
665 |
if $name_space =~ /[^\w:]/; |
666 |
eval "use $name_space"; |
|
cleanup
|
667 |
croak qq{Name space module "$name_space.pm" is needed. $@ } |
668 |
. _subname |
|
improved error messages
|
669 |
if $@; |
- added EXPERIMENTAL DBIx::C...
|
670 |
|
671 |
# Search model modules |
|
672 |
my $path = $INC{"$name_space.pm"}; |
|
673 |
$path =~ s/\.pm$//; |
|
674 |
opendir my $dh, $path |
|
cleanup
|
675 |
or croak qq{Can't open directory "$path": $! } . _subname |
- added EXPERIMENTAL DBIx::C...
|
676 |
$model_infos = []; |
677 |
while (my $module = readdir $dh) { |
|
678 |
push @$model_infos, $module |
|
679 |
if $module =~ s/\.pm$//; |
|
680 |
} |
|
681 |
close $dh; |
|
682 |
} |
|
683 |
|
|
cleanup
|
684 |
# Include models |
- added EXPERIMENTAL DBIx::C...
|
685 |
foreach my $model_info (@$model_infos) { |
686 |
|
|
cleanup
|
687 |
# Load model |
- added EXPERIMENTAL DBIx::C...
|
688 |
my $model_class; |
689 |
my $model_name; |
|
690 |
my $model_table; |
|
691 |
if (ref $model_info eq 'HASH') { |
|
692 |
$model_class = $model_info->{class}; |
|
693 |
$model_name = $model_info->{name}; |
|
694 |
$model_table = $model_info->{table}; |
|
695 |
|
|
696 |
$model_name ||= $model_class; |
|
697 |
$model_table ||= $model_name; |
|
698 |
} |
|
removed EXPERIMETNAL flag fr...
|
699 |
else { $model_class = $model_name = $model_table = $model_info } |
- added EXPERIMENTAL DBIx::C...
|
700 |
my $mclass = "${name_space}::$model_class"; |
cleanup
|
701 |
croak qq{"$mclass" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
702 |
if $mclass =~ /[^\w:]/; |
703 |
unless ($mclass->can('isa')) { |
|
704 |
eval "use $mclass"; |
|
cleanup
|
705 |
croak "$@ " . _subname if $@; |
- added EXPERIMENTAL DBIx::C...
|
706 |
} |
707 |
|
|
cleanup
|
708 |
# Create model |
removed EXPERIMETNAL flag fr...
|
709 |
my $args = {}; |
710 |
$args->{model_class} = $mclass if $mclass; |
|
711 |
$args->{name} = $model_name if $model_name; |
|
712 |
$args->{table} = $model_table if $model_table; |
|
713 |
$self->create_model($args); |
|
- added EXPERIMENTAL DBIx::C...
|
714 |
} |
715 |
|
|
716 |
return $self; |
|
717 |
} |
|
718 | ||
added DBIx::Custom::Mapper
|
719 |
sub mapper { |
720 |
my $self = shift; |
|
721 |
return DBIx::Custom::Mapper->new(@_); |
|
722 |
} |
|
723 | ||
added EXPERIMENTAL map_param...
|
724 |
sub map_param { |
725 |
my $self = shift; |
|
726 |
my $param = shift; |
|
727 |
my %map = @_; |
|
728 |
|
|
729 |
# Mapping |
|
730 |
my $map_param = {}; |
|
731 |
foreach my $key (keys %map) { |
|
732 |
my $value_cb; |
|
733 |
my $condition; |
|
734 |
my $map_key; |
|
735 |
|
|
736 |
# Get mapping information |
|
737 |
if (ref $map{$key} eq 'ARRAY') { |
|
738 |
foreach my $some (@{$map{$key}}) { |
|
739 |
$map_key = $some unless ref $some; |
|
740 |
$condition = $some->{if} if ref $some eq 'HASH'; |
|
741 |
$value_cb = $some if ref $some eq 'CODE'; |
|
742 |
} |
|
743 |
} |
|
744 |
else { |
|
745 |
$map_key = $map{$key}; |
|
746 |
} |
|
747 |
$value_cb ||= sub { $_[0] }; |
|
748 |
$condition ||= sub { defined $_[0] && length $_[0] }; |
|
749 | ||
750 |
# Map parameter |
|
751 |
my $value; |
|
752 |
if (ref $condition eq 'CODE') { |
|
753 |
$map_param->{$map_key} = $value_cb->($param->{$key}) |
|
754 |
if $condition->($param->{$key}); |
|
755 |
} |
|
756 |
elsif ($condition eq 'exists') { |
|
757 |
$map_param->{$map_key} = $value_cb->($param->{$key}) |
|
758 |
if exists $param->{$key}; |
|
759 |
} |
|
760 |
else { croak qq/Condition must be code reference or "exists" / . _subname } |
|
761 |
} |
|
762 |
|
|
763 |
return $map_param; |
|
764 |
} |
|
765 | ||
added EXPERIMENTAL updat_par...
|
766 |
sub merge_param { |
767 |
my ($self, @params) = @_; |
|
768 |
|
|
cleanup
|
769 |
# Merge parameters |
fixed merge_param bug
|
770 |
my $merge = {}; |
771 |
foreach my $param (@params) { |
|
772 |
foreach my $column (keys %$param) { |
|
773 |
my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0; |
|
774 |
|
|
775 |
if (exists $merge->{$column}) { |
|
776 |
$merge->{$column} = [$merge->{$column}] |
|
777 |
unless ref $merge->{$column} eq 'ARRAY'; |
|
778 |
push @{$merge->{$column}}, |
|
779 |
ref $param->{$column} ? @{$param->{$column}} : $param->{$column}; |
|
added EXPERIMENTAL updat_par...
|
780 |
} |
781 |
else { |
|
fixed merge_param bug
|
782 |
$merge->{$column} = $param->{$column}; |
added EXPERIMENTAL updat_par...
|
783 |
} |
784 |
} |
|
785 |
} |
|
786 |
|
|
fixed merge_param bug
|
787 |
return $merge; |
added EXPERIMENTAL updat_par...
|
788 |
} |
789 | ||
cleanup
|
790 |
sub method { |
791 |
my $self = shift; |
|
792 |
|
|
cleanup
|
793 |
# Register method |
cleanup
|
794 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
795 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
796 |
|
|
797 |
return $self; |
|
798 |
} |
|
799 | ||
- added EXPERIMENTAL DBIx::C...
|
800 |
sub model { |
801 |
my ($self, $name, $model) = @_; |
|
802 |
|
|
cleanup
|
803 |
# Set model |
- added EXPERIMENTAL DBIx::C...
|
804 |
if ($model) { |
805 |
$self->models->{$name} = $model; |
|
806 |
return $self; |
|
807 |
} |
|
808 |
|
|
809 |
# Check model existance |
|
cleanup
|
810 |
croak qq{Model "$name" is not included } . _subname |
- added EXPERIMENTAL DBIx::C...
|
811 |
unless $self->models->{$name}; |
812 |
|
|
cleanup
|
813 |
# Get model |
- added EXPERIMENTAL DBIx::C...
|
814 |
return $self->models->{$name}; |
815 |
} |
|
816 | ||
cleanup
|
817 |
sub mycolumn { |
818 |
my ($self, $table, $columns) = @_; |
|
819 |
|
|
cleanup
|
820 |
# Create column clause |
821 |
my @column; |
|
cleanup
|
822 |
$columns ||= []; |
added quote method's two cha...
|
823 |
push @column, $self->_q($table) . "." . $self->_q($_) . |
824 |
" as " . $self->_q($_) |
|
825 |
for @$columns; |
|
cleanup
|
826 |
|
827 |
return join (', ', @column); |
|
828 |
} |
|
829 | ||
added dbi_options attribute
|
830 |
sub new { |
831 |
my $self = shift->SUPER::new(@_); |
|
832 |
|
|
cleanup
|
833 |
# Check attributes |
added dbi_options attribute
|
834 |
my @attrs = keys %$self; |
835 |
foreach my $attr (@attrs) { |
|
- added EXPERIMENTAL DBIx::C...
|
836 |
croak qq{Invalid attribute: "$attr" } . _subname |
added dbi_options attribute
|
837 |
unless $self->can($attr); |
838 |
} |
|
- added EXPERIMENTAL order m...
|
839 | |
added EXPERIMENTAL system_ta...
|
840 |
# DEPRECATED |
cleanup
|
841 |
$self->{_tags} = { |
added EXPERIMENTAL system_ta...
|
842 |
'?' => \&DBIx::Custom::Tag::placeholder, |
843 |
'=' => \&DBIx::Custom::Tag::equal, |
|
844 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
845 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
846 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
847 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
848 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
849 |
'like' => \&DBIx::Custom::Tag::like, |
|
850 |
'in' => \&DBIx::Custom::Tag::in, |
|
851 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
852 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
cleanup
|
853 |
}; |
854 |
|
|
855 |
return $self; |
|
856 |
} |
|
857 | ||
- added EXPERIMENTAL pass at...
|
858 |
sub not_exists { DBIx::Custom::NotExists->singleton } |
cleanup
|
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 pass at...
|
2847 |
=head2 C<mapper EXPERIMETNAL> |
2848 | ||
2849 |
my $mapper = $dbi->mapper(param => $param); |
|
2850 | ||
2851 |
Create a new L<DBIx::Custom::Mapper> object. |
|
2852 | ||
added EXPERIMENTAL map_param...
|
2853 |
=head2 C<map_param> EXPERIMENTAL |
2854 | ||
2855 |
my $map_param = $dbi->map_param( |
|
2856 |
{id => 1, authro => 'Ken', price => 1900}, |
|
2857 |
'id' => 'book.id', |
|
2858 |
'author' => ['book.author' => sub { '%' . $_[0] . '%' }], |
|
2859 |
'price' => [ |
|
2860 |
'book.price', {if => sub { length $_[0] }} |
|
2861 |
] |
|
2862 |
); |
|
2863 | ||
2864 |
Map paramters to other key and value. First argument is original |
|
2865 |
parameter. this is hash reference. Rest argument is mapping. |
|
2866 |
By default, Mapping is done if the value length is not zero. |
|
2867 | ||
2868 |
=over 4 |
|
2869 | ||
2870 |
=item Key mapping |
|
2871 | ||
2872 |
'id' => 'book.id' |
|
2873 | ||
2874 |
This is only key mapping. Value is same as original one. |
|
2875 | ||
2876 |
(id => 1) is mapped to ('book.id' => 1) if value length is not zero. |
|
2877 | ||
2878 |
=item Key and value mapping |
|
2879 | ||
2880 |
'author' => ['book.author' => sub { '%' . $_[0] . '%' }] |
|
2881 | ||
2882 |
This is key and value mapping. Frist element of array reference |
|
2883 |
is mapped key name, second element is code reference to map the value. |
|
2884 | ||
2885 |
(author => 'Ken') is mapped to ('book.author' => '%Ken%') |
|
2886 |
if value length is not zero. |
|
2887 | ||
2888 |
=item Condition |
|
2889 | ||
2890 |
'price' => ['book.price', {if => 'exists'}] |
|
2891 |
'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}] |
|
2892 |
'price' => ['book.price', {if => sub { defined shift }}] |
|
2893 | ||
2894 |
If you need condition, you can sepecify it. this is code reference |
|
2895 |
or 'exists'. By default, condition is the following one. |
|
2896 | ||
2897 |
sub { defined $_[0] && length $_[0] } |
|
2898 | ||
2899 |
=back |
|
2900 | ||
- removed DEPRECATED DBIx::C...
|
2901 |
=head2 C<merge_param> |
added EXPERIMENTAL updat_par...
|
2902 | |
2903 |
my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2}); |
|
2904 | ||
DBIx::Custom::Model type att...
|
2905 |
Merge parameters. |
added EXPERIMENTAL updat_par...
|
2906 | |
2907 |
{key1 => [1, 1], key2 => 2} |
|
2908 | ||
- removed DEPRECATED DBIx::C...
|
2909 |
=head2 C<method> |
added experimental not_exist...
|
2910 | |
2911 |
$dbi->method( |
|
2912 |
update_or_insert => sub { |
|
2913 |
my $self = shift; |
|
update pod
|
2914 |
|
2915 |
# Process |
|
added experimental not_exist...
|
2916 |
}, |
2917 |
find_or_create => sub { |
|
2918 |
my $self = shift; |
|
update pod
|
2919 |
|
2920 |
# Process |
|
added experimental not_exist...
|
2921 |
} |
2922 |
); |
|
2923 | ||
update pod
|
2924 |
Register method. These method is called directly from L<DBIx::Custom> object. |
added experimental not_exist...
|
2925 | |
2926 |
$dbi->update_or_insert; |
|
2927 |
$dbi->find_or_create; |
|
2928 | ||
- removed DEPRECATED DBIx::C...
|
2929 |
=head2 C<model> |
update pod
|
2930 | |
2931 |
my $model = $dbi->model('book'); |
|
2932 | ||
updated pod
|
2933 |
Get a L<DBIx::Custom::Model> object, |
update pod
|
2934 | |
- removed DEPRECATED DBIx::C...
|
2935 |
=head2 C<mycolumn> |
cleanup
|
2936 | |
2937 |
my $column = $self->mycolumn(book => ['author', 'title']); |
|
2938 | ||
2939 |
Create column clause for myself. The follwoing column clause is created. |
|
2940 | ||
2941 |
book.author as author, |
|
2942 |
book.title as title |
|
2943 | ||
added experimental not_exist...
|
2944 |
=head2 C<new> |
2945 | ||
update pod
|
2946 |
my $dbi = DBIx::Custom->new( |
data_source is DEPRECATED! I...
|
2947 |
dsn => "dbi:mysql:database=dbname", |
update pod
|
2948 |
user => 'ken', |
2949 |
password => '!LFKD%$&', |
|
2950 |
dbi_option => {mysql_enable_utf8 => 1} |
|
2951 |
); |
|
added experimental not_exist...
|
2952 | |
2953 |
Create a new L<DBIx::Custom> object. |
|
2954 | ||
removed EXPERIMETNAL flag fr...
|
2955 |
=head2 C<not_exists> |
added experimental not_exist...
|
2956 | |
2957 |
my $not_exists = $dbi->not_exists; |
|
2958 | ||
update pod
|
2959 |
DBIx::Custom::NotExists object, indicating the column is not exists. |
2960 |
This is used by C<clause> of L<DBIx::Custom::Where> . |
|
experimental extended select...
|
2961 | |
- added EXPERIMENTAL order m...
|
2962 |
=head2 C<order> EXPERIMENTAL |
2963 | ||
2964 |
my $order = $dbi->order; |
|
2965 | ||
2966 |
Create a new L<DBIx::Custom::Order> object. |
|
2967 | ||
cleanup
|
2968 |
=head2 C<register_filter> |
2969 | ||
update pod
|
2970 |
$dbi->register_filter( |
2971 |
# Time::Piece object to database DATE format |
|
2972 |
tp_to_date => sub { |
|
2973 |
my $tp = shift; |
|
2974 |
return $tp->strftime('%Y-%m-%d'); |
|
2975 |
}, |
|
2976 |
# database DATE format to Time::Piece object |
|
2977 |
date_to_tp => sub { |
|
2978 |
my $date = shift; |
|
2979 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
2980 |
} |
|
2981 |
); |
|
cleanup
|
2982 |
|
update pod
|
2983 |
Register filters, used by C<filter> option of many methods. |
cleanup
|
2984 | |
added type_rule into logic
|
2985 |
=head2 C<type_rule> EXPERIMENTAL |
2986 | ||
2987 |
$dbi->type_rule( |
|
EXPERIMENTAL type_rule argum...
|
2988 |
into1 => { |
separate DBIx::Custom type_r...
|
2989 |
date => sub { ... }, |
2990 |
datetime => sub { ... } |
|
added type_rule into logic
|
2991 |
}, |
EXPERIMENTAL type_rule argum...
|
2992 |
into2 => { |
2993 |
date => sub { ... }, |
|
2994 |
datetime => sub { ... } |
|
2995 |
}, |
|
2996 |
from1 => { |
|
2997 |
# DATE |
|
2998 |
9 => sub { ... }, |
|
2999 |
# DATETIME or TIMESTAMP |
|
3000 |
11 => sub { ... }, |
|
3001 |
} |
|
3002 |
from2 => { |
|
changed type_rule arguments ...
|
3003 |
# DATE |
3004 |
9 => sub { ... }, |
|
3005 |
# DATETIME or TIMESTAMP |
|
3006 |
11 => sub { ... }, |
|
added type_rule into logic
|
3007 |
} |
3008 |
); |
|
3009 | ||
changed type_rule arguments ...
|
3010 |
Filtering rule when data is send into and get from database. |
separate DBIx::Custom type_r...
|
3011 |
This has a little complex problem. |
cleanup
|
3012 | |
EXPERIMENTAL type_rule argum...
|
3013 |
In C<into1> and C<into2> you can specify |
3014 |
type name as same as type name defined |
|
changed type_rule arguments ...
|
3015 |
by create table, such as C<DATETIME> or C<DATE>. |
EXPERIMENTAL type_rule argum...
|
3016 | |
separate DBIx::Custom type_r...
|
3017 |
Note that type name and data type don't contain upper case. |
EXPERIMENTAL type_rule argum...
|
3018 |
If these contain upper case charactor, you convert it to lower case. |
3019 | ||
updated pod
|
3020 |
C<into2> is executed after C<into1>. |
3021 | ||
EXPERIMENTAL type_rule argum...
|
3022 |
Type rule of C<into1> and C<into2> is enabled on the following |
3023 |
column name. |
|
separate DBIx::Custom type_r...
|
3024 | |
cleanup
|
3025 |
=over 4 |
3026 | ||
3027 |
=item 1. column name |
|
3028 | ||
3029 |
issue_date |
|
3030 |
issue_datetime |
|
3031 | ||
updated pod
|
3032 |
This need C<table> option in each method. |
3033 | ||
cleanup
|
3034 |
=item 2. table name and column name, separator is dot |
3035 | ||
3036 |
book.issue_date |
|
3037 |
book.issue_datetime |
|
3038 | ||
3039 |
=back |
|
3040 | ||
added EXPERIMENTAL DBIx::Cus...
|
3041 |
You get all type name used in database by C<available_typename>. |
update pod
|
3042 | |
added EXPERIMENTAL DBIx::Cus...
|
3043 |
print $dbi->available_typename; |
update pod
|
3044 | |
updated pod
|
3045 |
In C<from1> and C<from2> you specify data type, not type name. |
EXPERIMENTAL type_rule argum...
|
3046 |
C<from2> is executed after C<from1>. |
added EXPERIMENTAL DBIx::Cus...
|
3047 |
You get all data type by C<available_datatype>. |
changed type_rule arguments ...
|
3048 | |
added EXPERIMENTAL DBIx::Cus...
|
3049 |
print $dbi->available_datatype; |
changed type_rule arguments ...
|
3050 | |
EXPERIMENTAL type_rule argum...
|
3051 |
You can also specify multiple types at once. |
changed type_rule arguments ...
|
3052 | |
3053 |
$dbi->type_rule( |
|
EXPERIMENTAL type_rule argum...
|
3054 |
into1 => [ |
changed type_rule arguments ...
|
3055 |
[qw/DATE DATETIME/] => sub { ... }, |
3056 |
], |
|
3057 |
); |
|
added type_rule into logic
|
3058 | |
removed DBIx::Custom commit ...
|
3059 |
=head2 C<select> |
added select() all_column op...
|
3060 | |
select method column option ...
|
3061 |
my $result = $dbi->select( |
added select() all_column op...
|
3062 |
table => 'book', |
3063 |
column => ['author', 'title'], |
|
3064 |
where => {author => 'Ken'}, |
|
select method column option ...
|
3065 |
); |
added select() all_column op...
|
3066 |
|
updated document
|
3067 |
Execute select statement. |
added select() all_column op...
|
3068 | |
updated document
|
3069 |
The following opitons are available. |
added select() all_column op...
|
3070 | |
3071 |
=over 4 |
|
3072 | ||
updated document
|
3073 |
=item C<append> |
added select() all_column op...
|
3074 | |
updated document
|
3075 |
append => 'order by title' |
added select() all_column op...
|
3076 | |
updated document
|
3077 |
Append statement to last of SQL. |
added EXPERIMENTAL execute m...
|
3078 | |
3079 |
=item C<bind_type> |
|
3080 | ||
3081 |
Same as C<execute> method's C<bind_type> option. |
|
updated document
|
3082 |
|
added select() all_column op...
|
3083 |
=item C<column> |
3084 |
|
|
updated document
|
3085 |
column => 'author' |
3086 |
column => ['author', 'title'] |
|
3087 | ||
3088 |
Column clause. |
|
updated pod
|
3089 |
|
updated document
|
3090 |
if C<column> is not specified, '*' is set. |
added select() all_column op...
|
3091 | |
updated document
|
3092 |
column => '*' |
added select() all_column op...
|
3093 | |
- removed EXPERIMENTAL statu...
|
3094 |
You can specify hash of array reference. |
updated pod
|
3095 | |
updated document
|
3096 |
column => [ |
updated pod
|
3097 |
{book => [qw/author title/]}, |
3098 |
{person => [qw/name age/]} |
|
updated document
|
3099 |
] |
updated pod
|
3100 | |
updated pod
|
3101 |
This is expanded to the following one by using C<colomn> method. |
- select() column option can...
|
3102 | |
3103 |
book.author as "book.author", |
|
3104 |
book.title as "book.title", |
|
3105 |
person.name as "person.name", |
|
3106 |
person.age as "person.age" |
|
3107 | ||
- select method column optio...
|
3108 |
You can specify array of array reference, first argument is |
3109 |
column name, second argument is alias. |
|
- select() column option can...
|
3110 | |
updated document
|
3111 |
column => [ |
- select method column optio...
|
3112 |
['date(book.register_datetime)' => 'book.register_date'] |
updated document
|
3113 |
]; |
- select() column option can...
|
3114 | |
- select method column optio...
|
3115 |
Alias is quoted properly and joined. |
- select() column option can...
|
3116 | |
3117 |
date(book.register_datetime) as "book.register_date" |
|
updated pod
|
3118 | |
updated document
|
3119 |
=item C<filter> |
added select() all_column op...
|
3120 | |
updated document
|
3121 |
Same as C<execute> method's C<filter> option. |
3122 | ||
3123 |
=item C<id> |
|
3124 | ||
3125 |
id => 4 |
|
3126 |
id => [4, 5] |
|
3127 | ||
3128 |
ID corresponding to C<primary_key>. |
|
3129 |
You can select rows by C<id> and C<primary_key>. |
|
3130 | ||
3131 |
$dbi->select( |
|
3132 |
parimary_key => ['id1', 'id2'], |
|
3133 |
id => [4, 5], |
|
3134 |
table => 'book' |
|
added select() all_column op...
|
3135 |
); |
3136 | ||
updated document
|
3137 |
The above is same as the followin one. |
3138 | ||
updated pod
|
3139 |
$dbi->select( |
updated document
|
3140 |
where => {id1 => 4, id2 => 5}, |
3141 |
table => 'book' |
|
where can recieve array refr...
|
3142 |
); |
3143 |
|
|
updated document
|
3144 |
=item C<param> EXPERIMETNAL |
added select() all_column op...
|
3145 | |
updated document
|
3146 |
param => {'table2.key3' => 5} |
update pod
|
3147 | |
updated document
|
3148 |
Parameter shown before where clause. |
3149 |
|
|
3150 |
For example, if you want to contain tag in join clause, |
|
3151 |
you can pass parameter by C<param> option. |
|
update pod
|
3152 | |
updated document
|
3153 |
join => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . |
3154 |
' as table2 on table1.key1 = table2.key1'] |
|
3155 | ||
- removed EXPERIMENTAL statu...
|
3156 |
=itme C<prefix> |
added EXPERIMENTAL select pr...
|
3157 | |
3158 |
prefix => 'SQL_CALC_FOUND_ROWS' |
|
3159 | ||
3160 |
Prefix of column cluase |
|
3161 | ||
3162 |
select SQL_CALC_FOUND_ROWS title, author from book; |
|
3163 | ||
updated document
|
3164 |
=item C<join> |
3165 | ||
3166 |
join => [ |
|
3167 |
'left outer join company on book.company_id = company_id', |
|
3168 |
'left outer join location on company.location_id = location.id' |
|
3169 |
] |
|
3170 |
|
|
3171 |
Join clause. If column cluase or where clause contain table name like "company.name", |
|
3172 |
join clausees needed when SQL is created is used automatically. |
|
update pod
|
3173 | |
3174 |
$dbi->select( |
|
3175 |
table => 'book', |
|
cleanup
|
3176 |
column => ['company.location_id as location_id'], |
update pod
|
3177 |
where => {'company.name' => 'Orange'}, |
3178 |
join => [ |
|
3179 |
'left outer join company on book.company_id = company.id', |
|
3180 |
'left outer join location on company.location_id = location.id' |
|
3181 |
] |
|
3182 |
); |
|
3183 | ||
updated document
|
3184 |
In above select, column and where clause contain "company" table, |
3185 |
the following SQL is created |
|
update pod
|
3186 | |
cleanup
|
3187 |
select company.location_id as location_id |
update pod
|
3188 |
from book |
3189 |
left outer join company on book.company_id = company.id |
|
cleanup
|
3190 |
where company.name = ?; |
update pod
|
3191 | |
added join new syntax
|
3192 |
You can specify two table by yourself. This is useful when join parser can't parse |
cleanup
|
3193 |
the join clause correctly. This is EXPERIMENTAL. |
added join new syntax
|
3194 | |
3195 |
$dbi->select( |
|
3196 |
table => 'book', |
|
3197 |
column => ['company.location_id as location_id'], |
|
3198 |
where => {'company.name' => 'Orange'}, |
|
3199 |
join => [ |
|
3200 |
{ |
|
3201 |
clause => 'left outer join location on company.location_id = location.id', |
|
3202 |
table => ['company', 'location'] |
|
3203 |
} |
|
3204 |
] |
|
3205 |
); |
|
3206 | ||
updated document
|
3207 |
=item C<primary_key> |
added EXPERIMENTAL replace()...
|
3208 | |
updated document
|
3209 |
primary_key => 'id' |
3210 |
primary_key => ['id1', 'id2'] |
|
added EXPERIMENTAL replace()...
|
3211 | |
updated document
|
3212 |
Primary key. This is used by C<id> option. |
added EXPERIMENTAL replace()...
|
3213 | |
updated document
|
3214 |
=item C<query> |
update pod
|
3215 | |
updated document
|
3216 |
Same as C<execute> method's C<query> option. |
update pod
|
3217 | |
added EXPERIMENTAL execute m...
|
3218 |
=item C<sqlfilter EXPERIMENTAL> |
updated pod
|
3219 | |
added EXPERIMENTAL execute m...
|
3220 |
Same as C<execute> method's C<sqlfilter> option |
updated pod
|
3221 | |
updated document
|
3222 |
=item C<table> |
updated pod
|
3223 | |
updated document
|
3224 |
table => 'book' |
updated pod
|
3225 | |
updated document
|
3226 |
Table name. |
updated pod
|
3227 | |
updated document
|
3228 |
=item C<type_rule_off> EXPERIMENTAL |
updated pod
|
3229 | |
updated document
|
3230 |
Same as C<execute> method's C<type_rule_off> option. |
updated pod
|
3231 | |
EXPERIMENTAL type_rule argum...
|
3232 |
=item C<type_rule1_off> EXPERIMENTAL |
3233 | ||
3234 |
type_rule1_off => 1 |
|
3235 | ||
3236 |
Same as C<execute> method's C<type_rule1_off> option. |
|
3237 | ||
3238 |
=item C<type_rule2_off> EXPERIMENTAL |
|
3239 | ||
3240 |
type_rule2_off => 1 |
|
3241 | ||
3242 |
Same as C<execute> method's C<type_rule2_off> option. |
|
3243 | ||
updated document
|
3244 |
=item C<where> |
3245 |
|
|
3246 |
# Hash refrence |
|
3247 |
where => {author => 'Ken', 'title' => 'Perl'} |
|
3248 |
|
|
3249 |
# DBIx::Custom::Where object |
|
3250 |
where => $dbi->where( |
|
3251 |
clause => ['and', 'author = :author', 'title like :title'], |
|
3252 |
param => {author => 'Ken', title => '%Perl%'} |
|
3253 |
); |
|
updated pod
|
3254 |
|
3255 |
# Array reference 1 (array reference, hash referenc). same as above |
|
3256 |
where => [ |
|
3257 |
['and', 'author = :author', 'title like :title'], |
|
3258 |
{author => 'Ken', title => '%Perl%'} |
|
3259 |
]; |
|
3260 |
|
|
3261 |
# Array reference 2 (String, hash reference) |
|
3262 |
where => [ |
|
3263 |
'title like :title', |
|
3264 |
{title => '%Perl%'} |
|
3265 |
] |
|
3266 |
|
|
3267 |
# String |
|
3268 |
where => 'title is null' |
|
update pod
|
3269 | |
updated document
|
3270 |
Where clause. |
3271 |
|
|
improved pod
|
3272 |
=item C<wrap> EXPERIMENTAL |
3273 | ||
3274 |
Wrap statement. This is array reference. |
|
3275 | ||
added EXPERIMENTAL execute m...
|
3276 |
wrap => ['select * from (', ') as t where ROWNUM < 10'] |
improved pod
|
3277 | |
3278 |
This option is for Oracle and SQL Server paging process. |
|
3279 | ||
update pod
|
3280 |
=back |
cleanup
|
3281 | |
cleanup
|
3282 |
=head2 C<update> |
removed reconnect method
|
3283 | |
updated document
|
3284 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 4}); |
removed reconnect method
|
3285 | |
insert and update method's p...
|
3286 |
Execute update statement. First argument is update row data. |
3287 | ||
3288 |
If you want to set constant value to row data, use scalar reference |
|
3289 |
as parameter value. |
|
3290 | ||
3291 |
{date => \"NOW()"} |
|
added experimental update_pa...
|
3292 | |
updated document
|
3293 |
The following opitons are available. |
added experimental update_pa...
|
3294 | |
update pod
|
3295 |
=over 4 |
3296 | ||
updated document
|
3297 |
=item C<append> |
update pod
|
3298 | |
updated document
|
3299 |
Same as C<select> method's C<append> option. |
- insert, insert_at, update,...
|
3300 | |
added EXPERIMENTAL execute m...
|
3301 |
=item C<bind_type> |
3302 | ||
3303 |
Same as C<execute> method's C<bind_type> option. |
|
3304 | ||
updated document
|
3305 |
=item C<filter> |
- insert, insert_at, update,...
|
3306 | |
updated document
|
3307 |
Same as C<execute> method's C<filter> option. |
- insert, insert_at, update,...
|
3308 | |
updated document
|
3309 |
=item C<id> |
- insert, insert_at, update,...
|
3310 | |
updated document
|
3311 |
id => 4 |
3312 |
id => [4, 5] |
|
- insert, insert_at, update,...
|
3313 | |
updated document
|
3314 |
ID corresponding to C<primary_key>. |
3315 |
You can update rows by C<id> and C<primary_key>. |
|
update pod
|
3316 | |
DEPRECATED select() param op...
|
3317 |
$dbi->update( |
updated document
|
3318 |
{title => 'Perl', author => 'Ken'} |
3319 |
parimary_key => ['id1', 'id2'], |
|
3320 |
id => [4, 5], |
|
3321 |
table => 'book' |
|
where can recieve array refr...
|
3322 |
); |
update pod
|
3323 | |
updated document
|
3324 |
The above is same as the followin one. |
update pod
|
3325 | |
updated document
|
3326 |
$dbi->update( |
3327 |
{title => 'Perl', author => 'Ken'} |
|
3328 |
where => {id1 => 4, id2 => 5}, |
|
3329 |
table => 'book' |
|
3330 |
); |
|
update pod
|
3331 | |
- removed EXPERIMENTAL statu...
|
3332 |
=item C<prefix> |
added EXPERIMENTAL insert, u...
|
3333 | |
3334 |
prefix => 'or replace' |
|
3335 | ||
3336 |
prefix before table name section |
|
3337 | ||
3338 |
update or replace book |
|
3339 | ||
updated document
|
3340 |
=item C<primary_key> |
add experimental setup_model...
|
3341 | |
updated document
|
3342 |
primary_key => 'id' |
3343 |
primary_key => ['id1', 'id2'] |
|
update pod
|
3344 | |
updated document
|
3345 |
Primary key. This is used by C<id> option. |
update pod
|
3346 | |
updated document
|
3347 |
=item C<query> |
update pod
|
3348 | |
updated document
|
3349 |
Same as C<execute> method's C<query> option. |
update pod
|
3350 | |
added EXPERIMENTAL execute m...
|
3351 |
=item C<sqlfilter EXPERIMENTAL> |
3352 | ||
3353 |
Same as C<execute> method's C<sqlfilter> option. |
|
3354 | ||
updated document
|
3355 |
=item C<table> |
update pod
|
3356 | |
updated document
|
3357 |
table => 'book' |
update pod
|
3358 | |
updated document
|
3359 |
Table name. |
update pod
|
3360 | |
added EXPERIMENTAL execute()...
|
3361 |
=item C<type_rule_off> EXPERIMENTAL |
3362 | ||
EXPERIMENTAL type_rule argum...
|
3363 |
Same as C<execute> method's C<type_rule_off> option. |
3364 | ||
3365 |
=item C<type_rule1_off> EXPERIMENTAL |
|
3366 | ||
3367 |
type_rule1_off => 1 |
|
3368 | ||
3369 |
Same as C<execute> method's C<type_rule1_off> option. |
|
3370 | ||
3371 |
=item C<type_rule2_off> EXPERIMENTAL |
|
3372 | ||
3373 |
type_rule2_off => 1 |
|
3374 | ||
3375 |
Same as C<execute> method's C<type_rule2_off> option. |
|
added EXPERIMENTAL execute()...
|
3376 | |
added EXPERIMENTAL execute m...
|
3377 |
=item C<where> |
3378 | ||
3379 |
Same as C<select> method's C<where> option. |
|
3380 | ||
updated pod
|
3381 |
=back |
update pod
|
3382 | |
updated pod
|
3383 |
=head2 C<update_all> |
update pod
|
3384 | |
updated pod
|
3385 |
$dbi->update_all({title => 'Perl'}, table => 'book', ); |
update pod
|
3386 | |
updated document
|
3387 |
Execute update statement for all rows. |
updated pod
|
3388 |
Options is same as C<update> method. |
update pod
|
3389 | |
- update_param_tag is DEPREC...
|
3390 |
=head2 C<update_param> |
update pod
|
3391 | |
- update_param_tag is DEPREC...
|
3392 |
my $update_param = $dbi->update_param({title => 'a', age => 2}); |
update pod
|
3393 | |
3394 |
Create update parameter tag. |
|
3395 | ||
- update_param_tag is DEPREC...
|
3396 |
set title = :title, author = :author |
added EXPERIMENTAL updat_par...
|
3397 | |
removed EXPERIMETNAL flag fr...
|
3398 |
=head2 C<where> |
fix tests
|
3399 | |
cleanup
|
3400 |
my $where = $dbi->where( |
- update_param_tag is DEPREC...
|
3401 |
clause => ['and', 'title = :title', 'author = :author'], |
cleanup
|
3402 |
param => {title => 'Perl', author => 'Ken'} |
3403 |
); |
|
fix tests
|
3404 | |
3405 |
Create a new L<DBIx::Custom::Where> object. |
|
3406 | ||
- removed DEPRECATED DBIx::C...
|
3407 |
=head2 C<setup_model> |
cleanup
|
3408 | |
update pod
|
3409 |
$dbi->setup_model; |
cleanup
|
3410 | |
update pod
|
3411 |
Setup all model objects. |
update pod
|
3412 |
C<columns> of model object is automatically set, parsing database information. |
cleanup
|
3413 | |
fix heading typos
|
3414 |
=head1 ENVIRONMENTAL VARIABLES |
added environment variable D...
|
3415 | |
3416 |
=head2 C<DBIX_CUSTOM_DEBUG> |
|
3417 | ||
3418 |
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true, |
|
improved debug message
|
3419 |
executed SQL and bind values are printed to STDERR. |
3420 | ||
update pod
|
3421 |
=head2 C<show_datatype EXPERIMENTAL> |
3422 | ||
3423 |
$dbi->show_datatype($table); |
|
3424 | ||
3425 |
Show data type of the columns of specified table. |
|
3426 | ||
3427 |
book |
|
3428 |
title: 5 |
|
3429 |
issue_date: 91 |
|
3430 | ||
3431 |
This data type is used in C<type_rule>'s C<from1> and C<from2>. |
|
3432 | ||
test cleanup
|
3433 |
=head2 C<show_tables EXPERIMETNAL> |
3434 | ||
3435 |
$dbi->show_tables; |
|
3436 | ||
3437 |
Show tables. |
|
3438 | ||
update pod
|
3439 |
=head2 C<show_typename EXPERIMENTAL> |
3440 | ||
3441 |
$dbi->show_typename($table); |
|
3442 | ||
3443 |
Show type name of the columns of specified table. |
|
3444 | ||
3445 |
book |
|
3446 |
title: varchar |
|
3447 |
issue_date: date |
|
3448 | ||
3449 |
This type name is used in C<type_rule>'s C<into1> and C<into2>. |
|
3450 | ||
improved debug message
|
3451 |
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING> |
3452 | ||
3453 |
DEBUG output encoding. Default to UTF-8. |
|
added environment variable D...
|
3454 | |
fix heading typos
|
3455 |
=head1 DEPRECATED FUNCTIONALITY |
- added EXPERIMENTAL order m...
|
3456 | |
3457 |
L<DBIx::Custom> |
|
3458 | ||
3459 |
# Attribute methods |
|
added EXPERIMENTAL each_tabl...
|
3460 |
data_source # will be removed at 2017/1/1 |
3461 |
dbi_options # will be removed at 2017/1/1 |
|
3462 |
filter_check # will be removed at 2017/1/1 |
|
3463 |
reserved_word_quote # will be removed at 2017/1/1 |
|
3464 |
cache_method # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3465 |
|
3466 |
# Methods |
|
added EXPERIMENTAL each_tabl...
|
3467 |
create_query # will be removed at 2017/1/1 |
3468 |
apply_filter # will be removed at 2017/1/1 |
|
3469 |
select_at # will be removed at 2017/1/1 |
|
3470 |
delete_at # will be removed at 2017/1/1 |
|
3471 |
update_at # will be removed at 2017/1/1 |
|
3472 |
insert_at # will be removed at 2017/1/1 |
|
3473 |
register_tag # will be removed at 2017/1/1 |
|
3474 |
default_bind_filter # will be removed at 2017/1/1 |
|
3475 |
default_fetch_filter # will be removed at 2017/1/1 |
|
3476 |
insert_param_tag # will be removed at 2017/1/1 |
|
update pod
|
3477 |
register_tag # will be removed at 2017/1/1 |
added EXPERIMENTAL each_tabl...
|
3478 |
register_tag_processor # will be removed at 2017/1/1 |
3479 |
update_param_tag # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3480 |
|
3481 |
# Options |
|
added EXPERIMENTAL each_tabl...
|
3482 |
select method relation option # will be removed at 2017/1/1 |
3483 |
select method param option # will be removed at 2017/1/1 |
|
3484 |
select method column option [COLUMN, as => ALIAS] format |
|
3485 |
# will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3486 |
|
3487 |
# Others |
|
cleanup
|
3488 |
execute("select * from {= title}"); # execute method's |
3489 |
# tag parsing functionality |
|
added EXPERIMENTAL each_tabl...
|
3490 |
# will be removed at 2017/1/1 |
3491 |
Query caching # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3492 | |
3493 |
L<DBIx::Custom::Model> |
|
3494 | ||
DBIx::Custom::Query filters ...
|
3495 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3496 |
filter # will be removed at 2017/1/1 |
3497 |
name # will be removed at 2017/1/1 |
|
3498 |
type # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3499 | |
3500 |
L<DBIx::Custom::Query> |
|
3501 |
|
|
DBIx::Custom::Query filters ...
|
3502 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3503 |
default_filter # will be removed at 2017/1/1 |
DBIx::Custom::Query filters ...
|
3504 |
table # will be removed at 2017/1/1 |
3505 |
filters # will be removed at 2017/1/1 |
|
3506 |
|
|
3507 |
# Methods |
|
3508 |
filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3509 | |
3510 |
L<DBIx::Custom::QueryBuilder> |
|
3511 |
|
|
DBIx::Custom::Query filters ...
|
3512 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3513 |
tags # will be removed at 2017/1/1 |
3514 |
tag_processors # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3515 |
|
DBIx::Custom::Query filters ...
|
3516 |
# Methods |
added EXPERIMENTAL each_tabl...
|
3517 |
register_tag # will be removed at 2017/1/1 |
3518 |
register_tag_processor # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3519 |
|
3520 |
# Others |
|
3521 |
build_query("select * from {= title}"); # tag parsing functionality |
|
added EXPERIMENTAL each_tabl...
|
3522 |
# will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3523 | |
3524 |
L<DBIx::Custom::Result> |
|
3525 |
|
|
DBIx::Custom::Query filters ...
|
3526 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3527 |
filter_check # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3528 |
|
3529 |
# Methods |
|
added EXPERIMENTAL each_tabl...
|
3530 |
end_filter # will be removed at 2017/1/1 |
3531 |
remove_end_filter # will be removed at 2017/1/1 |
|
3532 |
remove_filter # will be removed at 2017/1/1 |
|
3533 |
default_filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3534 | |
3535 |
L<DBIx::Custom::Tag> |
|
3536 | ||
added EXPERIMENTAL each_tabl...
|
3537 |
This module is DEPRECATED! # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3538 | |
fix heading typos
|
3539 |
=head1 BACKWARDS COMPATIBILITY POLICY |
- added EXPERIMENTAL order m...
|
3540 | |
3541 |
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings |
|
3542 |
except for attribute method. |
|
3543 |
You can check all DEPRECATED functionalities by document. |
|
3544 |
DEPRECATED functionality is removed after five years, |
|
3545 |
but if at least one person use the functionality and tell me that thing |
|
added EXPERIMENTAL each_tabl...
|
3546 |
I extend one year each time he tell me it. |
- added EXPERIMENTAL order m...
|
3547 | |
3548 |
EXPERIMENTAL functionality will be changed without warnings. |
|
DBIx::Custom is now stable
|
3549 | |
added EXPERIMENTAL each_tabl...
|
3550 |
This policy was changed at 2011/6/28 |
DBIx::Custom is now stable
|
3551 | |
removed DESTROY method(not b...
|
3552 |
=head1 BUGS |
3553 | ||
renamed build_query to creat...
|
3554 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
3555 | |
3556 |
C<< <kimoto.yuki at gmail.com> >> |
|
3557 | ||
3558 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
3559 | ||
removed reconnect method
|
3560 |
=head1 AUTHOR |
3561 | ||
3562 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
3563 | |
packaging one directory
|
3564 |
=head1 COPYRIGHT & LICENSE |
3565 | ||
cleanup
|
3566 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
3567 | |
3568 |
This program is free software; you can redistribute it and/or modify it |
|
3569 |
under the same terms as Perl itself. |
|
3570 | ||
3571 |
=cut |