| ... | ... |
@@ -410,6 +410,17 @@ sub _build_bind_values {
|
| 410 | 410 |
|
| 411 | 411 |
# binding values |
| 412 | 412 |
my @bind_values; |
| 413 |
+ |
|
| 414 |
+ # Filter |
|
| 415 |
+ $filter ||= {};
|
|
| 416 |
+ |
|
| 417 |
+ # Parameter |
|
| 418 |
+ $params ||= {};
|
|
| 419 |
+ |
|
| 420 |
+ # Check filter |
|
| 421 |
+ $self->_check_filter($self->filters, $filter, |
|
| 422 |
+ $self->default_bind_filter, $params) |
|
| 423 |
+ if $self->filter_check; |
|
| 413 | 424 |
|
| 414 | 425 |
# Build bind values |
| 415 | 426 |
my $count = {};
|
| ... | ... |
@@ -423,9 +434,6 @@ sub _build_bind_values {
|
| 423 | 434 |
? $params->{$column}->[$count->{$column} || 0]
|
| 424 | 435 |
: $params->{$column};
|
| 425 | 436 |
|
| 426 |
- # Filter |
|
| 427 |
- $filter ||= {};
|
|
| 428 |
- |
|
| 429 | 437 |
# Filter name |
| 430 | 438 |
my $fname = $filter->{$column} || $self->default_bind_filter || '';
|
| 431 | 439 |
|
| ... | ... |
@@ -454,6 +462,27 @@ sub _build_bind_values {
|
| 454 | 462 |
return \@bind_values; |
| 455 | 463 |
} |
| 456 | 464 |
|
| 465 |
+sub _check_filter {
|
|
| 466 |
+ my ($self, $filters, $filter, $default_filter, $params) = @_; |
|
| 467 |
+ |
|
| 468 |
+ # Filter name not exists |
|
| 469 |
+ foreach my $fname (values %$filter) {
|
|
| 470 |
+ croak qq{Bind filter "$fname" is not registered}
|
|
| 471 |
+ unless exists $filters->{$fname};
|
|
| 472 |
+ } |
|
| 473 |
+ |
|
| 474 |
+ # Default filter name not exists |
|
| 475 |
+ croak qq{Default bind filter "$default_filter" is not registered}
|
|
| 476 |
+ if $default_filter && ! exists $filters->{$default_filter};
|
|
| 477 |
+ |
|
| 478 |
+ # Column name not exists |
|
| 479 |
+ foreach my $column (keys %$filter) {
|
|
| 480 |
+ |
|
| 481 |
+ croak qq{Column name "$column" in bind filter is not found in paramters}
|
|
| 482 |
+ unless exists $params->{$column};
|
|
| 483 |
+ } |
|
| 484 |
+} |
|
| 485 |
+ |
|
| 457 | 486 |
=head1 NAME |
| 458 | 487 |
|
| 459 | 488 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
| ... | ... |
@@ -513,11 +513,20 @@ eval{$result->fetch_hash_first};
|
| 513 | 513 |
ok(!$@, "$test : hash : filter_check off"); |
| 514 | 514 |
|
| 515 | 515 |
|
| 516 |
-test 'filter_check in binding parameter'; |
|
| 516 |
+test 'filter_check in parameter binding'; |
|
| 517 | 517 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 518 | 518 |
$dbi->execute($CREATE_TABLE->{0});
|
| 519 | 519 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 520 | 520 |
|
| 521 |
+$dbi->default_bind_filter('not_exists');
|
|
| 522 |
+eval{$dbi->select(table => 'table1')};
|
|
| 523 |
+like($@, qr/\QDefault bind filter "not_exists" is not registered/, "$test : default_bind_filter"); |
|
| 521 | 524 |
|
| 525 |
+$dbi->default_bind_filter(undef); |
|
| 526 |
+eval{$dbi->select(table => 'table1', filter => {key1 => 'not_exists'})};
|
|
| 527 |
+like($@, qr/\QBind filter "not_exists" is not registered/, "$test : bind_filter"); |
|
| 522 | 528 |
|
| 529 |
+eval{$dbi->select(table => 'table1', filter => {not_exists => 'encode_utf8'})};
|
|
| 530 |
+like($@, qr/\QColumn name "not_exists" in bind filter is not found in paramters/, |
|
| 531 |
+ "$test : fetch_filter"); |
|
| 523 | 532 |
|