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