... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
0.1631 |
2 | 2 |
added experimental DBIx::Custom::Result end_filter method |
3 | 3 |
experimental extended select method's where option |
4 |
+ fix select method empty where failed bug |
|
4 | 5 |
0.1630 |
5 | 6 |
fix test bug |
6 | 7 |
0.1629 |
... | ... |
@@ -507,25 +507,36 @@ sub select { |
507 | 507 |
|
508 | 508 |
# Where clause |
509 | 509 |
my $param; |
510 |
+ my $wexists; |
|
510 | 511 |
if (ref $where eq 'HASH' && keys %$where) { |
511 | 512 |
$param = $where; |
512 |
- $source .= 'where ('; |
|
513 |
- foreach my $where_key (keys %$where) { |
|
514 |
- $source .= "{= $where_key} and "; |
|
513 |
+ $wexists = keys %$where; |
|
514 |
+ |
|
515 |
+ if ($wexists) { |
|
516 |
+ $source .= 'where ('; |
|
517 |
+ foreach my $where_key (keys %$where) { |
|
518 |
+ $source .= "{= $where_key} and "; |
|
519 |
+ } |
|
520 |
+ $source =~ s/ and $//; |
|
521 |
+ $source .= ') '; |
|
515 | 522 |
} |
516 |
- $source =~ s/ and $//; |
|
517 |
- $source .= ') '; |
|
518 | 523 |
} |
519 | 524 |
elsif (ref $where eq 'ARRAY') { |
520 |
- my$where_str = $where->[0] || ''; |
|
525 |
+ my $w = $where->[0] || ''; |
|
521 | 526 |
$param = $where->[1]; |
522 | 527 |
|
523 |
- $source .= "where ($where_str) "; |
|
528 |
+ if (ref $w eq 'HASH') { |
|
529 |
+ |
|
530 |
+ } |
|
531 |
+ else { |
|
532 |
+ $wexists = $w =~ /\S/; |
|
533 |
+ $source .= "where ($w) " if $wexists; |
|
534 |
+ } |
|
524 | 535 |
} |
525 | 536 |
|
526 | 537 |
# Relation |
527 | 538 |
if ($relation) { |
528 |
- $source .= $where ? "and " : "where "; |
|
539 |
+ $source .= $wexists ? "and " : "where "; |
|
529 | 540 |
foreach my $rkey (keys %$relation) { |
530 | 541 |
$source .= "$rkey = " . $relation->{$rkey} . " and "; |
531 | 542 |
} |
... | ... |
@@ -786,3 +786,16 @@ $result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 }); |
786 | 786 |
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 }); |
787 | 787 |
$row = $result->fetch_hash_first; |
788 | 788 |
is_deeply($row, {key1 => 6, key2 => 40}); |
789 |
+ |
|
790 |
+ |
|
791 |
+test 'empty where select'; |
|
792 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
793 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
794 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
795 |
+$result = $dbi->select(table => 'table1', where => {}); |
|
796 |
+$row = $result->fetch_hash_first; |
|
797 |
+is_deeply($row, {key1 => 1, key2 => 2}); |
|
798 |
+ |
|
799 |
+$result = $dbi->select(table => 'table1', where => [' ', {}]); |
|
800 |
+$row = $result->fetch_hash_first; |
|
801 |
+is_deeply($row, {key1 => 1, key2 => 2}); |