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